How do I assign a value in a generics C# class?
public class GeneralWrapper<T>
{
public GeneralWrapper()
{
Datas = new ?
}
public T Datas { get; set; }
}
I’m writing a generic wrapper class for a List objects (any object). So I can use this class like
GeneralWrapper<List<string>> _wrapper = new GeneralWrapper<List<string>>();
_wrapper.Datas.Add("hello")
but the Datas need to be automatically initialized in the constructor like
Datas = new Datas<t>();
it seems so that I don’t have to create new after I create the GeneralWrapper class.
http://msdn.microsoft.com/en-us/library/sd2w2ew5.aspx Has the answer.