Re: Cannot put delegate in interface - why not?
- From: atwomey@xxxxxxxxx
- Date: 29 Jun 2006 04:14:59 -0700
Jon Skeet [C# MVP] wrote:
atwomey@xxxxxxxxx wrote:
When I try and place a delegate in an interface, like this :
public interface ITest {
double foo();
delegate void bar();
}
I get an error "delegates cannot declare types". What is it about a
delegate that makes it incompatible in an interface. I know that an
interface cannot have any implementation - is there some implementation
detail in a delegate that I don't know about?
You've tried to do something like:
public interface ITest
{
public class Foo
{
}
}
Declaring a delegate is declaring a type, which can't be part of an
interface. You should declare the delegate itself elsewhere - you can
have a member of the type which *uses* the delegate, but that's a
different matter.
Jon
Thanks for your replies - I think my question is : is the delgate a
type because it inherits from System.Delgates, even though the delegate
itself is not instantiated? I always thought of a delegate as a
"function pointer", but it's also a class and therefore a type.
.
- Follow-Ups:
- Re: Cannot put delegate in interface - why not?
- From: Ignacio Machin \( .NET/ C# MVP \)
- Re: Cannot put delegate in interface - why not?
- From: Marc Gravell
- Re: Cannot put delegate in interface - why not?
- References:
- Cannot put delegate in interface - why not?
- From: atwomey
- Re: Cannot put delegate in interface - why not?
- From: Jon Skeet [C# MVP]
- Cannot put delegate in interface - why not?
- Prev by Date: Re: Windows Service - Event Log
- Next by Date: Re: Counterpart of the 'synchronized' java keyword?
- Previous by thread: Re: Cannot put delegate in interface - why not?
- Next by thread: Re: Cannot put delegate in interface - why not?
- Index(es):
Relevant Pages
|