Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

array to dictionary

Tags:

c#

lambda

I'm trying to get this _valueAdds = List<ValueAddedItemHelper> into gridItems (Dictionary) with _valueAdds being the Key and all the values being false. But I'm not sure how to do this with Lamda. This how far I got below. I did succeed in doing it with a while loop but would like learn to do it with Lamda

gridItems = new Dictionary<ValueAddedItemHelper, bool>();
gridItems = _valueAdds.Select(k => new { k }).ToArray().ToDictionary(t => t, false);
like image 646
Domitius Avatar asked Apr 19 '26 03:04

Domitius


1 Answers

_valueAdds.ToDictionary(t => t, t => false);
like image 184
Femaref Avatar answered Apr 20 '26 16:04

Femaref



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!