C#&.NET 6应用程序编程开发中,假如有如下的List集合:
List
var list = new List{"1","5","3","3","1","1","2","3","6","6","1","1"};
有什么方法可以将集合list中相邻重复的元素删除呢?比如上例期望得到的结果为:
list
1,5,3,1,2,3,6,1
Rector
2021-12-27 提问
使用while循环语句,对比集合(数组)中当前下标元素与下一个元素是否相同,代码示例如下:
while
运行结果为:
2021-12-27 回答
码龄: 3091天
专注.NET/.NET Core