[英]How can ı remove from duplicated items in C#?
I have a list in the below it has 18 value .I have another list(include unique 6 value ) created by random numbers(1,18), and they are unique.我在下面有一个列表,它有18 个值。我有另一个由随机数(1,18)创建的列表(包括唯一的 6 个值) ,它们是唯一的。
When i do these for example elidenkiKartlar
list shows me 6 unique values, but i have 2 list more in other lists, I have same values for example in elindekiKartlar=K1,K3,S4,RD-1,S2,M4
in another list K1,K4,RD-2,S4,K3
, i have same values (K1,K3)
eg当我执行这些操作时,例如
elidenkiKartlar
列表显示了 6 个唯一值,但我在其他列表中还有 2 个列表,例如在另一个列表K1,K4,RD-2,S4,K3
中的elindekiKartlar=K1,K3,S4,RD-1,S2,M4
中有相同的值K1,K4,RD-2,S4,K3
,我有相同的值(K1,K3)
例如
How can i remove them?我怎样才能删除它们? How can I share this big list to 3 equal(6,6,6) part?
我怎样才能将这个大列表分享给 3 个相等(6,6,6)部分?
Thanks for your advise from now..从现在开始感谢您的建议..
public List<string> kartlar = new List<string>
{
"S1",
"S2",
"S3",
"S4",
"S5",
"M1",
"M2",
"M3",
"M4",
"M5",
"K1",
"K2",
"K3",
"K4",
"K5",
"RD-1",
"RD-2",
"RD-3",
};
//Creating uniqe random list
int [] sayilar=new int[6];
for (int i = 0; i < sayilar.Length; i++)
{
essiz:
sayilar[i] = random.Next(0, 18);
for (int j = 0; j < i; j++)
{
if (sayilar[i]==sayilar[j])
{
goto essiz;
}
}
}
//Adding string items by randomList index
foreach (var sayi in sayilar)
{
elindekiKartlar.Add(kartlar[sayi]);
}
Use Distinct Method
使用
Distinct Method
var uniqueValues = kartlar.Distinct().ToList();
Try this尝试这个
elindekiKartlar.Distinct();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.