Basically, I want to be able to use string.Split(char[]) without actually defining a char array as a separate variable. I know in other languages you could do like string.split([' ', '\n']); or something like that. How would I do this in C#?
3 Answers
It's not pretty, but: string.Split(new char[] { ' ', '\n' });
2 Comments
Eric Lippert
Note that in C# 3 you can make this slightly prettier by eliding the "char". The compiler will work out that new[]{x,y,z} means "new array of the best common type of x, y and z".
Chris Schmich
Awesome, good to know. I'm guessing this is possible because of the type inference work done for LINQ.