Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / February 2008

Tip: Looking for answers? Try searching our database.

delegate in interfaces vb.net vs c#

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
HelloWorld - 29 Feb 2008 08:58 GMT
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#?
HelloWorld - 29 Feb 2008 09:09 GMT
I mean the question is from interface perspective... i could define delegate in vb.net interface but not in C#...

 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#?
Jon Skeet [C# MVP] - 29 Feb 2008 09:13 GMT
> 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#
>
[quoted text clipped - 4 lines]
>
> 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...

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

HelloWorld - 29 Feb 2008 09:22 GMT
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...

>> I could define delegates in VB.NET code
>>
[quoted text clipped - 20 lines]
> if you can *use* a nested type defined like this from C#. Will try it
> another time...
Jon Skeet [C# MVP] - 29 Feb 2008 09:31 GMT
> 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?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

HelloWorld - 29 Feb 2008 09:48 GMT
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.

:)

>> 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...
[quoted text clipped - 19 lines]
> Just to clarify - do you have a VB interface which you need to
> implement in C#, or a slightly different situation?
Jon Skeet [C# MVP] - 29 Feb 2008 10:10 GMT
> 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.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

HelloWorld - 29 Feb 2008 11:32 GMT
thanks :)

>> No its exactly the same situation. One of our other team were having
>> these
[quoted text clipped - 28 lines]
>
> Note that you don't need to "implement" IFoo.Abc.
HelloWorld - 29 Feb 2008 12:57 GMT
thanks :)

>> No its exactly the same situation. One of our other team were having
>> these
[quoted text clipped - 28 lines]
>
> Note that you don't need to "implement" IFoo.Abc.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.