17
Reply

Can you declare variable in interface

Mukesh Kumar

Mukesh Kumar

7y
18.8k
4
Reply

    No, it doesn't mean that. The interface doesn't actually contain the property, either.Remember than interface has to be implemented by a class in order for you to use it. An interface only defines a contract, meaning that any class that implements that interface will have all of the members defined by the interface. The interface doesn't actually have those members; it's more like a template. The instance of the class that implements the interface is the one that contains the property, and therefore the private backing field used for the property.Interfaces can only define signatures for the following members:Methods Properties Indexers Events

    We cant declare fields inside the Interface. Note : We can declare abstract properties and functions inside Interface.

    When you declare a variable, it will give "Interface can not contain a field" which means you can;t declare a variable in an interface. So answer is No, we Can't.

    no

    No

    Well now, starting from C# 8.0 preview version you can declare variables in interface
    Default implementation of methods in interface
    As well as body methods

    No,we cannot declare variable inside interface. We can declare property in Interface.

    NO

    No you can not declare variable in interface.

    No, we cannot declare variables, methods, properties, and constructors in the interface

    No, we can't declare variables, constructors, properties, and methods in the interface.

    No, you can not declare 'variable' in interface.Also interface can not contain 'operators'. I have written blogs on interface that will helps you to understand the concept of interface. You can visit on following link https://www.c-sharpcorner.com/blogs/interface-in-c-sharpnet-simple-way-part-one

    interface cannot contains fields

    No.you cannot declare variables in an interface as interface can only contain the signatures of methods, properties, events or indexers

    no,interface cannot contains fields.

    no

    No