I am trying to use the AS keyword with an unknown type. Here is my code:
public GetData(Type MyType, string CSVPath)
{
var engine = new FileHelperEngine(MyType);
try
{
_Data = engine.ReadFile(CSVPath) as MyType; //error here
}
catch(Exception ex)
{
Console.WriteLine("Error occured: " + ex.Message);
}
}
as you can see in this code I am getting an error were MyType is. Is there a better way to do this
Use a generic method instead of passing in a
Typeas a parameter: