如何在 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.");
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP