Wednesday, 2 October 2013

Based on Generic

Based on Generic

Question #1:
How would I return the default value of a type passed in to the
GetDefaultValue function. For example, passing in an
int would yield 0, a string would yield null, etc.
How would I constrain the type passed in to the GetDefaultValue function
to a class with a parameterless constructor
that implements IDisposable?
How would I instantiate an instance of the above type to return from the
GetDefaultValue function?
What other approaches could I use to do the same thing as #2 and #3, but
without generics?
public class GenericsExample
{
public static T GetDefaultValue()
{
}
}
// return ???
throw new NotImplementedException();

No comments:

Post a Comment