Create Generic Method in C#
<p>I have the following structure:</p>

<pre><code>public enum MyTypes
{
    Type1 = 1, 
    Type2 = 2,
    Type3 = 3
}

public abstract class class1
{
   int id;
   string name;
   MyType type;
}

public class class2 : class1
{

}


public class class3 : class1
{

}

public class class4 : class1
{

}
</code></pre>

<p>now what I want to do is to make a generic method , I want to give it the type of object say class 3 and it will create object from class 3 and define it's variables and return it to be able to add it to a list of class1 </p>

<p>like that </p>

<pre><code>private class1 myFunction (MyType t , int id , string name)
{
    T obj = new T();
    obj.type = t ;
    obj.id = id ;
    obj.name = name;
    return obj;
}
</code></pre>

<p>how to create this generic method ?</p>

<p>please Help me as soon as you can</p>

<p>Thanks in Advance</p>
