My question is: can I check whether a variable (string or int/double type) or an array (string or int/double type) is initialized in C#?
Thanks in advance.
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.
You are guaranteed some sort of initialization. For any static or instance members, all variables are automatically initialized when the type or instance is constructed, either explicitly or implicitly (in which case
default(Type)is the value, so 0 for numeric types,nullfor strings and other reference types, etc.).For local variables, they cannot be used before declaration, so if you can check it, it’s been initialized.