Image for post

Tuples get a lot of hate in the C## world where they rarely see implementation, in part because of the obscurity of the “tuple” in certain programming languages such as C#, but also because the objects inside traditional C## Tuples are accessed as “Item1”, “Item2” and so on.

When it comes to how I return multiple properties from a method, here’s my hierarchy:

  1. Return a tuple (ValueTuple)
  2. Break the method up into smaller methods, each returning only one object
  3. and finally: create and use a POCO (plain ol’ C## object) to hold the objects

For me, creating a POCO just to store a method’s return value is the worst and last-resort option, yet it is probably the go-to for most C## developers in such a scenario. Using a custom POCO gives us Intellisense and allows us to access the results of the method by their property names. What’s not to love?

#tuples #c# #csharp #programming-c

Returning multiple properties in a C# method with ValueTuple
1.20 GEEK