Quantcast
Channel: Better naming in Tuple classes than "Item1", "Item2" - Stack Overflow
Browsing all 21 articles
Browse latest View live

Answer by CHRISTOPHER MICHAEL-DON ROGERS for Better naming in Tuple classes...

Hey if you wind up having issues with the Dynamic or Object casting removing your Named Tuple parameters, just create a function that passes the dynamic/object cast pointer by reference and recasts it...

View Article



Answer by Abdullah Tahan for Better naming in Tuple classes than "Item1",...

Why not using a multiple returns instead of using tuplevar handler = GenerateFromMethod1(hits);Process(handler.string1, handler.string1);private static (string string1, string string2)...

View Article

Answer by Snap for Better naming in Tuple classes than "Item1", "Item2"

TL:DR -> System.ValueTuples can have custom names for fields, System.Tuples cannot.Just to clarify, there are 2 different types of tuples in C# 7.0 and later. Before that there was only 1 single...

View Article

Answer by Qudus for Better naming in Tuple classes than "Item1", "Item2"

As of today, it's this simple. Instead of using the Tuple keywordpublic Tuple<int, int, int int> GetOrderRelatedIds()Use this.public (int alpha, int beta, int candor) GetOrderRelatedIds()Get the...

View Article

Answer by alin for Better naming in Tuple classes than "Item1", "Item2"

(double, int) t1 = (4.5, 3);Console.WriteLine($"Tuple with elements {t1.Item1} and {t1.Item2}.");// Output:// Tuple with elements 4.5 and 3.(double Sum, int Count) t2 = (4.5, 3);Console.WriteLine($"Sum...

View Article


Answer by Eugene Kulabuhov for Better naming in Tuple classes than "Item1",...

Just to add to @MichaelMocko answer. Tuples have couple of gotchas at the moment:You can't use them in EF expression treesExample:public static (string name, string surname) GetPersonName(this...

View Article

Answer by Sumesh Es for Better naming in Tuple classes than "Item1", "Item2"

C# 7 tuple examplevar tuple = TupleExample(key, value); private (string key1, long value1) ValidateAPIKeyOwnerId(string key, string value) { return (key, value); } if (!string.IsNullOrEmpty(tuple.key1)...

View Article

Answer by Mihir Dave for Better naming in Tuple classes than "Item1", "Item2"

MichaelMocko Answered is great,but I want to add a few things which I had to figure out(string first, string middle, string last) LookupName(long id)above Line will give you compile-time error if you...

View Article


Answer by RBT for Better naming in Tuple classes than "Item1", "Item2"

Reproducing my answer from this post as it is a better fit here.Starting C# v7.0, it is now possible to name the tuple properties which earlier used to default to names like Item1, Item2 and so...

View Article


Answer by Mitch Stewart for Better naming in Tuple classes than "Item1", "Item2"

This is very annoying and I expect future versions of C# will address this need. I find the easiest work around to be either use a different data structure type or rename the "items" for your sanity...

View Article

Answer by MichaelMocko for Better naming in Tuple classes than "Item1", "Item2"

In C# 7.0 (Visual Studio 2017) there is a new construction to do that:(string first, string middle, string last) LookupName(long id)

View Article

Answer by Kim Yang Jacobsen for Better naming in Tuple classes than "Item1",...

I would write the Item names in the summay..so by hovering over the function helloworld() the text will say hello = Item1 and world = Item2 helloworld("Hi1,Hi2");/// <summary>/// Return hello =...

View Article

Answer by bytecode77 for Better naming in Tuple classes than "Item1", "Item2"

Why is everyone making life so hard. Tuples are for rather temporary data processing. Working with Tuples all the time will make the code very hard to understand at some point. Creating classes for...

View Article


Answer by s-s for Better naming in Tuple classes than "Item1", "Item2"

You Can write a class that contains the Tuple.You need to override the Equals and GetHashCode functionsand the == and != operators.class Program{ public class MyTuple { private Tuple<int, int> t;...

View Article

Answer by hebinda for Better naming in Tuple classes than "Item1", "Item2"

If the types of your items are all different, here is a class I made to get them more intuitively.The usage of this class:var t = TypedTuple.Create("hello", 1, new MyClass());var s =...

View Article


Answer by Jonas Elfström for Better naming in Tuple classes than "Item1",...

I think I would create a class but another alternative is output parameters.public void GetOrderRelatedIds(out int OrderGroupId, out int OrderTypeId, out int OrderSubTypeId, out int...

View Article

Answer by scottm for Better naming in Tuple classes than "Item1", "Item2"

Here is an overly complicated version of what you are asking:class MyTuple : Tuple<int, int>{ public MyTuple(int one, int two) :base(one, two) { } public int OrderGroupId { get{ return...

View Article


Answer by Joe Mancuso for Better naming in Tuple classes than "Item1", "Item2"

No, you can't name the tuple members.The in-between would be to use ExpandoObject instead of Tuple.

View Article

Answer by George Duckett for Better naming in Tuple classes than "Item1",...

With .net 4 you could perhaps look at the ExpandoObject, however, don't use it for this simple case as what would have been compile-time errors become run-time errors.class Program{ static void...

View Article

Answer by MarkPflug for Better naming in Tuple classes than "Item1", "Item2"

Up to C# 7.0, there was no way to do this short of defining your own type.

View Article
Browsing all 21 articles
Browse latest View live




Latest Images