Op Englesch liesen Editéieren

Deelen iwwer


Contract.Result<T> Method

Definition

Represents the return value of a method or property.

C#
public static T Result<T>();

Type Parameters

T

Type of return value of the enclosing method or property.

Returns

T

Return value of the enclosing method or property.

Examples

The following example shows how to use the Result method to specify an expected return value. This code example is part of a larger example provided for the ContractClassAttribute class.

C#
int IArray.Add(Object value)
{
    // Returns the index in which an item was inserted.
    Contract.Ensures(Contract.Result<int>() >= -1);
    Contract.Ensures(Contract.Result<int>() < ((IArray)this).Count);
    return default(int);
}

Remarks

This method can be used only in the conditional expression for the Ensures contract.

Applies to

Produkt Versiounen
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0