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 in Others by pranav
• 2,580 points
20 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 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 in Others by Soham
• 8,740 points
28 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 in Others by narikkadan
• 11,280 points
30 views
0 votes
1 answer

Using unserialize in PHP throws the same error repeatedly

I googled 'Node no longer exists', and ...READ MORE

answered Nov 14, 2018 in Others by DataKing99
• 8,240 points
821 views
0 votes
1 answer
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
665 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
229 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
262 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 in Others by rajiv
• 1,620 points
32 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 in Others by rajiv
• 1,620 points
88 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP