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

前端 未结 16 2257
时光说笑
时光说笑 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:43

    I have implemented a tuple library in C#. Visit http://www.adventuresinsoftware.com/generics/ and click on the "tuples" link.

    0 讨论(0)
  • 2021-02-07 03:44
    public struct Pair<T1, T2>
    {
        public T1 First;
        public T2 Second;
    }
    
    public struct Triple<T1, T2, T3>
    {
        public T1 First;
        public T2 Second;
        public T3 Third;
    }
    
    0 讨论(0)
  • 2021-02-07 03:47

    There are also the Tuple<> types in F#; you just need to reference FSharp.Core.dll.

    0 讨论(0)
  • 2021-02-07 03:48

    NGenerics - the popular .Net algorithms and data structures library, has recently introduced immutable data structures to the set.

    The first immutable ones to implement were pair and tuple classes. The code is well covered with tests and is quite elegant. You can check it here. They are working on the other immutable alternatives at the moment and they should be ready shortly.

    0 讨论(0)
提交回复
热议问题