P
Peter
I want to copy a parent class instance's all datas to a child's. It's
actually a C++'s copy constructor. But why the following code does not
work - there is a compile error! How it should look like?
(The background is I don't know (I don't care indeed) all members in
DataGrid, so I don't want to copy all members in DataGrid one by one.)
public class GridEx : DataGrid
{
public GridEx()
{
InitializeComponent();
this.HeaderClicked += new HeaderEventHandler(
InternalHeaderClick );
}
public GridEx( DataGrid src )
: this()
{
base = src.MemberwiseClone(); //error CS0175: Use of keyword base
is not valid in this context
// Why? and how
should I to do??????????
// OR
this = src.MemberwiseClone(); //error CS1540: Cannot access
protected member
//'object.MemberwiseClone()'
via a qualifier of type 'DataGrid';
//the qualifier must be of
type 'GridEx' (or derived from it)
// What's the solution for the issue???????????????
}
}
actually a C++'s copy constructor. But why the following code does not
work - there is a compile error! How it should look like?
(The background is I don't know (I don't care indeed) all members in
DataGrid, so I don't want to copy all members in DataGrid one by one.)
public class GridEx : DataGrid
{
public GridEx()
{
InitializeComponent();
this.HeaderClicked += new HeaderEventHandler(
InternalHeaderClick );
}
public GridEx( DataGrid src )
: this()
{
base = src.MemberwiseClone(); //error CS0175: Use of keyword base
is not valid in this context
// Why? and how
should I to do??????????
// OR
this = src.MemberwiseClone(); //error CS1540: Cannot access
protected member
//'object.MemberwiseClone()'
via a qualifier of type 'DataGrid';
//the qualifier must be of
type 'GridEx' (or derived from it)
// What's the solution for the issue???????????????
}
}