What is the use and general practical use of using Tuples in .NET 4.0?

I had read about Tuples, which was presented at the output of the new .NET Framework features, and yet I wonder how it can be useful in enterprise applications of the real world.

Can anyone give me a brief explanation along with a simple real-world code example?

Thank! =)

+3
source share
4 answers

Tuples are currently not as significant in C # because there is no clear syntax for them. However, the concept is very common in functional languages โ€‹โ€‹such as F # (new to .NET 4.0).

, F # , F #, . #, , . , Item1 ItemX, . .

, ( ) , , , - .

+5

- .

+4

, . .

:

return new Tuple<int, string, char>(1, "some string", 10.00);

-

public class ReturnMany
{
   public int intValue { get; set; }
   public string strValue { get; set; }
   public decimal decValue { get; set; }
}

return new ReturnMany() { intValue = 1, strValue = "some string", decValue = 10.00 }
+4
source

Tuples in .NET are immutable, so they are also an easy way to pass a bunch of values โ€‹โ€‹around threads. I am currently using tuples with Retlang, and they are great for use with this type of library.

+4
source

Source: https://habr.com/ru/post/1747421/


All Articles