Maha

Maha

  • NA
  • 0
  • 325.8k

As casting

Jul 7 2013 7:23 PM
In this example following way casting is done. string value = list[i] as string;

Similar output is obtained with varied casting way string value = (string)list[i];

My question is whether casting is correct either way whatever data types are.

using System;
using System.Collections;

class Program
{
static void Main()
{
ArrayList list = new ArrayList();
list.Add("man");
list.Add("woman");
list.Add("plant");

for (int i = 0; i < list.Count; i++)
{
string value = list[i] as string;
Console.WriteLine(value);
}
Console.ReadKey();
}
}


Answers (4)