In my ASP.NET MVC project I have a code like below that I have variable "CheckListItems" with type of "IEnumerable<KeyValuePair<Guid, string>>" that at the end I check a condition to add another item to this variable:
public class Person
{
public Guid ID { get; set; }
public string Caption { get; set; }
}
var chliList = new List<Person>()
{
new Person{ID = Guid.NewGuid(), Caption = "Person1"}
};
var pointRelatedColumns = new List<KeyValuePair<Guid, string>> { };
pointRelatedColumns.Add(new KeyValuePair<Guid, string>(Guid.Parse("00000000-0000-0000-0000-000000000004"), "one"));
var CheckListItems = chliList
.Select(x => new KeyValuePair<Guid, string>(x.ID, x.Caption))
.Union(pointRelatedColumns)
.Union(new List<KeyValuePair<Guid, string>> {
new KeyValuePair<Guid, string>(Guid.Parse("00000000-0000-0000-0000-000000000003"), "two")
});
And I try union below line with the condition that you can see here
but it will not be added:
if (pointValueAbsolute >= selectManMandatoryLevel)
{
var values = new[] {
new KeyValuePair<Guid, string>(Guid.Parse("00000000-0000-0000-0000-000000000006"), "three")
};
CheckListItems.Union(values);
}
How can I solve this problem?
Any help will be appriciated!
question from:
https://stackoverflow.com/questions/65670985/c-sharp-how-union-with-object-of-type-ienumerablekeyvaluepairguid-string 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…