P
Player
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hello all.
I am in the process of teaching myself C# and I think I am doing OK.
I have learnt how to how to call the right constructor of a class, if the
class has more than than one cosntructor, by making sure that each
constructor has a different signature. I have managed to learn that and get
it stuck up there in the old brain cells
But I am having a little difficulty with the, "this" initializer for calling
a classes OWN constructor rather than it's inherited base class cosntructor.
Example as follows, [and for clarity's sake I will mention that these
classes are book examples]
Say I have these two classes one a base class the other a derived one.
class A
{
public A()
{
Console.WriteLine("A");
}
} // end class A
class B : A
{
public B() : base()
{
Console.WriteLine("B");
}
} // end class B
Now I know in class B that it is, "explicitly" calling it's base class
constructor from the base class, "A" using the initializer, "base()" .
BUT what I don't know how to do is make sure that the derived class, "B"
calls ONLY it's own constructor via the use of the, "this()" initilaizer.
Can anyone help me with this please?
As I have said, I have learnt how to overload methods and constructors via
the different signature approach, I am just a touch confused on how to use
the, "this()" initializer within a constructor to make it's class call it
and not it's base class constructor, which it will do anyway if it's a
derived class, even without the explicit call.
Thanks in advance
Player
- --
***********
I hear, and I forget.
I see, and I remember.
I do, and I understand.
- -- Confucius
************
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0
iQA/AwUBQYXnOS/z2sM4qf2WEQIzAQCgkP3vbB5lNJotB1/9WXSt3+jQnb4Anjek
6jRR6opsxA7UIqLslbD53ugg
=JHPs
-----END PGP SIGNATURE-----
Hash: SHA1
Hello all.
I am in the process of teaching myself C# and I think I am doing OK.
I have learnt how to how to call the right constructor of a class, if the
class has more than than one cosntructor, by making sure that each
constructor has a different signature. I have managed to learn that and get
it stuck up there in the old brain cells

But I am having a little difficulty with the, "this" initializer for calling
a classes OWN constructor rather than it's inherited base class cosntructor.
Example as follows, [and for clarity's sake I will mention that these
classes are book examples]
Say I have these two classes one a base class the other a derived one.
class A
{
public A()
{
Console.WriteLine("A");
}
} // end class A
class B : A
{
public B() : base()
{
Console.WriteLine("B");
}
} // end class B
Now I know in class B that it is, "explicitly" calling it's base class
constructor from the base class, "A" using the initializer, "base()" .
BUT what I don't know how to do is make sure that the derived class, "B"
calls ONLY it's own constructor via the use of the, "this()" initilaizer.
Can anyone help me with this please?
As I have said, I have learnt how to overload methods and constructors via
the different signature approach, I am just a touch confused on how to use
the, "this()" initializer within a constructor to make it's class call it
and not it's base class constructor, which it will do anyway if it's a
derived class, even without the explicit call.
Thanks in advance

Player
- --
***********
I hear, and I forget.
I see, and I remember.
I do, and I understand.
- -- Confucius
************
-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0
iQA/AwUBQYXnOS/z2sM4qf2WEQIzAQCgkP3vbB5lNJotB1/9WXSt3+jQnb4Anjek
6jRR6opsxA7UIqLslbD53ugg
=JHPs
-----END PGP SIGNATURE-----