Skip to content

Why can't we have fields in C# interfaces? #3

@ShervanN

Description

@ShervanN

Hello,

I googled this question but I cannot understand it well.
In C#, We can have a property in interfaces but we cannot have fields. Could you please why?

I've seen the below description here

Interfaces don’t allow fields because they consist of a contract that is a **list of methods**, whose implementation is provided by a class. **Properties are implemented as methods (get and set accessors)**, so they fit this model. But fields are just data locations, so it doesn’t make sense to include them in an interface.

Is it true? In C#, Are Properties implemented as methods (get and set accessors)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions