
元组比较是在 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).");lseConsole.WriteLine("Both the tuples values are not same.");
以上就是如何在 C# 中比较两个元组?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1434979.html
微信扫一扫
支付宝扫一扫