What s the strangest corner case you ve seen in C or NET

0 votes

I've amassed a little collection of oddities and brain teasers, and I'm always interested in hearing more. The page mostly focuses on C# language details, but I'm also interested in core.NET topics. For instance, here's one that isn't on the page but that I think is amazing:

string x = new string(new char[0]);
string y = new string(new char[0]);
Console.WriteLine(object.ReferenceEquals(x, y));

That should print False, right? After all, doesn't "new" (with a reference type) always generate a new object? It should, according to the specifications for both C# and the CLI. In this case, however, that is not the case. It prints True on every version of the framework with which I've tested it. (Admittedly, I haven't tried it on Mono...)

To be clear, this is just an example of what I'm looking for; I wasn't seeking for a debate or explanation of this peculiarity. (String interning isn't the same as regular string interning; string interning doesn't usually happen when a function Object() { [native code] } is invoked.) I was actually hoping for the same strange behaviour.

Are there any more hidden gems out there?

May 27, 2022 in Others by pranav
• 2,590 points
512 views

1 answer to this question.

0 votes

Bankers' Rounding is a term that refers to the practise of rounding numbers

This isn't so much a bug or a fault in the compiler as it is a strange corner case...

The.Net Framework uses a rounding mechanism known as Banker's Rounding.

The 0.5 integers are rounded to the next even number in Bankers' Rounding, thus

Math.Round(-0.5) == 0
Math.Round(0.5) == 0
Math.Round(1.5) == 2
Math.Round(2.5) == 2
etc...

This can cause unanticipated flaws in financial calculations that use the more well-known Round-Half-Up rounding method.

Visual Basic is no exception.

answered May 30, 2022 by rajiv
• 1,620 points

Related Questions In Others

0 votes
1 answer

What's the difference between struct and class in .NET?

In .NET, there are two categories of ...READ MORE

answered Feb 8, 2022 in Others by Soham
• 9,710 points
446 views
0 votes
1 answer

Is the single page app in asp.net MVC 4 examples, "Big Shelf", SEO friendly?

the pages that render on the basics ...READ MORE

answered Feb 20, 2022 in Others by narikkadan
• 63,600 points
454 views
0 votes
1 answer

What is the better API to Reading Excel sheets in java - JXL or Apache POI

Here are the things where both APIs ...READ MORE

answered Oct 9, 2022 in Others by narikkadan
• 63,600 points
3,438 views
0 votes
1 answer

SQLite.Net not being able to create text file in Win IoT Library!

That exception comes when access limited to ...READ MORE

answered Aug 3, 2018 in IoT (Internet of Things) by nirvana
• 3,130 points
1,048 views
0 votes
2 answers

Is there a .NET equivalent to Apache Hadoop?

Hadoop is a Java-based platform. So, to ...READ MORE

answered Jul 16, 2020 in Big Data Hadoop by Suhana
• 340 points
1,770 views
0 votes
1 answer

Validate String against USPS State Abbreviations

Try something like this: private static String states ...READ MORE

answered Sep 20, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
973 views
0 votes
1 answer

Authenticate on an ASP.Net Forms Authorization website from a console app

Essentially, we need to record a regular ...READ MORE

answered Sep 20, 2018 in IoT (Internet of Things) by Annie97
• 2,160 points
955 views
0 votes
1 answer

C# code works in Visual Studio 2019 but not in online compiler

Repl.it compiles in Mono C# 4.6.2.0, according ...READ MORE

answered May 30, 2022 in Others by rajiv
• 1,620 points
1,275 views
0 votes
1 answer

Disable Postback on button ASP.NET c#

If you're dynamically adding controls to the ...READ MORE

answered May 30, 2022 in Others by rajiv
• 1,620 points
7,842 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP