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?

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

3 Answers3

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

And what other uses does it have?

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

TypeIA
  • 16,916
  • 1
  • 38
  • 52
3
return new int[] {element1, element2};

Inline declaration.

Jakob Bowyer
  • 33,878
  • 8
  • 76
  • 91
-2

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

AD.Net
  • 13,352
  • 2
  • 28
  • 47
  • 2
    OP wants an "anonymous array", not an "anonymous type". It's shaky terminology but this interpretation is too literal, I think. –  Jan 20 '14 at 16:54