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 expect it 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 discussion or explanation of this peculiarity; this is merely an example of the kind of stuff I'm looking for. I was really looking for comparable strange behaviour (it's not the same as usual string interning; in particular, string interning doesn't typically happen when a function Object() { [native code] } is invoked.)

Any other gems lurking out there?

Dec 9, 2022 in Android by Edureka
• 13,620 points
331 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 Android

0 votes
0 answers

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

I have classes like these: class MyDate { ...READ MORE

Sep 20, 2022 in Android by Edureka
• 13,620 points
426 views
0 votes
0 answers

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

As I stated in an earlier article, ...READ MORE

Sep 20, 2022 in Android by Edureka
• 13,620 points
401 views
0 votes
0 answers

What is the difference between C# and .NET?

May I know what is the difference ...READ MORE

Sep 20, 2022 in Android by Edureka
• 13,620 points
366 views
0 votes
0 answers

Error: No toolchains found in the NDK toolchains folder for ABI with prefix: llvm

I tried to use Gradel (gradlew clean ...READ MORE

Sep 21, 2022 in Android by Edureka
• 13,620 points
392 views
0 votes
1 answer

What is the purpose of setImageResource() in Android?

setImageResource(): Use a resource id to set the ...READ MORE

answered Nov 8, 2022 in Android by Edureka
• 13,620 points
1,512 views
+1 vote
1 answer

net: ERR_UNKNOWN_URL_SCHEME in Android Webview codes not working in Kotlin

3 ways to fix the err_unknown_url_scheme error. You ...READ MORE

answered Nov 8, 2022 in Android by Edureka
• 13,620 points
8,759 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,691 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
901 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
859 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