Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use C# Initialization Syntax to pass a parameter?

Tags:

c#

c#-4.0

In C#, using the initialization syntax I can say:

string[] mystrings = {"one", "two", "three"};

Is it possible to use the same array initialization syntax to convert this:

string test = "This is a good sentance to split, it has at least one split word to split on.";
string[] mystrings = test.Split(new string[] { "split" }, StringSplitOptions.RemoveEmptyEntries);

Into something like this:

string test = "This is a good sentance to split, it has at least one split word to split on.";
string[] mystrings = test.Split({ "split" }, StringSplitOptions.RemoveEmptyEntries);

It seems like it should work but I can't get it to do anything.

like image 269
Nate Zaugg Avatar asked Dec 28 '22 11:12

Nate Zaugg


1 Answers

Almost there:

string[] mystrings = test.Split(new[]{ "split" }, 
    StringSplitOptions.RemoveEmptyEntries);
like image 194
Darin Dimitrov Avatar answered Jan 03 '23 17:01

Darin Dimitrov