I have a data object
Data = class
public
s: string;
i: Integer;
end;
with many of them in a list (or some collection):
var ol : List<Data> := new List<Data>;
ol.Add(new Data(s := 'One', i := 1));
ol.Add(new Data(s := 'Two', i := 2));
ol.Add(new Data(s := 'Three', i := 3));
ol.Add(new Data(s := 'Four', i := 4));
ol.Add(new Data(s := 'Five', i := 5));
And I want to put it in a dictionary:
var l: Dictionary<string, data> := new Dictionary<String,Data>;
I know I can do a for or for each loop to do this
for each d in ol do
begin
l.Add(d.s, d);
end;
But I want to either use a LINQ statement (preferred) or a For Loop expression. It is easy when only returning one element, but not sure on the syntax for the two elements for a Dictionary.