I have an abstract data entity MyDataRow
which inheritance DataRowA
from it.
There is a generic class which use of it BusinessRow<TData> where TData:MyDataRow
. Problem is where I want create a new object of BusinessRow depend of a string variable:
public BusinessRow<MyDataRow> AddNewRow(string rowType)
and using one of the inheritance class of MyDataRow in its generic type:
public class BusinessRow<TData>
where TData : MyDataRow
{
}
public abstract class MyDataRow
{
}
public class DataRowA : MyDataRow
{
}
public class Main
{
public BusinessRow<MyDataRow> AddNewRow(string rowType)
{
BusinessRow<MyDataRow> row = null;
switch (rowType)
{
case "A":
default:
row =new BusinessRow<DataRowA>();
// Error CS0029 Cannot implicitly convert type
// 'BusinessRow<DataRowA>' to 'BusinessRow<MyDataRow>'
break;
}
return row;
}
}
at the following code
BusinessRow<MyDataRow> row = new BusinessRow<DataRowA>();
I get this error
Error CS0029 Cannot implicitly convert type
'BusinessRow<DataRowA>' to 'BusinessRow<MyDataRow>'