Adding a property to an interface that's a List
This compiles:
public interface IBookCatalogueView
{
Book[] Books
{
get;
set;
}
}
This doesn't, giving the error "Interfaces cannot contain fields"
public interface IBookCatalogueView
{
List<Book> Books
{
get;
set;
}
}
>
开发者_JAVA技巧Why? How can I define a property that's a list in an interface?
This (your second example) does compile:
public interface IBookCatalogueView
{
// Property
List<Book> Books
{
get;
set;
}
}
This does not:
public interface IBookCatalogueView
{
// Field
List<Book> Books;
}
Check your syntax. Did you sneak an accidental ;
in there, perhaps?
This doesn't, giving the error "Interfaces cannot contain fields"
public interface IBookCatalogueView
{
List<Book> Books
{
get;
set;
}
}
But this is not fields but instead property and hence will compile fine.
精彩评论