MSDN Library

INullableValue Interface  

[Dieser Teil der Visual Studio-Dokumentation ist eine vorläufige Fassung und unterliegt Änderungen in zukünftigen Versionen. Einige Hilfethemen enthalten noch keinen Text und dienen lediglich als Platzhalter.]

Note: This interface is new in the .NET Framework version 2.0.

Defines the fundamental value and existence properties for nullable types.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

public interface INullableValue
/** @attribute ComVisibleAttribute(true) */ 
public interface INullableValue
public interface INullableValue

A type is said to be nullable if it can be assigned a value or can be assigned a null reference (Nothing in Visual Basic), which means the type has no value whatsoever. Consequently, a nullable type can express either a value or that no value exists. For example, a reference type such as String is nullable, whereas a value type such as Int32 is not. A value type cannot be nullable because it has enough capacity to express only the values appropriate for that type; it does not have the additional capacity required to express a value of null.

Use nullable types to represent things that exist or do not exist, depending on circumstance. For example, an optional attribute of an HTML tag might exist in one tag but not another, or a nullable column of a database table might exist in one row of the table but not another. You can define a type that represents an HTML tag or a database row, and define a field in the type that represents an optional attribute or a nullable column. If you define the field as a reference type you can assign the field a value or you can assign a null reference (Nothing in Visual Basic), which means the optional attribute is absent or the nullable column does not exist. However, if you define the field as a value type, you can assign a value but not null.

The solution to the problem is to define the field as a Nullable value type with a suitable value type as the generic type parameter. The Nullable object can be assigned values appropriate to the generic type parameter as well as a null reference (Nothing in Visual Basic).

The INullableValue interface, the generic Nullable class, and the nongeneric Nullable class collectively support using a value type as a nullable type. Only value types can implement the INullableValue interface.

Determining Whether a Type is Nullable

It is often necessary for an application to determine whether a type is a Nullable object. For example, your application might need to determine whether a method parameter passed anonymously as an Object type is actually a Nullable object.

A Nullable object is derived directly from the Object class, and consequently class inheritance cannot be used to determine if an anonymous type is a Nullable object. However, you can determine whether an anonymous type is a Nullable object by testing whether the type implements the INullableValue interface.

Fundamental Properties

The two fundamental members of the INullableValue interface are the HasValue and Value properties. If the HasValue property for a particular generic value type is true, the value of the type can be accessed with the Value property. If the HasValue property is false, the value of the structure is undefined and an attempt to access the Value property throws an InvalidOperationException.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile 2003 for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

.NET Compact Framework

Supported in: 2.0
© 2016 Microsoft