Need to replace this with one line of code

           string[] columns = new string[1];
            columns[0] = "A";
newbiewebSr. Software EngineerAsked:
Who is Participating?
 
wdosanjosConnect With a Mentor Commented:
string[] columns = {"A"} is a shortcut to string[] columns = new string[]{"A"}.  This type of shortcut can only be used during variable declaration.  So, when you call a function with an array parameter you should use the following syntax:

myfunction( new string[] {"A"} );

0
 
wdosanjosConnect With a Mentor Commented:
string[] columns = {"A"};
0
 
newbiewebSr. Software EngineerAuthor Commented:
Fine, but when I try and use {"A"} in a function parameter that expects string[] column, I get the following error:

"Invalid expression term '{"

Why?
0
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.