|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Simple questions about interfacesSorry! 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" <wtr_***@yahoo.com> skrev i en meddelelse Haha. You know, I'm exactly the same. Get stuck on some issue. Can't get 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. 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 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. -- Show quoteHide quoteGregory A. Beamer ************************************************* Think Outside the Box! ************************************************* "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 > 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. > 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. >> 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 Greg, can you explain a bit more? I guess you are referring to>items associated with it (as a type) though this is not allowed in C# or any >other major language :) 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. |
|||||||||||||||||||||||