Search This Blog

22 March, 2011

C# Program with "as - keyword".

//C# Program with "as - keyword".


class aaa
{
public void sam()
{
System.Console.WriteLine("Hello");
}
}
class bbb
{
public void accept(object k)
{
aaa a=k as aaa;  // Null will be assigned if not castable
//aaa a=(aaa)k; //Would generate an exception if the material is not castable
if(a!=null)
{
a.sam();
}
}
}
class ccc
{
public void tom()
{
System.Console.WriteLine("good");
}
}
class psp
{
public static void Main()
{
aaa a=new aaa();
bbb b=new bbb();
b.accept(a);
ccc c=new ccc();
b.accept(c);
}
}
------------------------------------------------------------------------------------------------------

No comments:

Post a Comment

Meetme@