Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#可枚举收益率和foreach_C# - Fatal编程技术网

C#可枚举收益率和foreach

C#可枚举收益率和foreach,c#,C#,今天的教授让我们在课堂上用C来解决这个练习#谁能帮我解决我迷路了 本练习和下一个练习的目的是强调枚举和 收益率和收益率报表。 声明一个通用静态方法Flatten,该方法将IEnumerable数组作为参数,并返回 IEnumerable。使用foreach语句和yield-return语句。该方法应该具有以下特性: 标题: 公共静态IEnumerable展平(IEnumerable[]ebles){…} 如果按如下所示调用该方法,则应得到2 3 5 7 2 3 5 7 2 3 5 7: IEn

今天的教授让我们在课堂上用C来解决这个练习#谁能帮我解决我迷路了

本练习和下一个练习的目的是强调枚举和 收益率和收益率报表。 声明一个通用静态方法Flatten,该方法将
IEnumerable
数组作为参数,并返回
IEnumerable
。使用foreach语句和yield-return语句。该方法应该具有以下特性: 标题:

公共静态IEnumerable展平(IEnumerable[]ebles){…}
如果按如下所示调用该方法,则应得到2 3 5 7 2 3 5 7 2 3 5 7:

IEnumerable<int>[] ebles = new IEnumerable<int>[3];
ebles[0] = ebles[1] = ebles[2] = new int[] { 2, 3, 5, 7 };
foreach (int i in Flatten<int>(ebles))
Console.Write(i + " ");
IEnumerable[]ebles=新的IEnumerable[3];
ebles[0]=ebles[1]=ebles[2]=newint[]{2,3,5,7};
foreach(整平中的int i(ebles))
控制台。写入(i+“”);

您需要两个嵌套的foreach循环。一个迭代每个列表中元素的内部元素。最里面的循环包含一个
收益返回元素


这是提纲。现在去读一下这个提纲中提到的每一个单词。

你具体想得到什么帮助?事实上,这里没有提出任何实际问题…@YuvalItzchakov:这就汇编了。。。你为什么认为不会呢?这是一个整数序列数组…返回新的int[]{2,3,5,7,2,3,5,7,2,3,5,7}方法体:
return ebles.SelectMany(i=>i)
IEnumerable<int>[] ebles = new IEnumerable<int>[3];
ebles[0] = ebles[1] = ebles[2] = new int[] { 2, 3, 5, 7 };
foreach (int i in Flatten<int>(ebles))
Console.Write(i + " ");