G
Guest
There is something that I don't understand about .NET Generics. I have code
like the following:
public class A
{
private string _paramOne;
private string _paramTwo;
public A(string paramOne, string paramTwo)
{
_paramOne = paramOne;
_paramTwo = paramTwo;
}
}
public class GenericA<T> where T : new()
{
public GenericA(string paramOne, string paramTwo)
{
new T(paramOne, paramTwo);
}
}
static void Main(string[] args)
{
GenericA<A> instance = new GenericA<A>("paramOne", "paramTwo");
}
In trying to get the strings to the type specified by the generic type
parameter I get numerous errors mainly focusing on the fact that I either
must define a parameterless construtor or I cannot use parameters in a
constructor. So my question is two fold. How do I get the arguments on the
GenericA<A> constructor to the A class? And, when and how is the type A
instantiated and constructed.
Thank you.
Kevin Burton
like the following:
public class A
{
private string _paramOne;
private string _paramTwo;
public A(string paramOne, string paramTwo)
{
_paramOne = paramOne;
_paramTwo = paramTwo;
}
}
public class GenericA<T> where T : new()
{
public GenericA(string paramOne, string paramTwo)
{
new T(paramOne, paramTwo);
}
}
static void Main(string[] args)
{
GenericA<A> instance = new GenericA<A>("paramOne", "paramTwo");
}
In trying to get the strings to the type specified by the generic type
parameter I get numerous errors mainly focusing on the fact that I either
must define a parameterless construtor or I cannot use parameters in a
constructor. So my question is two fold. How do I get the arguments on the
GenericA<A> constructor to the A class? And, when and how is the type A
instantiated and constructed.
Thank you.
Kevin Burton