I am beginner of C#, and have problem that keep bothers me.
I will very appreciated if someone makes a solution.
I have a code something like :
public class SomeClass
{
public SomeClass()
{
GenericMethod<Object1>(out result);
....
}
public void GenericMethod<T>(out Result result) where T : Parent
{
T t = new T();
//do something need to be done all parent's child object ( Object1, Object2..)
...somthing same things...
//and do specific things to be done relatively
Handle(t, result);
}
// Object1 is child of Parent
private void Handle(Object1 arg1, out Result result)
{
//do something need to be done for Object1;
}
// Object1 is child of Parent
private void Handle(Object2 arg1, out Result result)
{
//do something need to be done for Object2;
}
....
}
as you will discover, what I want to do is simple.
make specified value with Type T in GenericMethod, and invoke the specified Handle Method. It will works in C++, but C# keep telling me like
"cannot convert 'T' expression to type 'Object1'"
How can I solve this problem ? Thanx in advance.