C# default Generic Value

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)
{/*  w w w  .  j a  v a2 s .  c  o  m*/
  for (int i = 0; i < array.Length; i++)
    array[i] = default(T);
}




















Home »
  C# Tutorial »
    Custom Types »




C# Class
C# Struct
C# Interface
C# Inheritance
C# Namespace
C# Object
C# Delegate
C# Lambda
C# Event
C# Enum
C# Attribute
C# Generics
C# Preprocessor