My initialization is:
List<string> convertedList = new List<string>();
List<KeyValuePair<string, int>> originalList = new List<KeyValuePair<string, int>>();
And I basically want to populate convertedList
with only the string values in originalList
So if originalList
has some items: ["foo",5],["bar",16],["baz",100]
,
I want convertedList
to contain: ["foo"],["bar"],["baz"]
So far I've tried:
for (int i = 0; i <= originalList.Count; i++)
{
convertedList.Add(actions.ToString());
}
but with no luck.
Oh, and keep in mind that I'm a newbie and the answers to this might be really obvious.
Thanks for helping me out!
And how would I go about proceeding if I want to convert only the first X items?
List<String> convertedList = originalList.Select(x => x.Key).ToList();
Or:
convertedList.AddRange(originalList.Select(x => x.Key));
Sticking to the original syntax:
foreach (KeyValuePair<string, int> kvp in originalList)
{
convertedList.Add(kvp.Key);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With