Search code examples
c#asp.netsyntaxinterfacemodifiers

Using the 'new' modifier with interfaces at a given index like 'var b = new ISomeInterface[0];', what does it mean?


I've come across the following C# syntax for the first time, I would have discarded it as a syntax error except that VS is absolutely happy with it and compiles.

var a = new ISomeInterface[0];

The interface is declared as

public interface ISomeInterface
{
}

Links to further reading are also highly appreciated.


Solution

  • You've created an array of ISomeInterface.

    This is the same as declaring any other array, such as:

    string[] a = new string[0];
    

    I kinda did a double-take on that at first too, because at first glance it appeared the code was instantiating an interface, something you can't normally do.