Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Need to replace this with one line of code

Posted on 2011-09-12
4
208 Views
Last Modified: 2013-12-17
           string[] columns = new string[1];
            columns[0] = "A";
0
Comment
Question by:newbieweb
  • 2
  • 2
4 Comments
 
LVL 23

Assisted Solution

by:wdosanjos
wdosanjos earned 500 total points
ID: 36523472
string[] columns = {"A"};
0
 

Author Comment

by:newbieweb
ID: 36523575
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
 
LVL 23

Accepted Solution

by:
wdosanjos earned 500 total points
ID: 36523690
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
 

Author Closing Comment

by:newbieweb
ID: 36524152
Thanks!
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question