我正在玩本地函数,如果它包含具有相同名称的本地函数,则无法弄清楚如何调用host函数.
class Program
{
static void Main(string[] args)
{
new Test().Foo();
Console.Read();
}
}
class Test
{
public void Foo()
{
Console.WriteLine("Host function");
void Foo()
{
Console.WriteLine("Local function");
}
Foo(); // This calls the local function
Foo(); // I would like to call the host Foo() recursively here
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个数组列表:
var inp = new List<int[]>()
{
new int[]{11,12,13},
new int[]{21,22,23},
new int[]{31,32,33},
new int[]{41,42,43},
new int[]{51,52,53},
};
Run Code Online (Sandbox Code Playgroud)
我想把它转换成一对列表.我可以使用基本for循环以某种方式完成此操作.但我正在寻找使用LINQ的更简单的分拣机解决方案.
这是我到目前为止:
var outp = new List<KeyValuePair<int, int>>();
var rowlen = inp[0].Length;
for (int i = 0; i < inp.Count; i++)
for (int j = 0; j < rowlen; j++)
outp.Add(new KeyValuePair<int, int>(i * rowlen + j, inp[i][j]));
Run Code Online (Sandbox Code Playgroud)
期望的输出如下所示:
0 11
1 12
2 13
3 21
4 22
5 23
6 31
7 32
8 33
9 41
10 42
11 …Run Code Online (Sandbox Code Playgroud)