首頁  >  文章  >  後端開發  >  如何在 C# 中比較兩個元組?

如何在 C# 中比較兩個元組?

王林
王林轉載
2023-08-26 11:53:12913瀏覽

如何在 C# 中比较两个元组?

元組比較是在 C# 7.3 之後出現的。

使用 C# 中的相等運算子輕鬆比較兩個元組。

假設我們有兩個元組-

var one = (x: 1, y: 2);
var two = (p: 1, 2: 3, r: 3, s:4);

要比較它們,只需使用== 運算子-

if (one == two)
Console.WriteLine("Both the tuples are same (values are same).");

讓我們看看程式碼-

範例

var one = (x: 1, y: 2);
var two = (p: 1, 2: 3, r: 3, s:4);

if (one == two)
Console.WriteLine("Both the tuples are same (values are same).");
lse
Console.WriteLine("Both the tuples values are not same.");

以上是如何在 C# 中比較兩個元組?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除