'how to change list's type?
if I have a list like {"4" , "3"},
I want to change that list's type(string to float) -> {4f , 3f}.
Is there a function can help me?
I want {"4" , "3"} to {4f , 3f}
Solution 1:[1]
You could use the List<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> converter) method in combination with the float.Parse() method.
Assuming you have this list of strings:
var strings = new List<string> { "4", "3" };
...it may be called as:
List<float> floats = strings.ConvertAll(s => float.Parse(s));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kaffekopp |
