元组在 C# 中的类
Tuple<T1> 类表示称为单例的 1 元组。元组是一种具有元素序列的数据结构。
它用于 −
- 更轻松地访问数据集。
- 更轻松地处理数据集。
- 表示一组数据。
- 从方法返回多个值
- 将多个值传递给方法
它有一个属性 −
Item1 - 获取当前 Tuple<T1> 对象的第一个组件的值。
示例
现在让我们看一个示例在 C# 中实现 1 元组 −
using System;
public class Demo {
public static void Main(string[] args) {
Tuple<int> tuple = new Tuple<int>(100);
Console.WriteLine("Value = " + tuple.Item1);
if (tuple.Item1 == 150) {
Console.WriteLine(tuple.Item1);
}
if (tuple.Item1 == 100) {
Console.WriteLine(tuple.Item1);
}
}
}输出
这将产生以下输出 −
Value = 100 100
示例
现在让我们看另一个示例在 C# 中实现 1 元组 −
using System;
public class Demo {
public static void Main(string[] args) {
Tuple<string> tuple = new Tuple<string>("amit");
Console.WriteLine("Value = " + tuple.Item1);
if (tuple.Item1 == "tom") {
Console.WriteLine(tuple.Item1);
}
if (tuple.Item1 == "amit") {
Console.WriteLine("Exists: Tuple Value = " +tuple.Item1);
}
}
}输出
这将产生以下输出 −
Value = amit Exists: Tuple Value = amit
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP