Work on C# .I want to inherit generic class for this purpose i write the bellow syntax
public class Father
{
public string FatherName { get; set; }
}
public class Mother
{
public string MotherName { get; set; }
}
public class Ancestors<T, U>
{
//public class Bar
//{
// private T t;
// private U u;
//}
}
class Program : Ancestors<Father, Mother>
{
static void Main(string[] args)
{
Ansestors.Father.FatherName = "xxx";
}
}
I want Ansestors.Father.FatherName = “xxx”; property .What’s problem on my syntax?Plz show some syntax to solve this issue.if have any query plz ask.Thanks in advance
Looks like you haven’t fully wrapped your head around the concept of generic classes.
What you say to the compiler with the above declaration is: Whenever you find a T (or U) in the code of the
Programclass, then replace it withFather(orMother).Why do you expect the
Programclass to have a nested object of typeFather? It’s not declared anywhere, all you’ve declared is a type resolving directive for the compiler.HTH!