C# Programming - Datatypes - Discussion
Discussion Forum : Datatypes - General Questions (Q.No. 13)
13.
Which of the following statements are correct about data types?
- Each value type has an implicit default constructor that initializes the default value of that type.
- It is possible for a value type to contain the null value.
- All value types are derived implicitly from System.ValueType class.
- It is not essential that local variables in C# must be initialized before being used.
- Variables of reference types referred to as objects and store references to the actual data.
Discussion:
4 comments Page 1 of 1.
Jiten said:
1 decade ago
Values types also can have nullable types. For example int? number = null or int? number =10 .
There is a keyword called Default in C# but I am not very sure that there is a default value for variables.
There is a keyword called Default in C# but I am not very sure that there is a default value for variables.
Chandan Gupta said:
1 decade ago
Int? number = null can be assigned as a null but it is not a value type anymore.
Jacques Ford said:
1 decade ago
Value types do not have a default constructor that sets default values. If you declare a value type without assigning it a value you get a compile time error. Therefore statement 1 is invalid.
There might be a default constructor which is inherited from its base class but that constructor is empty.
There might be a default constructor which is inherited from its base class but that constructor is empty.
AndrewC said:
1 decade ago
Value types do have a default constructor you just can't use it when declaring a new variable. You can use them as below:
class wibble
{
private int i; // Initialised to zero.
}
class wibble
{
private int i; // Initialised to zero.
}
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers