Number of questions 1,751
Number of tests completed 250,177
Number of questions answered 3,739,532
Number of registered users 19,109
Sign In | Register
Skip Navigation Links
Question: Which one best shows an example implicitly typed array?
Answer1: All elements in the initializer list must be of the same type.
Answer2: All elements in the initializer list must be implicitly convertible to a known type which is the actual type of at least one member in the initializer list.
Answer3: All elements in the initializer list must be implicitly convertible to common type which is a base type of the items actually in the list.
Answer4: string[] names = new string[] {"Bob", "Sam", "Jim", "Dan", "Mel"};
Answer5:
Answer: All elements in the initializer list must be implicitly convertible to a known type which is the actual type of at least one member in the initializer list.

Explaination: Implicitly Typed Arrays Implicitly typed arrays are similar to implicitly typed variables. Rather than explicitly defining the data type of the variable, you specify that the compiler should examine the elements of the array to determine the type that should be applied. This means that type inference may only be applied to arrays that are declared with an array initializer. To indicate that the type of an array is to be inferred, the initial declaration of a data type is replaced by the "var" keyword. The second reference to the data type, which appears before the two square brackets, is simply omitted altogether. If we take the previous code example and convert it to use implicit typing, we can write the code as follows: var names = new [] { "Bob", "Sam", "Jim", "Dan", "Mel" }; During a build, the compiler scans the contents of the array initializer and determines that every item is a string. It therefore creates a string array. If you are using Visual Studio, you will notice the Intellisense system also identifies each item in the array as a string. It is important to note that the compiled code is the same as if you had explicitly declared the type; in this context the var keyword and simpler syntax is simply syntactic sugar.
Link: External Explaination

Correctly answered: 293
Incorrectly answered: 684
Terms of Use
contact@quiznetonline.com Ver. 2.0.6783.38332