C# 中的键值对

2023年 8月 27日 43.6k 0

C# 中的键值对

KeyValuePair类使用C#将一对值存储在单个列表中。

设置KeyValuePair并添加元素 −

var myList = new List();

// adding elements
myList.Add(new KeyValuePair("Laptop", 20));
myList.Add(new KeyValuePair("Desktop", 40));
myList.Add(new KeyValuePair("Tablet", 60));

登录后复制

这里是学习如何使用 KeyValuePair 并显示键和值的代码 -

示例

Using System;
using System.Collections.Generic;
class Program {
static void Main() {
var myList = new List();
// adding elements
myList.Add(new KeyValuePair("Laptop", 20));
myList.Add(new KeyValuePair("Desktop", 40));
myList.Add(new KeyValuePair("Tablet", 60));
foreach (var val in myList) {
Console.WriteLine(val);
}
}
}

登录后复制

以上就是C# 中的键值对的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论