• Saves Valuable Time
  • Trusted Accuracy for 12 Years
  • 15-Day Money-Back Guarantee

VB Equivalent to C# Tuples

C# VB
public (string first, string middle, string last) TupleReturningMethod1()
{
    //... retrieve first, middle and last
    return (first, middle, last);
}

//option to not assign names to tuple fields:
public (string, string, string) TupleReturningMethod2()
{
    //... retrieve first, middle and last
    return (first, middle, last);
}

public void CallTupleMethods()
{
    //assign the tuple to an implicitly-type variable:
    var names = TupleReturningMethod1();
    //can reference different parts of tuple via 'Item1', 'Item2', etc.
    Foo(names.Item1, names.Item3);
    //can reference different parts via names provided in tuple header:
    Foo(names.first, names.last);

    //assign the tuple to an explicitly-typed variable:
    (string first1, string middle1, string last1) tuple = TupleReturningMethod1();
}
Public Function TupleReturningMethod1() As (first As String, middle As String, last As String)
    '... retrieve first, middle and last
    Return (first, middle, last)
End Function

'option to not assign names to tuple fields:
Public Function TupleReturningMethod2() As (String, String, String)
    '... retrieve first, middle and last
    Return (first, middle, last)
End Function

Public Sub CallTupleMethods()
    'assign the tuple to an implicitly-type variable:
    Dim names = TupleReturningMethod1()
    'can reference different parts of tuple via 'Item1', 'Item2', etc.
    Foo(names.Item1, names.Item3)
    'can reference different parts via names provided in tuple header:
    Foo(names.first, names.last)

    'assign the tuple to an explicitly-typed variable:
    Dim tuple As (first1 As String, middle1 As String, last1 As String) = TupleReturningMethod1()
End Sub


Use Instant VB to convert from C# to VB.NET.     

Additional resource: VB.NET and C# Equivalents


Copyright © 1997 – 2017 Tangible Software Solutions Inc.