Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Named tuple in dictionary?

Tags:

c#

.net

i'm trying to create a dictionary with a string key and a tuple value(string, bool). I'd like to make the tuple a named one, so something like:

Dictionary<string, (string, bool)> spColumnMapping = new Dictionary<string, 
(string, bool)>();

Is it possible?

Thanks

like image 634
Gonzalo Avatar asked Aug 03 '18 14:08

Gonzalo


1 Answers

void Main()
{
    Dictionary<string, (string Foo, bool Bar)> spColumnMapping = new Dictionary<string, (string, bool)>();

    spColumnMapping.Add("foo", ("Quax", false));

    var x = spColumnMapping["foo"];

    Console.WriteLine(x.Foo); // prints Quax
    Console.WriteLine(x.Bar); // prints False
}

Just name the parameters after the type.

like image 74
Stuart Avatar answered Oct 21 '22 13:10

Stuart