Amass

Creating arrays of strings on-the-fly

May 23rd, 2008 Luke

Sometimes you’ll encounter a situation where you need an array of strings, just so that you can pass it into a function. Doing it in two lines is ugly if it’s just a temporary variable - and it tends to pollute your Intellisense. Here’s how to do it in one:

new string[3]{"foo","bar","baz"};

Let’s say you were calling a function that took in an array of strings. You could use it like this:

myFunction(new string[3]{"foo","bar","baz"});

And you’d be good to go!