在 C# 中连接 int 和 list
Concatenating int and list in c#
我有一个 int 列表候选键和一个 int randnumber,它们具有一定的价值。对于每个候选键,我想添加随机数。
怎么办?我试过这个:
foreach (int l in candidatekey)
{
candidatekey.Add( randnumber);
}
如果我没理解错的话,你想给每个候选键号加上随机数。如果是这样的话,试试这个。
var candidatekey = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
var randomnumber=42;
//we are using LINQ on list
candidatekey=candidatekey.Select(c => c+randomnumber).ToList();
我有一个 int 列表候选键和一个 int randnumber,它们具有一定的价值。对于每个候选键,我想添加随机数。
怎么办?我试过这个:
foreach (int l in candidatekey)
{
candidatekey.Add( randnumber);
}
如果我没理解错的话,你想给每个候选键号加上随机数。如果是这样的话,试试这个。
var candidatekey = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
var randomnumber=42;
//we are using LINQ on list
candidatekey=candidatekey.Select(c => c+randomnumber).ToList();