I am trying to do this:
protected List<T> list = new List<T>(); for (int i = 0; i < size; i++) { list.Add(null); } I get a compiler error saying "cannot convert from null to T".
I have looked around but could not find an answer to this question.
Okay, I'm sorry, literally a few seconds after posting this I noticed I didnt put a constraint into the class header and when including where T : class in the constraints, I can null the list member.
default(T)default(T) will not equate to null when dealing with structs like int, bool, etcdefault(T), in and of itself, does not guarantee so, therefore it wouldn't be a good answer to this post.
Tin this context?where T : classto the constraints I was able to add the null member. Avoidable question, but maybe someone else runs into this problem and can benefit from this.list = Enumerable.Repeat(default(T), size).ToList();note, that ifTisstruct(e.g.int,booletc.),default(T)will not benull