Jan 15
What I’ve learned today: C# .NET Generic Constraints
Programming, What I've learned todayConstraints list on MSDN.
Using example - create an instance of an object that must have a public parameterless constructor:
public class ObjectFactory<T> where T : new() { public static T CreateObject() { return new T(); }}
Advantage: specifying a class that does not provide a default constructor will now generate a compile time error.
No Comments »
Recent Comments