Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there something like tuple in .net 3.5 [duplicate]

I need some data type like List<int , int , int ,string , int >. Of course I can implement , but is there something built in .net 3.5.

Thanks .

like image 255
Night Walker Avatar asked Sep 19 '11 10:09

Night Walker


People also ask

Is tuple immutable in C#?

Tuple types are immutable. Data members of System. ValueTuple types are fields.

What is .NET tuple?

NET Framework 4.0. A tuple is a data structure that contains a sequence of elements of different data types. It can be used where you want to have a data structure to hold an object with properties, but you don't want to create a separate type for it.

Is it good to use tuple in C#?

Why should we use Tuples? You may want to use a tuple to represent a set of heterogeneous data and provide an easy way to access that data. You can also take advantage of a tuple to return multiple values from a method or even pass multiple values to a method.


1 Answers

No, there isn't anything in .NET 3.5. But rather than Tuple, have you considered implementing your own simple type which encapsulates the members you need? Usually that ends up giving more readable code than Tuple anyway - especially when you've got quite a lot of members, most of which have the same types.

It's a lot easier to understand:

foo(sale.AdultTickets, sale.ChildTickets, ...);

than

foo(sale.Item1, sale.Item2, ...);

It's a little bit more work, but it needn't be much more.

like image 120
Jon Skeet Avatar answered Nov 09 '22 00:11

Jon Skeet