从字典创建字符串数组

编程入门 行业动态 更新时间:2024-10-26 23:39:38
本文介绍了从字典创建字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好

我有以下内容:

IDictionary<String, IList<String>> data;

推荐答案

以下内容可能会为您解决此问题或给您一些想法:

The following might either solve this for you or give you some ideas: using System; using System.Collections.Generic; namespace MatrixLambda { class Program { static void Main(string[] args) { // Load test data. IDictionary<String, IDictionary<String, IList<String>>> data = new Dictionary<String, IDictionary<String, IList<String>>>(); data.Add("A", new Dictionary<String, IList<String>>()); data["A"].Add("AX", new List<String>()); data["A"]["AX"] = new string[] { "Hello", "World" }; data.Add("B", new Dictionary<String, IList<String>>()); data["B"].Add("BY", new List<String>()); data["B"]["BY"] = new string[] { "Good", "Evening" }; // Here is the lambda for the function that determines what goes in each cell given zero-based row and col index. Func<int, int, string> f = (row, col) => col == 0 ? data["A"]["AX"][row] : data["B"]["BY"][row]; String[,] result = new string[2, 2]; // Apply function to determine what goes in each cell. for (int row = 0; row <= result.GetUpperBound(0); row++) { for (int col = 0; col <= result.GetUpperBound(1); col++) { result[row, col] = f(row, col); } } // Print for diagnostic. for (int row = 0; row <= result.GetUpperBound(0); row++) { for (int col = 0; col <= result.GetUpperBound(1); col++) { if (col != 0) Console.Write(' '); Console.Write(result[row, col]); } Console.WriteLine(); } } } }

更多推荐

从字典创建字符串数组

本文发布于:2023-10-28 02:08:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535192.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   字符串   字典

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!