delegate in interfaces vb.net vs c#

  • Thread starter Thread starter HelloWorld
  • Start date Start date
H

HelloWorld

Hi,

I could define delegates in VB.NET code

Public Interface Interface1
Delegate Function Abc()
End Interface

wherer as the following was not allowed in C#

interface Interface1
{
delegate void Abc();
}

what could be reasons behing this being allowed in VB.NET and not in C#?
 
I mean the question is from interface perspective... i could define delegate in vb.net interface but not in C#...

"HelloWorld" <no_mails_AT_to_me_.com> wrote in message Hi,

I could define delegates in VB.NET code

Public Interface Interface1
Delegate Function Abc()
End Interface

wherer as the following was not allowed in C#

interface Interface1
{
delegate void Abc();
}

what could be reasons behing this being allowed in VB.NET and not in C#?
 
I could define delegates in VB.NET code

Public Interface Interface1
Delegate Function Abc()
End Interface

Hmm, interesting.
wherer as the following was not allowed in C#

interface Interface1
{
delegate void Abc();
}

what could be reasons behing this being allowed in VB.NET and not in C#?

Interfaces don't allow nested types at all in C#, whether delegates or
not. I'm not sure I've ever desired them, to be honest. I'm not sure it
makes much sense.

I'm quite surprised they're allowed in VB (and indeed in IL). I wonder
if you can *use* a nested type defined like this from C#. Will try it
another time...
 
Thanks Jon. Though i am new here, I have seen many many many posts of yor
over here ... thanks for your efforts for the community...

Yes i could implement this vb interface in C# class, bind an event to this
delegate 'handler' and execute this event...
 
Thanks Jon. Though i am new here, I have seen many many many posts of yor
over here ... thanks for your efforts for the community...

My pleasure - very literally. I wouldn't post if I didn't enjoy it :)
Yes i could implement this vb interface in C# class, bind an event to this
delegate 'handler' and execute this event...

This is why it doesn't make much sense to me to have the delegate type
in an interface - it's something that you wouldn't need to implement,
because it's just a type declaration. If you want the interface to
specify a member to be implemented (such as a property or event) which
is *of* a particular type, that's a different matter.

It's worth being clear about the difference between declaring a new
delegate type, and declaring a variable/property/event of that type.
Hopefully
http://pobox.com/~skeet/csharp/events.html will help even though it's
in C#. I'm sure the same things apply to VB.

Just to clarify - do you have a VB interface which you need to
implement in C#, or a slightly different situation?
 
No its exactly the same situation. One of our other team were having these
VB.NET interfaces having these delegates in them. They wanted to implement
these on C# interfaces and were fumbling with not being able to create these
for C# (from rather wondring perspective to 'implement' those delegates). It
came down to C# can not allow this being done and hence the query.

:)
 
No its exactly the same situation. One of our other team were having these
VB.NET interfaces having these delegates in them. They wanted to implement
these on C# interfaces and were fumbling with not being able to create these
for C# (from rather wondring perspective to 'implement' those delegates). It
came down to C# can not allow this being done and hence the query.

Just tried it, and basically you don't need to do anything with the
delegate types. They're just extra types which are available. Here's an
example:

IFoo.vb:

Public Interface IFoo
Function GimmeString() As String
Delegate Function Abc() As Object
End Interface

Foo.cs:

class Foo : IFoo
{
public string GimmeString()
{
return "Yes";
}
}

Note that you don't need to "implement" IFoo.Abc.
 
thanks :)

Jon Skeet said:
Just tried it, and basically you don't need to do anything with the
delegate types. They're just extra types which are available. Here's an
example:

IFoo.vb:

Public Interface IFoo
Function GimmeString() As String
Delegate Function Abc() As Object
End Interface

Foo.cs:

class Foo : IFoo
{
public string GimmeString()
{
return "Yes";
}
}

Note that you don't need to "implement" IFoo.Abc.
 
thanks :)

Jon Skeet said:
Just tried it, and basically you don't need to do anything with the
delegate types. They're just extra types which are available. Here's an
example:

IFoo.vb:

Public Interface IFoo
Function GimmeString() As String
Delegate Function Abc() As Object
End Interface

Foo.cs:

class Foo : IFoo
{
public string GimmeString()
{
return "Yes";
}
}

Note that you don't need to "implement" IFoo.Abc.
 
Back
Top