Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Implicit array declaration

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#?

like image 945
The.Anti.9 Avatar asked Dec 28 '22 17:12

The.Anti.9


1 Answers

Here's a really nice way to do it:

string[] s = myString.Split("abcdef".ToCharArray());

The above is equivalent to:

string[] s = myString.Split('a', 'b', 'c', 'd', 'e', 'f');
like image 182
Dan Tao Avatar answered Dec 31 '22 05:12

Dan Tao