Home > Backend Development > C#.Net Tutorial > How to compare two tuples in C#?

How to compare two tuples in C#?

王林
Release: 2023-08-26 11:53:12
forward
976 people have browsed it

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

Tuple comparison appeared after C# 7.3.

Easily compare two tuples using the equality operator in C#.

Suppose we have two tuples-

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

To compare them just use == operator-

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

Let’s see the code-

Example

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.");
Copy after login

The above is the detailed content of How to compare two tuples in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template