Which one is better to use?
int xyz = 0;
OR
int xyz= default(int);
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.
Why make people think more than necessary?
defaultis useful with generic code, but here it doesn’t add anything. You should also think if you’re initializing it in the right place, with a meaningful value. Sometimes you see, with stack variables, code like:In such cases, you should delay initialization until you have the real value. Do:
The compiler ensures you don’t use an uninitialized stack variable. In some cases, you have to use meaningless values because the compiler can’t know code will never execute (due to an exception, call to Exit, etc.). This is the exception (no pun intended) to the rule.