Simple question of syntax

  • Thread starter David P. Donahue
  • Start date
D

David P. Donahue

How do I create an array of something in-line? That is, I'm calling a
function which takes an array of strings as an argument. Knowing how
many elements are in the array and what they are, how would I create
that array within the function call itself? (Something I did often in
VB, but just can't seem to find the correct syntax in C#.)


Regards,
David P. Donahue
(e-mail address removed)
 
D

Dennis Myrén

Function(new string [2] { "Like ", "this" });
or
Function(new string [] { "Like ", "this" });

The element size specifier is actually optional, as the compiler already
knows it will be 2.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top