Googling is only coming up with the keyword, but I stumbled across some code that says
MyVariable = default(MyObject);
and I am wondering what it means.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
nullNullable<T>it returns a zero-initialized valueNullable<T>it returns the empty (pseudo-null) value (actually, this is a re-statement of the second bullet, but it is worth making it explicit)The biggest use of
default(T)is in generics, and things like theTry...pattern:As it happens, I also use it in some code-generation, where it is a pain to initialize fields / variables – but if you know the type: