Skip to main content

Posts

Showing posts with the label LINQ

C# - The Tuples and Anonymous Types [Beginner]

Many times when you talk with developers about anonymous types or tuples you will often get a negative gut-reaction. There's probably a bit of that hard-core object-oriented designer in all of us that cringes a bit inside at the idea of using one of these "lightweight" types instead of building a full-fledged class. But, when used properly, these types can actually improve the maintainability of the code-base when used judiciously because they eliminate the need of creating dozens of one-use, simple types that can simply clutter up a project. In addition, as we will see, these types have a few tricks up their sleeves that can actually, in some circumstances, make them safer than constructing your own type.   Tuples The Tuple is a family of generic types that hold specific numbers of items of specific types in a specific order. For example: var triple = new Tuple < int , string , int >( 13 , "Hello" , 42 );   T...