I have a class and a list<class> that I want to set up in the constructor. I want to fill the collection when I instantiate the object.
I get an error that "this" is readonly.
Can this be done?
Thanks,
Tom
Code:
public class DotNetType
{
public string DatabaseDataType { get; set; }
public string DotNetDataType { get; set; }
}
public class DotNetTypeCollection : List<DotNetType>
{
public DotNetTypeCollection()
{
DbObject dbo = new DbObject();
DataSet ds = null;
ds = dbo.GetDataSet("dbGen.GetDotNetDataTypes");
this = ds.Tables[0].AsEnumerable().Select(row => new DotNetType
{
DotNetDataType = row.Field<string>("DotNetDataType"),
DatabaseDataType = row.Field<string>("DatabaseDataType")
}).ToList();
}
}
I get an error that "this" is readonly.
Can this be done?
Thanks,
Tom