D
Dean L. Howen
Ex: I have 2 classes like this:
class Parent
{
private string msg;
public string Message
{
get
{
return this.msg;
}
set
{
this.msg = value;
}
.......
}
};
class Child : Parent
{
Child ()
{
// do something with property "Message"
}
...
}
As the class I describe above, I have some questions. Please help me:
Q1: I just want the property "Message" is used directly when create instance
of class Parent
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Parent obj = new Parent();
obj.Message = "Parent"; // it's ok
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
but, I don't want it (the property "Message") be used if create instance of
class Child, although it could be used inside class Child
Child obj = new Child();
obj.Message = "Parent"; // it's not allowed
could we do something like those.
Q2: could we override properties in inheritance class. I want override
System.Data.DataTable.Rows in System.Data.DataTable class
ex:
class MyDataRowCollection : System.Data.DataRowCollection
{
.....
}
class MyDataTable : System.Data.DataTable
{
/// I want covert the property: base.Rows from System.Data.DataRowCollection
to MyDataRowCollection. Could we do this?
};
Please give me your ideas.
Thanks so much.
class Parent
{
private string msg;
public string Message
{
get
{
return this.msg;
}
set
{
this.msg = value;
}
.......
}
};
class Child : Parent
{
Child ()
{
// do something with property "Message"
}
...
}
As the class I describe above, I have some questions. Please help me:
Q1: I just want the property "Message" is used directly when create instance
of class Parent
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Parent obj = new Parent();
obj.Message = "Parent"; // it's ok
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
but, I don't want it (the property "Message") be used if create instance of
class Child, although it could be used inside class Child
Child obj = new Child();
obj.Message = "Parent"; // it's not allowed
could we do something like those.
Q2: could we override properties in inheritance class. I want override
System.Data.DataTable.Rows in System.Data.DataTable class
ex:
class MyDataRowCollection : System.Data.DataRowCollection
{
.....
}
class MyDataTable : System.Data.DataTable
{
/// I want covert the property: base.Rows from System.Data.DataRowCollection
to MyDataRowCollection. Could we do this?
};
Please give me your ideas.
Thanks so much.