Générique: Exemple d’utilisation du mot clé ‘default’

Author:

Non,Edité
{filelink=17497}

using System;

class MaClasse
{
}

class Sakoba
{
  public T objet;

  public Sakoba()
  {
    objet = default(T);
  }
}

class UtilisationDefault
{
  public static void Main()
  {
    Sakoba x = new Sakoba();

    if(x.objet == null)
      Console.WriteLine("x.objet est null.");

    Sakoba y = new Sakoba();

    if(y.objet == 0)
      Console.WriteLine("y.objet esy 0.");
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *