Note that there are some explanatory texts on larger screens.

plurals
  1. POIs Using .NET 4.0 Tuples in my C# Code a Poor Design Decision?
    primarykey
    data
    text
    <p>With the addition of the <a href="http://msdn.microsoft.com/en-us/library/system.tuple.aspx" rel="noreferrer">Tuple</a> class in .net 4, I have been trying to decide if using them in my design is a bad choice or not. The way I see it, a <a href="http://msdn.microsoft.com/en-us/library/system.tuple.aspx" rel="noreferrer">Tuple</a> can be a shortcut to writing a result class (I am sure there are other uses too). </p> <p>So this:</p> <pre><code>public class ResultType { public string StringValue { get; set; } public int IntValue { get; set; } } public ResultType GetAClassedValue() { //..Do Some Stuff ResultType result = new ResultType { StringValue = "A String", IntValue = 2 }; return result; } </code></pre> <p>Is equivalent to this:</p> <pre><code>public Tuple&lt;string, int&gt; GetATupledValue() { //...Do Some stuff Tuple&lt;string, int&gt; result = new Tuple&lt;string, int&gt;("A String", 2); return result; } </code></pre> <p>So setting aside the possibility that I am missing the point of Tuples, is the example with a <a href="http://msdn.microsoft.com/en-us/library/system.tuple.aspx" rel="noreferrer">Tuple</a> a bad design choice? To me it seems like less clutter, but not as self documenting and clean. Meaning that with the type <code>ResultType</code>, it is very clear later on what each part of the class means but you have extra code to maintain. With the <code>Tuple&lt;string, int&gt;</code> you will need to look up and figure out what each <code>Item</code> represents, but you write and maintain less code.</p> <p>Any experience you have had with this choice would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload