I'm getting the below error when trying to create a Key,Value pair and load it into a HashTable
Cannot implicitly convert type
'System.Collections.Generic.IEnumerable<AnonymousType#1>'
to 'System.Collections.Hashtable'. An explicit conversion exists (are you missing a cast?)
Below is the code snippet
hashtable selectedValues = radTree.CheckedNodes.Where(node => node.Level == 0).Select(row => new
{
key = row.Value,
Value = row.Text
});
In the above query I'm trying to get the Key and Value of selected checkboxes (for a particular level) in a Telerik RadTreeControl and load them into a hashtable.
Is there a way in LINQ that we could cast the result to hashtable or is it better that I just go with Dictionary since we have the ToDictionary()
method available ?
Better to just use a Dictionary.
Otherwise you can use ToDictionary and then pass that to the constructor of a hashtable if you really want.