What's the best way of using a pair (triple, etc) of values as one value in C#?

前端 未结 16 2568
时光说笑
时光说笑 2021-02-07 03:00

That is, I\'d like to have a tuple of values.

The use case on my mind:

Dictionary, object>

or

<         


        
16条回答
  •  粉色の甜心
    2021-02-07 03:33

    You could use System.Collections.Generic.KeyValuePair as your Pair implementation.

    Or you could just implement your own, they aren't hard:

    public class Triple
    {
      public T First {get;set;}
      public U Second {get;set;}
      public V Third {get;set;}
    }
    

    Of course, you may someday run into a problem that Triple(string, int, int) is not compatible with Triple(int, int, string). Maybe go with System.Xml.Linq.XElement instead.

提交回复
热议问题