What is C# analog of C++ std::pair?

前端 未结 14 2021
情话喂你
情话喂你 2020-11-29 16:54

I\'m interested: What is C#\'s analog of std::pair in C++? I found System.Web.UI.Pair class, but I\'d prefer something template-based.

Than

14条回答
  •  一生所求
    2020-11-29 17:28

    Unfortunately, there is none. You can use the System.Collections.Generic.KeyValuePair in many situations.

    Alternatively, you can use anonymous types to handle tuples, at least locally:

    var x = new { First = "x", Second = 42 };
    

    The last alternative is to create an own class.

提交回复
热议问题