I wrote the following code parsing a csv file:
var result = FullFile.Split('\n')
.Select(s => new
{ FirstName = s.Split(',')[(int)FirstName.Value],
SirName = s.Split(',')[(int)sirName.Value],
garde = s.Split(',')[(int)Grade.Value] });
Now, I use the function Split too many times with the same arguments, and on the same object.
Is there a way to carry on using the lambada expression, and cut down this function calls?
Any other comments on my coding are welcome
Yes, you can split once in the first Select, and pass the result down the chain to the second Select, like this:
var result = FullFile
.Split('\n')
.Select(line => line.Split(','))
.Select(tt => new
{ FirstName = tt[(int)FirstName.Value],
SirName = tt[(int)sirName.Value],
garde = tt[(int)Grade.Value] });
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