0

What is the meaning in this code where it reads "new[] {}" ?

public Cube(Game game) : base(game)
{
    vertices = Buffer.Vertex.New(
        game.GraphicsDevice,
        new[]
            {
                new VertexPositionColor(new Vector3(-1.0f, 1.0f, -1.0f), Color.OrangeRed),
                new VertexPositionColor(new Vector3(-1.0f, 1.0f, 1.0f), Color.OrangeRed),
            });
}
Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
user2260199
  • 877
  • 4
  • 13
  • 20
  • It's an example of object initialization. It's declaring a new array of `VertexPositionColor` with a length of 2 and initializing the 2 elements by the call to `new VertexPositionColor`. – Tim Aug 15 '14 at 04:24
  • See: [Object and Collection Initializers](http://msdn.microsoft.com/en-us/library/bb384062.aspx) – Mike Aug 15 '14 at 04:26
  • possible duplicate of [Initializing an Array of Structs in C#](http://stackoverflow.com/questions/309496/initializing-an-array-of-structs-in-c-sharp) – Sean Vieira Aug 15 '14 at 04:26

1 Answers1

4

Just creating an implicity typed array, in your code it is a VertexPositionColor[] with two elements.

EduardoS
  • 199
  • 1
  • 3