0

What are the syntax rules for creating an anonymous array?

i.e.

int[] function()
{
   int element1 = 1;
   int element2 = 2;
   return //array with element1 and element2
{

And what other uses does it have?

2
  • 4
    If you need syntax and general information, try Google. First result for "C# Anonymous Array": msdn.microsoft.com/en-us/library/bb384090.aspx Commented Jan 20, 2014 at 16:51
  • I'm not asking for implicitly typed arrays. Anonymous arrays don't bound itself to identities. Commented Jan 20, 2014 at 16:54

3 Answers 3

10
return new int[] { element1, element2 };

And what other uses does it have?

I'm not sure what you mean here I'm afraid.

Sign up to request clarification or add additional context in comments.

1 Comment

You may not even need to specify int, since it can be inferred from the elements.
3
return new int[] {element1, element2};

Inline declaration.

Comments

-3

You can't return anonymous type and int[] is not anonymous

1 Comment

OP wants an "anonymous array", not an "anonymous type". It's shaky terminology but this interpretation is too literal, I think.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.