gpt4 book ai didi

c# - 如何在 C# 中打印嵌套在列表中的元组?

转载 作者:行者123 更新时间:2023-11-30 21:43:31 25 4
gpt4 key购买 nike

我有一个函数来填充包含 TupleList。它以字典作为参数并填充列表。

我需要它来为文本值分配数值。

为了清关;

我有一个属性部分,其中包括假设;

属性:阴

阴天的文本值:晴天、雨天、有雾等

属性:温度

它的文本值:热、冷、温和

List 具有作为属性的数据、作为文本的值和作为数字的值。

我有数据部分。它具有“晴天、寒冷”、“晴天、炎热”等值。

我的目标是分配数字并表示数据,如“1,2”、“1,3”等。为此,我编写了一个函数。

public List<Tuple<string, string, int>> SetNumAttrb(Dictionary<string, string[]> dic)
{
List<Tuple<string, string, int>> attNumNom = new List<Tuple<string, string, int>>();
int ctrl = 1;
foreach (KeyValuePair<string, string[]> kvp in dic)
{
for (int i = 0; i < kvp.Value.Length; i++)
{
attNumNom.Add(Tuple.Create<string, string, int>(kvp.Key, dic[kvp.Key][i], ctrl));
ctrl++;
}
}
return attNumNom;
}

现在我需要打印它来检查它是否正常工作,我将需要访问它的内容。我怎样才能做到这一点?

最佳答案

这很简单。只需遍历列表并打印元组的内容。

List<Tuple<string, string, int>> list = SetNumAttrb(dict);

foreach (var tuple in list)
{
Console.WriteLine("{0} - {1} - {2}", tuple.Item1, tuple.Item2, tuple.Item3.ToString());
}

关于c# - 如何在 C# 中打印嵌套在列表中的元组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41660720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com