I have a Table to store constants with columns(Name, Value). How do I go about getting the result of LINQ query in name value format like (Name = Value) so I can obtain the values like
Var thisVal 开发者_开发问答= VarCollection("Name")
Hope this is clear.
Thanks in advance.
I don't have a compiler handy to test this, but it'll go something like:
var VarCollection = (from t in Table
select new { t.Name, t.Value})
.ToLookup(t=>t.Name, t=>t.Value);
UPDATE: Upon reflection, I'm pretty sure that can be reduced to just:
var VarColelction = Table.ToLookup(t=>t.Name, t=>t.Value);
You could use a select to put them into a KeyValuePair and then put those into a Hash (basically a set of KeyValuePairs), then refer to the variables by name.
精彩评论