Question: introduction to interview questions based on continuous assignment of C

  • 2020-05-10 18:42:35
  • OfStack

We know that C#, a=b=c; Is legal, for example:

int i,j,k;
i=j=k=1;

Here are two questions:

Question 1:


    const int x=1;
    short y;
    object z;
    z=y=x;
    // What is the output below ?
    Console.WriteLine(z.GetType().ToString());

Question 2:

class C
 {
     private string x;
     public string X
     {
         get { return x ?? ""; }
         set { x = value; }
     }
 } 
static void Main()
{
    C c = new C();
    object z;
    z = c.X = null;
    // What do the following two sentences say 
    System.Console.WriteLine(z == null);
    System.Console.WriteLine(c.X == null);
}


Related articles: