Is
keyword is used to check variable's type ...
using System;
namespace IsKeyword
{
class A
{
public string str = "A";
}
class B
{
public string str = "B";
}
class Program
{
static void Main()
{
ArrayList al = new ArrayList();
al.Add(new B());
al.Add(new A());
al.Add(new B());
al.Add(new B());
al.Add(new A());
al.Add(new A());
al.Add(new B());
foreach (var item in al)
{
if (item is A)
{
Console.WriteLine(((A)item).str);
}
}
Console.ReadKey();
}
}
}
No comments:
Post a Comment