Simple questions about interfaces

  • Thread starter Thread starter Water Cooler v2
  • Start date Start date
W

Water Cooler v2

Sorry! I know these are basic, stupid questions, and I already knew the
answers to these, I swear, and I have used them countless times, I
swear, but at the moment I am fighting a bout of amnesia and it is
extremely important for me to know the answers just now.


Can an interface have:

1. a private field?
2. a public member variable instead of having a public property
declaration?
3. a public member variable initialized with some value?
 
sorry, please ignore. To get my memory back, I just tried this code
out. It took about five seconds. Got my answers. I am such a dick
sometimes.


1. a private field?
A: No


2. a public member variable instead of having a public property
declaration?
Ans: No


3. a public member variable initialized with some value?
Ans: No. It cannot even have a member.


Sorry again.
 
Water Cooler v2 said:
sorry, please ignore. To get my memory back, I just tried this code
out. It took about five seconds. Got my answers. I am such a dick
sometimes.

Haha. You know, I'm exactly the same. Get stuck on some issue. Can't get
past it. Write a message to a newsgroup... and then you work it out yourself
two minutes later, and realise how lame the questions really were. :-)

Peter
 
To clearify the reason why it can't:

An interface is just a contract for classes to fulfill. An interface can
never contain any data or any code.
 
This is not entirely true ... an interface can techincally have a static
items associated with it (as a type) though this is not allowed in C# or any
other major language :)

Cheers,

Greg
 
How true. The psychological reason is clear. When you are banging away at a
problem, you get caught in a cycle. As soon as you get it off your plate,
your mind has a cleared path to actually solve the problem.

--
Gregory A. Beamer

*************************************************
Think Outside the Box!
*************************************************
 
This is not entirely true ... an interface can techincally have a static
items associated with it (as a type) though this is not allowed in C# or any
other major language :)

Greg, can you explain a bit more? I guess you are referring to
provisions for statics in generated IL code, but how would this work
in practice? I was just considering a related problem (how to
associate constants with an Interface) and thought that it was a
multiple-inheritance problem.
 
Back
Top