你好
我有以下内容:
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(); } } } }
更多推荐
从字典创建字符串数组
发布评论