4
Answers

As casting

Maha

Maha

11y
1.1k
1
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)