Thursday, January 19, 2012

Thursday 1-19-12

class Program
{
static void Main(string[] args)
{
DeclareImplicitArrays();
ArrayOfObjects();
}

static void DeclareImplicitArrays()
{
//a is really int[]
var a = new[] { 1, 10, 100, 1000 };
Console.WriteLine("a is a: {0}", a.ToString());

//b is really double[]
var b = new[] { 1, 1.4, 2, 2.5 };
Console.WriteLine("b is a: {0}", b.ToString());

//c is really string[]
var c = new[] { " hello", null, " world" };
Console.WriteLine("c is a: {0}", c.ToString());
Console.WriteLine();

}

static void ArrayOfObjects()
{
Console.WriteLine("=> Array of Objects.");

//An array of objects can be anything at all.

object[] myObjects = new object[4];
myObjects[0] = 10;
myObjects[1] = false;
myObjects[2] = new DateTime(1969, 3, 24);
myObjects[3] = "Form & Void";

foreach (object obj in myObjects)
{
//print the type and value for each item in the array
Console.WriteLine("Type: {0}, Value: {1}", obj.GetType(), obj);
}
Console.WriteLine();

}


}

No comments:

Post a Comment