Coffeehouse Post

Single Post Permalink

View Thread: How are you using Tuple in code?
  • User profile image
    Bass

    , cbae wrote

    *snip*

    Instead of List<Tuple<string,int>>, I'd probably use Dictionary<string,int> if the string element needed to be unique.

    I would most likely use Tuple<int,int> for managing data for 2D graphing. The benefit is that it's a reference type, whereas something like System.Drawing.Point is a value type, and passing the Tuple object as an argument to methods is more efficient.

    If you're doing 3D surface modelling, then Tuple<int, int, int> is the only way to go.

     

    You can pass value types by reference in C# using the "out" keyword. If your reason for doing this is performance, I'd strongly suggest benchmarking first.. that's a pretty controversial assumption you are making about the performance of reference types, especially when going against value types that are 8 or 12 bytes.

    Also I would recommend capital punishment for anyone who uses "Tuple" as a parameter argument in an API. Seems appropriate for the crime.