What does the new [] {a, b} and the creator mean?

I found this code

Stream foo() 
{
  ...
  return new MemoryStream(new[] { a, b });
}

and can guess what he is doing, but cannot find an explanation why the type definition byte[]can be omitted. I looked at msdn C # a new explanation, but it is too simple.

+4
source share
4 answers

You can create an implicitly typed array in which the type of the array instance is inferred from the elements specified in the array initializer. The rules for any implicitly typed variable also apply to implicitly typed arrays.

Taken from https://msdn.microsoft.com/en-us/library/bb384090.aspx

+6
source

, .

# , , , , . , () , , c ++.

+2

,

, , new byte[] { a, b }

, byte[]

, , , a, b byte. , , byte s, .

Microsoft . , var, .

+1
source

with this, basically you create an array of objects implicitly!

0
source

Source: https://habr.com/ru/post/1654562/


All Articles