array of interface?

  • Thread starter Thread starter haroldsphsu
  • Start date Start date
H

haroldsphsu

Hi,

I understand that I cannot create an instance of an interface, but why
is it ok to do the following? What is it creating?

foo = New System.ComponentModel.IEditableObject(10) {}

whereas the following will get a compiler error ('New' cannot be used
on interface):

foo = New System.ComponentModel.IEditableObject(10)

Thanks,
Harold
 
But why is it an error if I don't specify the empty array element
initializer?
 
I understand that I cannot create an instance of an interface, but why
is it ok to do the following? What is it creating?

foo = New System.ComponentModel.IEditableObject(10) {}

An array with items of type 'IEditableObject' containing 11 elements with
indices 0 through 10.
whereas the following will get a compiler error ('New' cannot be used
on interface):

foo = New System.ComponentModel.IEditableObject(10)

In this case the curly braces are required to make the compiler aware that
an array should be created instead of calling a non-existing constructor.
 
Sorry, I think I got it. Without the array initializer, it's not
actually an array I'm creating.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top