P
Praveen
trying to learn plymorphism.
My sample is
public class Class1
{
public static void Main(string[] args)
{
Cls1 x = new Cls1();
Cls2 y = new Cls2();
Cls3 y = new Cls3();
Object[] coll = new Object[] {x,y,z};
foreach (Object obj in coll)
{
Console.WriteLine(obj.Rtn());
// here is the issue.
//How to get the return value of Rtn();
//I want to use the loop and the concept of polymorphism
}
}
}
public class Cls1
{
public string Rtn()
{
return "From Cls1";
}
}
public class Cls2
{
public string Rtn()
{
return "From Cls2";
}
}
public class Cls3
{
public string Rtn()
{
return "From Cls3";
}
}
My sample is
public class Class1
{
public static void Main(string[] args)
{
Cls1 x = new Cls1();
Cls2 y = new Cls2();
Cls3 y = new Cls3();
Object[] coll = new Object[] {x,y,z};
foreach (Object obj in coll)
{
Console.WriteLine(obj.Rtn());
// here is the issue.
//How to get the return value of Rtn();
//I want to use the loop and the concept of polymorphism
}
}
}
public class Cls1
{
public string Rtn()
{
return "From Cls1";
}
}
public class Cls2
{
public string Rtn()
{
return "From Cls2";
}
}
public class Cls3
{
public string Rtn()
{
return "From Cls3";
}
}