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

0 votes

I have a small collection of puzzles and corner cases, and I'm constantly interested in learning more. The page mainly deals with bits and pieces of the C# language, although I also find the fundamentals of.NET interesting. Here's one that isn't on the page but that I think is incredible:

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

Since "new" (when used with a reference type) always creates a new object, I would anticipate that to print False. It should, according to the specifications for both C# and the CLI. Well, not in this specific instance. On every version of the framework I've tested it with, it prints True. (I must admit that I haven't tried it on Mono.)

Just to be clear, I wasn't specifically searching for a debate or explanation of this peculiarity; this is merely an example of the kind of stuff I'm looking for. (It differs from standard string interning in that string interning typically doesn't take place when a function Object() { [native code] } is called.) In reality, I was requesting odd behaviour just like that.

Any other hidden treasures out there?

Dec 12, 2022 in C# by Roshan
• 300 points
188 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In C#

0 votes
1 answer

What is the best C# to VB.net converter

Telerik has a solid SharpDevelop-based converter that ...READ MORE

answered May 30, 2022 in C# by rajiv
• 1,620 points
1,321 views
0 votes
1 answer

What are the differences between C, C# and C++ in terms of real-world applications?

C is a bare-bones, straightforward, and clean ...READ MORE

answered May 30, 2022 in C# by rajiv
• 1,620 points
333 views
0 votes
1 answer

What is the difference between C# and .NET?

C# is a programming language, and.NET refers ...READ MORE

answered Jun 7, 2022 in C# by pranav
• 2,590 points
502 views
0 votes
1 answer

Is a Library a project or a C# source code file in Visual Studio?

A library project is a collection of ...READ MORE

answered Jun 7, 2022 in C# by rajiv
• 1,620 points
279 views
0 votes
1 answer

How do I specify the exit code of a console application in .NET

Simply put, you can return the exit ...READ MORE

answered Jun 11, 2022 in C# by pranav
• 2,590 points
2,002 views
0 votes
1 answer

How do I turn a C# object into a JSON string in .NET

Newtonsoft.json can be used to accomplish this. ...READ MORE

answered Jun 13, 2022 in C# by krishna
• 2,820 points
362 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
1,416 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
697 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
609 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