. NET, have you forgotten? (vii)--from the perspective of A?B:C

Source: Internet
Author: User

1. The SUMMARY

In this article, I will analyze a simple statement through IL.

If it feels really simple, you can skip it.

2. Intro

The thing is, a colleague wrote a code like this:

class Program
{
       static void Main(string[] args)
       {
             object o = new object();
             int i;
             Int32.TryParse(Console.ReadLine(), out i);
             o = i > 3 ? null : 3.5;
       }
}

Not in the console program, of course, I'm just writing a simulation here.

Then the system reported one such error.

3. Error analysis

My colleague asked me in amazement, why is this?

The reason he gives is that object is the parent of all classes, so I have 3.5 or null assigned to him is no problem ah, so what is the problem?

I realized that my language skills were far less persuasive than the code, so write a piece of code and then take the IL.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.