I have:
IEnumerable<string> c = codigo_incidencia.Split('#');
I need to cast "c" to be an IEnumerable<int>
. I don´t know how to do this cast in C#.
Can someone help me?
Shortest way is to using linq .Select
likewise:
var c = codigo_incidencia.Split('#').Select(int.Parse);
If you are not sure that the sections are valid ints then you'd want to use a TryParse
as in: Select parsed int, if string was parseable to int. And if working with C# 7.0 you can look at this answer of the question:
var result = codigo_incidencia.Split('#')
.Select(s => new { Success = int.TryParse(s, out var value), value })
.Where(pair => pair.Success)
.Select(pair => pair.value);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments