Marc Gravell's helfpul answer covers the C# / general .NET perspective; let me add a PowerShell-specific one:
With respect to System.Tuple<...>, which are reference types:
$t1 -eq $t2 # True (How??)
PowerShell's -eq operator does not act like C's ==, which would test for reference equality here; put simply, PowerShell's -eq[ acts like $t1.Equals($t2), which with System.Tuple<...> (as well as with value type System.ValueTuple<...>) performs member-wise equality comparison and reports $true if all members are equal.
What is the syntax to create tuple in posh with named fields? Like(c#):
There is no such syntax in PowerShell - you'll have to use the default .Item<n> property (Tuple) / field (ValueTuple) names:
PS> ([ValueTuple]::Create(1, 'two')).Item2
two
However, PowerShell (Core) 7+ (not Windows PowerShell) offers convenient positional indexing:
PS> ([ValueTuple]::Create(1, 'two'))[1] # same as [-1] (last element) in this case
two
In general, note that PowerShell's array literals are [object[]]-typed, so it's easy to create a collection of objects of disparate type:
PS> $arr = 1, 'two'; $arr[1]
two
If you want named elements, you can use a hashtable literal (which constructs a System.Collections.Hashtable with case-insensitive key lookup):
PS> $ht = @{ Id = 1; Name = 'two' }; $ht.Name
two
To create a "property-bag" ad-hoc object, use a [pscustomobject] "cast" (in reality, this is syntactic sugar for directly constructing an object of that type, i.e. a quasi-anonymous PowerShell-only object):
PS> $obj = [pscustomobject] @{ Id = 1; Name = 'two' }; $obj.Name
two
Note that all these options won't perform as well as ValueTuple, but performance isn't PowerShell's focus in general.
Therefore, from a PowerShell perspective the answer to:
What's the point of the tuple?
is:
Not much:
Using them for optimized performance is generally not worth it in a scripting language such as PowerShell.
Unlike in C#, there is no syntactic sugar for creating them, so explicit [ValueTuple]::Create(...) calls are always required, which are cumbersome.
PowerShell's array literals and hashtable literals, for indexed / named mixed-type data structures, as shown above - are convenient, PowerShell-idiomatic alternatives. Native PowerShell command do not use tuples (though you may need to use them for calling .NET APIs directly).
- As an aside: The
[pscustomobject] @{ foo = 1; bar = 2 } syntactic sugar for creating the PowerShell analog of anonymous types in C# isn't as concise as one would hope (compare to C#: new { foo = 1, bar = 2 }).