C # Implicit array declaration

Basically, I want to be able to use string.Split(char[]) without actually defining the char array as a separate variable. I know other languages ​​that you could do like string.split([' ', '\n']); or something like that. How can I do this in C #?

+4
source share
3 answers

Here's a really good way to do this:

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

The above is equivalent to:

 string[] s = myString.Split('a', 'b', 'c', 'd', 'e', 'f'); 
+8
source

This is not very, but: string.Split(new char[] { ' ', '\n' });

+1
source

you can use this overload:

 public String [] Split(params char [] separator) 

like this:

 yourstring.Split(' ', '\n') 
+1
source

Source: https://habr.com/ru/post/1309232/


All Articles