default
Allgemeines
Gibt den Standardwert für einen Typ zurück, wenn dieser Typ in einem generischen Typ als
Parameter verwendet wird.
Beipiel
| C# |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
using System;
namespace GoloRoden.GuideToCSharp
{
/// <summary>
/// Represents a foo class.
/// </summary>
public class Foo
{
/// <summary>
/// Gets the default value for the specified type.
/// </summary>
/// <typeparam name="T">The type.</typeparam>
/// <returns>The default value.</returns>
public T GetDefaultValue<T>()
{
// Get the default value for the specified type
// and return it to the caller.
return default(T);
}
}
}
|
Details
default gibt 0 für einen Wertetyp und null für einen Verweistyp zurück.
Siehe auch (Guide)