Covariance preserve assignment compatibility between Parent and Child relationship during dynamic polymorphism
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Covariance
{
class Program
{
static void Main(string[] args)
{
List
objAthelete.Add(new Athelete
{
SportName = "100 meter",
SportsType = "Running"
});
IEnumerable
Athelete objAth = new Athelete();
//objAth.PrintAll(Persons);
}
}
public class Person
{
public string Name { get; set; }
public string City { get; set; }
}
public class Athelete : Person
{
public string SportName { get;set; }
public string SportsType { get;set; }
public void PrintAll(IEnumerable
{
foreach (Athelete o in objects)
{
Console.WriteLine("Sports Name:" + o.SportName + "Sports Type:" + o.SportsType);
}
}
}
}
The following error is thrown when the application is run in .Net framework 3.5, but it support in 4.0 framework.
No comments:
Post a Comment
Comments Welcome