PC Review


Reply
Thread Tools Rate Thread

Can we declare delegates in class and can we declare delegates in Interface

 
 
Bhuwan Bhaskar
Guest
Posts: n/a
 
      2nd Oct 2007
Hello,

Can we declare delegates in the class? Can we declare delegates in interface
?

Warm Regards,

Bhuwan


 
Reply With Quote
 
 
 
 
=?Utf-8?B?RWRnYXIgSGFycmlz?=
Guest
Posts: n/a
 
      2nd Oct 2007
Yes and no. The thing to remember about delegates is they are in themselves
classes that inherit from System.Delegate. Since nested classes are allowed
in classes you my declare a delegate in a class. For example the following
is legal:

public class MyClass
{
public delegate void MyDelegate();
}

To reference that delegate outside of MyClass you would write the following:

MyClass.MyDelegate myDel;

Since a delegate is a type that inherits from delegate you cannot declare a
delegate within an interface, because you cannot declare nested types in an
interface. That being said I tend to declare my delegates outside of a class
and inside a namespace, because like I said delegates really are just classes.


"Bhuwan Bhaskar" wrote:

> Hello,
>
> Can we declare delegates in the class? Can we declare delegates in interface
> ?
>
> Warm Regards,
>
> Bhuwan
>
>
>

 
Reply With Quote
 
Bhuwan Bhaskar
Guest
Posts: n/a
 
      3rd Oct 2007
Thnaks Edgar,

Can we declare delegates inside Interface.

Regards,
Bhuwan

"Edgar Harris" <(E-Mail Removed)> wrote in message
news:AF89D711-97E3-4D0C-ADA2-(E-Mail Removed)...
> Yes and no. The thing to remember about delegates is they are in
> themselves
> classes that inherit from System.Delegate. Since nested classes are
> allowed
> in classes you my declare a delegate in a class. For example the
> following
> is legal:
>
> public class MyClass
> {
> public delegate void MyDelegate();
> }
>
> To reference that delegate outside of MyClass you would write the
> following:
>
> MyClass.MyDelegate myDel;
>
> Since a delegate is a type that inherits from delegate you cannot declare
> a
> delegate within an interface, because you cannot declare nested types in
> an
> interface. That being said I tend to declare my delegates outside of a
> class
> and inside a namespace, because like I said delegates really are just
> classes.
>
>
> "Bhuwan Bhaskar" wrote:
>
>> Hello,
>>
>> Can we declare delegates in the class? Can we declare delegates in
>> interface
>> ?
>>
>> Warm Regards,
>>
>> Bhuwan
>>
>>
>>



 
Reply With Quote
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      3rd Oct 2007
Bhuwan Bhaskar wrote:
> Thnaks Edgar,
>
> Can we declare delegates inside Interface.
>
> Regards,
> Bhuwan


Edgar already answered that:

"Since a delegate is a type that inherits from delegate you cannot
declare a delegate within an interface".

> "Edgar Harris" <(E-Mail Removed)> wrote in message
> news:AF89D711-97E3-4D0C-ADA2-(E-Mail Removed)...
>> Yes and no. The thing to remember about delegates is they are in
>> themselves
>> classes that inherit from System.Delegate. Since nested classes are
>> allowed
>> in classes you my declare a delegate in a class. For example the
>> following
>> is legal:
>>
>> public class MyClass
>> {
>> public delegate void MyDelegate();
>> }
>>
>> To reference that delegate outside of MyClass you would write the
>> following:
>>
>> MyClass.MyDelegate myDel;
>>
>> Since a delegate is a type that inherits from delegate you cannot declare
>> a
>> delegate within an interface, because you cannot declare nested types in
>> an
>> interface. That being said I tend to declare my delegates outside of a
>> class
>> and inside a namespace, because like I said delegates really are just
>> classes.
>>
>>
>> "Bhuwan Bhaskar" wrote:
>>
>>> Hello,
>>>
>>> Can we declare delegates in the class? Can we declare delegates in
>>> interface
>>> ?
>>>
>>> Warm Regards,
>>>
>>> Bhuwan
>>>



--
Göran Andersson
_____
http://www.guffa.com
 
Reply With Quote
 
Bhuwan Bhaskar
Guest
Posts: n/a
 
      4th Oct 2007
Thanks ! Göran Andersson.

Regards,
Bhuwan
"Göran Andersson" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Bhuwan Bhaskar wrote:
>> Thnaks Edgar,
>>
>> Can we declare delegates inside Interface.
>>
>> Regards,
>> Bhuwan

>
> Edgar already answered that:
>
> "Since a delegate is a type that inherits from delegate you cannot declare
> a delegate within an interface".
>
>> "Edgar Harris" <(E-Mail Removed)> wrote in message
>> news:AF89D711-97E3-4D0C-ADA2-(E-Mail Removed)...
>>> Yes and no. The thing to remember about delegates is they are in
>>> themselves
>>> classes that inherit from System.Delegate. Since nested classes are
>>> allowed
>>> in classes you my declare a delegate in a class. For example the
>>> following
>>> is legal:
>>>
>>> public class MyClass
>>> {
>>> public delegate void MyDelegate();
>>> }
>>>
>>> To reference that delegate outside of MyClass you would write the
>>> following:
>>>
>>> MyClass.MyDelegate myDel;
>>>
>>> Since a delegate is a type that inherits from delegate you cannot
>>> declare a
>>> delegate within an interface, because you cannot declare nested types in
>>> an
>>> interface. That being said I tend to declare my delegates outside of a
>>> class
>>> and inside a namespace, because like I said delegates really are just
>>> classes.
>>>
>>>
>>> "Bhuwan Bhaskar" wrote:
>>>
>>>> Hello,
>>>>
>>>> Can we declare delegates in the class? Can we declare delegates in
>>>> interface
>>>> ?
>>>>
>>>> Warm Regards,
>>>>
>>>> Bhuwan
>>>>

>
>
> --
> Göran Andersson
> _____
> http://www.guffa.com



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to declare custom event in interface rodchar Microsoft C# .NET 2 30th Jul 2008 04:37 PM
How to declare a sub class JR Microsoft VB .NET 6 22nd Nov 2006 06:38 PM
declare variable in base class that must be set in dervied class? John B Microsoft C# .NET 3 18th Feb 2005 08:34 PM
Help: Declare Delegate type in an Interface ???? =?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?= Microsoft Dot NET 1 4th Nov 2004 05:47 PM
Declare an Event within an Interface Derrick Microsoft C# .NET 2 8th Jul 2004 03:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:36 PM.