> Ex: I have 2 classes like this:
>
[quoted text clipped - 25 lines]
>
> As the class I describe above, I have some questions.
First, this is C# code, but this is a C++ newsgroup. You want
microsoft.public.dotnet.languages.csharp. I've set follow-ups to that group
and copied this message there as well.
> Please help me:
> Q1: I just want the property "Message" is used directly when create
[quoted text clipped - 11 lines]
>
> could we do something like those.
Your design is flawed from an OO perspective, which is why you're having a
hard time making it do what you want. When you use derivation, you're
establishing an IsA (a Child IsA Parent) relationship. This implies that
anything the base class can do, the child class can do as well.
If you want the property to be visible in Parent but not visible in Child,
you need to use a form of composition other than derivation. Specifically,
you should embed an instance of Parent inside each instance of Child. You
may have to write forwarding functions to get Parent-like behavior from
Child in the places that you do what it. You might want to create an
interface that represents the common functionality that you do want (the
functionality that does satisfy the IsA relationship) and have both Parent
and Child implement that interface.
> Q2: could we override properties in inheritance class. I want override
> System.Data.DataTable.Rows in System.Data.DataTable class
[quoted text clipped - 10 lines]
> System.Data.DataRowCollection to MyDataRowCollection. Could we do this?
> };
C# does not support covariant property types. You can overload the property
by using the 'new' keyword, but it won't be an overload of a virtual
property in the base class. Again, containment instead of derivation is
probably what you want.
-cd