Home All Groups Group Topic Archive Search About

Simple questions about interfaces

Author
5 May 2006 7:00 AM
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?

Author
5 May 2006 7:04 AM
Water Cooler v2
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.
Author
5 May 2006 7:15 AM
Peter Kirk
"Water Cooler v2" <wtr_***@yahoo.com> skrev i en meddelelse
news:1146812644.879988.144020@u72g2000cwu.googlegroups.com...
> 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
Author
5 May 2006 12:10 PM
Cowboy (Gregory A. Beamer)
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!
*************************************************
Show quoteHide quote
"Peter Kirk" <p*@alpha-solutions.dk> wrote in message
news:%23UrUpOBcGHA.3504@TK2MSFTNGP04.phx.gbl...
>
> "Water Cooler v2" <wtr_***@yahoo.com> skrev i en meddelelse
> news:1146812644.879988.144020@u72g2000cwu.googlegroups.com...
>> 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
>
Author
5 May 2006 8:04 AM
Göran_Andersson
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.

Water Cooler v2 wrote:
Show quoteHide quote
> 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.
>
Author
5 May 2006 10:21 AM
Greg Young
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
Show quoteHide quote
"Göran Andersson" <gu***@guffa.com> wrote in message
news:eSsrVqBcGHA.3388@TK2MSFTNGP05.phx.gbl...
> 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.
>
> Water Cooler v2 wrote:
>> 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.
>>
Author
15 May 2006 6:56 PM
_DD
On Fri, 5 May 2006 06:21:57 -0400, "Greg Young"
<DruckDruckGo***@hotmail.com> wrote:

>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.