19 Haziran 2017 Pazartesi

default Anahtar Kelimesi

Giriş
Açıklaması şöyle
The default keyword is contextual since it has multiple usages. I am guessing that you are referring to its newer C# 2 meaning in which it returns a type's default value. For reference types this is null and for value types this a new instance all zero'd out.
Örnek
Şöyle yaparız.
using System;

Console.WriteLine(default(Int32)); // Prints "0"
Console.WriteLine(default(Boolean)); // Prints "False"
Console.WriteLine(default(String)); // Prints nothing (because it is null)
Örnek
Şöyle yaparız.
public T Foo<T>()
{
  ...
  return default(T);
}

Hiç yorum yok:

Yorum Gönder