Saturday, 15 May 2010

c# - Is it possible to cast an element directly to an Array? -



c# - Is it possible to cast an element directly to an Array? -

is there way cast single object of t t[]

an illustration of used in while passing single string functions requires string[]

example

void existingmethod(string[] sa); void main() { string s; existingmethod(s); //<= problem there syntax allows type of cast? }

not interested in solution this

string [] singleelementarray = new string[1]; singleelementarray[0] = s; existingmethod(singleelementarray)

i'm looking see if c# allows type of casting.

i thought saw way java allows wrapping ([s]) []. c# have type of syntax?

note, not interested in creating array of 1 , assigning it...

there's no cast allow this, can create array on fly with

string s = "blah"; foo(new [] { s });

c# casting

No comments:

Post a Comment