Mukesh Kumar
Can you declare variable in interface
By Mukesh Kumar in C# on Aug 21 2017
  • Bharathi Raja
    Feb, 2018 1

    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

    • 2
  • Sreekanth Reddy
    Mar, 2018 8

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

    • 1
  • Ashish Gope
    Nov, 2017 23

    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.

    • 1
  • Gopisetty Vvsskiran
    Nov, 2017 16

    no

    • 1
  • Yogesh Sevankar
    Oct, 2019 18

    No

    • 0
  • Ishoo Anyal
    Sep, 2019 28

    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

    • 0
  • sushil kumar
    Mar, 2019 11

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

    • 0
  • Udit Chauhan
    Jul, 2018 18

    NO

    • 0
  • VINAY MISHRA
    Jun, 2018 12

    No you can not declare variable in interface.

    • 0
  • Mounika Chandrapati
    Jun, 2018 11

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

    • 0
  • Mounika Chandrapati
    Jun, 2018 11

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

    • 0
  • Shrimant Telgave
    May, 2018 2

    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

    • 0
  • Pravinkumar Birajdar
    Apr, 2018 10

    interface cannot contains fields

    • 0
  • Akbar Mulla
    Mar, 2018 20

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

    • 0
  • Satish Sanaboyina
    Mar, 2018 15

    no,interface cannot contains fields.

    • 0
  • bebo bebo
    Nov, 2017 25

    no

    • 0
  • Mukesh Kumar
    Aug, 2017 21

    No

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS