CompanyDroneFromSector7G
CompanyDroneFromSector7G

Reputation: 4517

Interfaces cannot contain fields

probably a really dumb question, but I keep getting the above error with the following code:

public interface IAttributeOption
{
    AttributeTypeCode Type { get; set; }
}

You can probably tell, I'm trying to define an interface with a single property.

I know that somebody is BOUND to tell me "an interface is a virtual class, blah blah" and I want to confirm in advance I KNOW THIS! I'm clearly trying to define a property, which as far as I am aware is fine in an interface.

So what is wrong??

Thanks :)

Upvotes: 14

Views: 16980

Answers (2)

James
James

Reputation: 82096

So what is wrong?

Nothing, your interface declaration is fine. Sounds like you possibly forgot to put your accessor declarations in previously:

public interface IAttributeOption
{
    AttributeType Type; // no { get; set; }
}

If it's a linked assembly you may need to do a full rebuild as you may be pulling in a cached version.

Upvotes: 9

Darin Dimitrov
Darin Dimitrov

Reputation: 1038750

I'm clearly trying to define a property, which as far as I am aware is fine in an interface.

There's nothing wrong with this code. The error you are getting is somewhere else. Just make sure that the AttributeTypeCode class is defined of course.

Upvotes: 6

Related Questions