Without initialization how is it possible to assign values to arrays?
string[] s={"all","in","all"};
I mean why did not the compile show error?.Normally we need to
initialize ,before assign values.
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.
It’s just syntactic sugar.
This:
is compiled to the same code as:
Note that the array reference is not assigned to
suntil all the elements have been assigned. That isn’t important in this particular case where we’re declaring a new variable, but it would make a different in this situation:The same is true for object and collection initializers – the variable is only assigned at the end.