How to declare the default value of C# variables?

 Posted by Sheonarayan on 7/6/2016 | Category: C# Interview questions | Views: 593 | Points: 40
Answer:

To get the default value of the C# variables, default keyword can be used.
        float f = default(float); // float

Response.Write(f.ToString());
bool b = default(bool); // float
Response.Write(b.ToString());
DateTime d = default(DateTime); // float
Response.Write(d.ToString());


Above code snippet, prints the default value of float, bool and DateTime variable types. Same applies to double, long and other variables.

Thanks


Source: Narayan | Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response