Answer the question
In order to leave comments, you need to log in
How does inheritance work in C#?
class A
{
public int X { get; set; }
public int Y { get; set; }
public A(int x, int y)
{
X = x+1;
Y = y+1;
}
}
class B:A
{
public int X { get; set; }
public int Z { get; set; }
public B(int x, int y, int z):base(x,y)
{
X = x;
Z = z;
Console.WriteLine($"this.X = {X}, this.Y = {Y}, this.Z = {Z}");
Console.WriteLine($"base.X = {base.X}, base.Y = {base.Y}");
}
}
B b = new B(1,2,3);
Answer the question
In order to leave comments, you need to log in
1. base is a keyword
2. Variables declared in the class body (field) are automatically assigned a default value according to the declared type. This, of course, also applies to properties.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question