The following C# codes are? [code] 1. Myclass class; Myclass class2 = null; [/code] [code] 2. int i; int j = 0; [/code]

The following C# codes are?
Code:
 1. Myclass class;
    Myclass class2 = null;
Code:
 2. int i;
    int j = 0;
A. True for (1);False for (2)
B. True for (2);False for (1)
C. Both (1) and (2) are equivalents
D. Both (1) and (2) are not equivalents
 
Answer: c
Explanation: When we create a type in ‘C#’, It automatically gets filled with padded zeros. For the case of class (reference types) this equates to a null pointer. Hence, for code 1) Both variable values are equivalent to each other.Similarly, for code 2) i.e for value type (including int/float/double etc.), the type is passed with zeros. Hence, they are equivalent.
 

Tìm kiếm

Back
Top