I’m using lambda expression and trying convert into uint while adding into the Hashset. Here what I’m doing:
HashSet<uint> LeadsInSession = new HashSet<uint>();
if (HttpContext.Current.Session["Category_SelectedLeadIds"] != null)
{
Dictionary<LeadPurchase.CategoryLeadSearch, List<string>> toRemoveLeadsIDs =
(Dictionary<LeadPurchase.CategoryLeadSearch, List<string>>)HttpContext.Current.Session["Category_SelectedLeadIds"];
LeadPurchase.CategoryLeadSearch searches = (LeadPurchase.CategoryLeadSearch)HttpContext.Current.Session["searches"];
var toAdd = toRemoveLeadsIDs.Where(Pair => Pair.Key.VerticalID == searches.VerticalID)
.Select(Pair => Pair.Value)
.ToList();
foreach (var lead in toAdd)
LeadsInSession.Add(lead);// I need to convert lead into uint. Convert.ToUInt32() didn't work here.
}
Any way around?
Your problem is that
toRemoveLoasIOsis a dictionary with a value type ofList<string>. ThereforetoAddwill beIEnumerable<List<string>>, and thusleadisList<string>which, quite reasonably will not convert touint.You need to iterate over both
toAddand, an inner loop, overleadand then you have the individualstrings to convert. Something like: