C# 程序返回具有重复元素的集合
若要在 C# 中返回具有重复元素的集合,请使用 Enumerable.Repeat 方法。
它是 System.Linq 命名空间的一部分。
假设你需要重复一个数字两次,为此设置该数字和重复频率。
Enumerable.Repeat(50, 2);
现在将其分配给一个变量并显示它。
示例
using System;
using System.Linq;
class Demo {
static void Main() {
// repeating element 50, two times
var num = Enumerable.Repeat(50, 2);
// displayig repeating elements
foreach (int ele in num) {
Console.WriteLine(ele);
}
}
}输出
50 50
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
安卓
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP