C# default Generic Value
In this chapter you will learn:
Description
The default keyword can be used to get the default value given a generic type parameter.
The default value for a reference type is null, and the default value for a value type is the result of bitwise-zeroing the value type's fields:
Example
Example for default Generic Value
static void Zap<T> (T[] array)
{//from www . j a va2s .c o m
for (int i = 0; i < array.Length; i++)
array[i] = default(T);
}
Next chapter...
What you will learn in the next chapter:
- What are Generic Constraints
- Type of constraints
- Example for Generic Constraints
- Note for Generic Constraints
- Example for base class constraint or interface constraint
- Example for class constraint and struct constraint
- Example for parameterless constructor constraint
- Example for naked type constraint