.NET Framework Class Library
Contract..::.Result<(Of <(T>)>) Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Represents the return value of a method or property.

Namespace:  System.Diagnostics.Contracts
Assembly:  mscorlib (in mscorlib.dll)
Syntax

Visual Basic (Declaration)
Public Shared Function Result(Of T) As T
Visual Basic (Usage)
Dim returnValue As T

returnValue = Contract.Result()
C#
public static T Result<T>()
Visual C++
public:
generic<typename T>
static T Result()
F#
static member Result : unit -> 'T 

Type Parameters

T

Type of return value of the enclosing method or property.

Return Value

Type: T
Return value of the enclosing method or property.
Remarks

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

Examples

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

Visual Basic
Function Add(ByVal value As Object) As Integer Implements IArray.Add
    ' Returns the index in which an item was inserted.
    Contract.Ensures(Contract.Result(Of Integer)() >= -1) '
    Contract.Ensures(Contract.Result(Of Integer)() < CType(Me, IArray).Count) '
    Return 0
    '
    'ToDo: Error processing original source shown below
    '        return default(int);
End Function 'IArray.Add
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);
}
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4
See Also

Reference

Page view tracker