and has 2 comments
I found these cool websites where you can solve software challenges. Completely randomly I find out about this method that I found pretty cool, called Array.ConvertAll. Imagine you want to transform a string containing a space separated list of integers into an actual list of integers. You would use Array.ConvertAll(line.Split(' '),int.Parse). That is it. I liked the simplicity of it and also the fact that it works out of the box without having to import any namespace. The same thing can be achieved with LINQ thus: line.Split(' ').Select(int.Parse).ToArray(), but you need to import the System.Linq namespace.

Unfortunately, the same day I found about this method that I had never used before yet is there since .NET 2.0, I noticed that it doesn't exist in .NET Core. Like a butterfly, it only lived one day in my development repertoire.

Comments

Siderite

Yeah, you're right! I'll edit the post. I actually thought of it that way when I wrote it, then somehow it came out as a lambda. Booo, me!

Siderite

Cristian Lupașcu

Note that the LINQ version can be shortened to `line.Split(' ').Select(int.Parse).ToArray()`, which looks pretty sweet IMHO. I didn't know about `Array.ConvertAll()`. Thanks for sharing!

Cristian Lupașcu

Post a comment