How to use a literal tuple as property of a class in C # [closed]

2

Hello, I'm working with C # and read about literal tuples. With this, I'm creating the class below:

public class Foo 
{
    public (int bar, string bin)? barBin { get; set; }
}

In theory, for me to be able to use this class and assign values to this tuple, I would do it like this:

int testBar = 2;
string testBin = "hello world";

var foo = new Foo() 
{
    barBin = (bar: testBar, bin: testBin)
};

The problem is that when I use this statement VS gives me the message An expression tree may not contain a tuple literal . I also tried to pass an undeclared tuple ( barBin = (testBar, testBin) ) but it does not work.

How do I use literal tuples as properties in a class and work on them?

    
asked by anonymous 05.09.2018 / 14:43

1 answer

-2

Just to remember. The Tuple class was introduced in the .NET Framework 4.0.

static void Main(string[] args)
{
   var person = GetPerson();
}

static Tuple<int, string> GetPerson() 
{
   return Tuple.Create(1, "Fulano");
}

I hope I have helped.

    
05.09.2018 / 16:21