H
Heinz Kiosk
A piece of code generated by an MS wizard goes as follows:
public class MyDataTable : DataTable...
{
....
public override DataTable Clone()
{
MyDataTable cln = ((MyDataTable)(base.Clone())); // What is going on here?
cln.InitVars();
return cln;
}
....
}
MyDataTable is derived from DataTable. How does casting a DataTable to a
MyDataTable in the commented line work? I must be missing some rules about
how casting works in .NET. If you cast to a derived class does the compiler
fill in defaults for derived members or use the derived constructor and then
do a field-by-field copy or what? Something clever must be going on.
Thank you.
Tom
public class MyDataTable : DataTable...
{
....
public override DataTable Clone()
{
MyDataTable cln = ((MyDataTable)(base.Clone())); // What is going on here?
cln.InitVars();
return cln;
}
....
}
MyDataTable is derived from DataTable. How does casting a DataTable to a
MyDataTable in the commented line work? I must be missing some rules about
how casting works in .NET. If you cast to a derived class does the compiler
fill in defaults for derived members or use the derived constructor and then
do a field-by-field copy or what? Something clever must be going on.
Thank you.
Tom