// OOPS! Mismatch of size and elements!
int[] intArray = new int[2] { 20, 22, 23, 0 };
Defining an Array of Objects
As mentioned, when you define an array, you do so by specifying the type of item that can be within
the array variable. While this seems quite straightforward, there is one notable twist. As you will
come to understand in Chapter 6, System.Object is the ultimate base class to each and every type
(including fundamental data types) in the .NET type system. Given this fact, if you were to define an
array of objects, the subitems could be anything at all. Consider the following ArrayOfObjects()
method (which again can be invoked from Main() for testing):
static void ArrayOfObjects()
{
Console.WriteLine("=> Array of Objects.");
Do'stlaringiz bilan baham: |