object obj = new object[] { new object(), new object() };
How does this compile? It seems confusing.
Seems it should either be
object[] obj = new object[] { new object(), new object() };
or
object[] obj = { new object(), new object() };
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 compiles because an “object” can be anything, therefore it can be a reference to an array of object. The code below using strings to make the distinction a little clearer, might help. So:
Essentially, an object can always be a reference to anything, even an array of object. Object doesn’t care what is put in it, so by the very end of the code there, we’ve got a string array back. Run that code up in Visual Studio, drop a few breakpoints in and follow it through. It’ll hopefully help you make sense of why the code you specified is valid =)