473,320 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

declare delegate inside routine: Possible?

Hi, is it possible to declare a delegate inside a routine?

E.g

private void MySub()
{
delegate int oAddMe(int n1, int n2);
}

Or can delegates only be declared with a global scope inside the
class.......

public class MyClass {

delegate int oAddMe(int n1, int n2);

private void MySub()
{
// Code....
}
}

Thanks in advance
Mark
Nov 16 '05 #1
4 1684
Only within a class or globally...declaring a delegate within a method
doesn't really make much sense since a delegate is a type. What specifically
are you trying to achieve?

"Mark" <ma*******@n0Sp8mTAIRAWHITIdotAC.NZ> wrote in message
news:I0********************@news.xtra.co.nz...
Hi, is it possible to declare a delegate inside a routine?

E.g

private void MySub()
{
delegate int oAddMe(int n1, int n2);
}

Or can delegates only be declared with a global scope inside the
class.......

public class MyClass {

delegate int oAddMe(int n1, int n2);

private void MySub()
{
// Code....
}
}

Thanks in advance
Mark

Nov 16 '05 #2
Hi Daniel, thanks for your response.

I was just wondering, since we can use delegates to "point" to a function, I
was just thinking that we should be able to define a "Pointer" inside a
routine (Much like we can in C++).

I was just curious ;)

Thanks again
Mark

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:O%***************@tk2msftngp13.phx.gbl...
Only within a class or globally...declaring a delegate within a method
doesn't really make much sense since a delegate is a type. What specifically are you trying to achieve?

"Mark" <ma*******@n0Sp8mTAIRAWHITIdotAC.NZ> wrote in message
news:I0********************@news.xtra.co.nz...
Hi, is it possible to declare a delegate inside a routine?

E.g

private void MySub()
{
delegate int oAddMe(int n1, int n2);
}

Or can delegates only be declared with a global scope inside the
class.......

public class MyClass {

delegate int oAddMe(int n1, int n2);

private void MySub()
{
// Code....
}
}

Thanks in advance
Mark


Nov 16 '05 #3

"Mark" <ma*******@n0Sp8mTAIRAWHITIdotAC.NZ> wrote in message
news:xp********************@news.xtra.co.nz...
Hi Daniel, thanks for your response.

I was just wondering, since we can use delegates to "point" to a function,
I
was just thinking that we should be able to define a "Pointer" inside a
routine (Much like we can in C++).
Ahh, I see. Well, delegates are full fledged types, so they need to be
accessible globally to be of much use(A type defined in a method would be
useless everywhere except in that method. And if you aren't leaving the
method there is considerably less need for type definition).
I was just curious ;)

Thanks again
Mark

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:O%***************@tk2msftngp13.phx.gbl...
Only within a class or globally...declaring a delegate within a method
doesn't really make much sense since a delegate is a type. What

specifically
are you trying to achieve?

"Mark" <ma*******@n0Sp8mTAIRAWHITIdotAC.NZ> wrote in message
news:I0********************@news.xtra.co.nz...
> Hi, is it possible to declare a delegate inside a routine?
>
> E.g
>
> private void MySub()
> {
> delegate int oAddMe(int n1, int n2);
> }
>
> Or can delegates only be declared with a global scope inside the
> class.......
>
> public class MyClass {
>
> delegate int oAddMe(int n1, int n2);
>
> private void MySub()
> {
> // Code....
> }
> }
>
> Thanks in advance
> Mark
>
>



Nov 16 '05 #4
Hi Daniel, cool, thanks for your help
Cheers
Mark

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:eH*************@TK2MSFTNGP12.phx.gbl...

"Mark" <ma*******@n0Sp8mTAIRAWHITIdotAC.NZ> wrote in message
news:xp********************@news.xtra.co.nz...
Hi Daniel, thanks for your response.

I was just wondering, since we can use delegates to "point" to a function, I
was just thinking that we should be able to define a "Pointer" inside a
routine (Much like we can in C++).

Ahh, I see. Well, delegates are full fledged types, so they need to be
accessible globally to be of much use(A type defined in a method would be
useless everywhere except in that method. And if you aren't leaving the
method there is considerably less need for type definition).
I was just curious ;)

Thanks again
Mark

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:O%***************@tk2msftngp13.phx.gbl...
Only within a class or globally...declaring a delegate within a method
doesn't really make much sense since a delegate is a type. What

specifically
are you trying to achieve?

"Mark" <ma*******@n0Sp8mTAIRAWHITIdotAC.NZ> wrote in message
news:I0********************@news.xtra.co.nz...
> Hi, is it possible to declare a delegate inside a routine?
>
> E.g
>
> private void MySub()
> {
> delegate int oAddMe(int n1, int n2);
> }
>
> Or can delegates only be declared with a global scope inside the
> class.......
>
> public class MyClass {
>
> delegate int oAddMe(int n1, int n2);
>
> private void MySub()
> {
> // Code....
> }
> }
>
> Thanks in advance
> Mark
>
>



Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael C | last post by:
Hi all, Is there an easy way to get the parameters of an asynchronous delegate call from the callback function? Here's an example of what I'm trying to do: private delegate ArrayList...
3
by: N8 | last post by:
I am trying to get an exception to occur and consequently found that when adding a target method to a delegates invocation list, a copy of that object is added instead of a reference to the object....
5
by: Richard MSL | last post by:
I have an application in managed C++, and a method in C# that I call. But now I want to add the ability to tell the C# method a specific method in my C++ assembly to call back to. For example, to...
1
by: Quimbly | last post by:
I'm having some problems comparing delegates. In all sample projects I create, I can't get the problem to occur, but there is definitely a problem with my production code. I can't give all the...
3
by: lothar.behrens | last post by:
Hi, I am thinking about the delegate mechanism and try to understand it. I am coming from C++ and know about callbacks or member callbacks. In C++ I have this typedef for every class that...
9
by: Flomo Togba Kwele | last post by:
I have a class which processes for a relatively long time. I want to enable other classes which call this one to receive process messages if they wish. The called routine (the one defining the...
3
by: Deckarep | last post by:
Hey all, I pass my methods to be called into my function by Delegate. Once inside my function which invokes them I'd like to get the orignal name of the delegate if possible. I just want the...
4
by: =?Utf-8?B?UmljaGFyZEBub3NwYW0ubm9zcGFt?= | last post by:
I'm trying to declare CreateFile as an extern from the dll like so: .... using System.Runtime.InteropServices; internal static extern IntPtr CreateFile( String filename, UInt32...
2
by: Tony Johansson | last post by:
Hello! Below I have two different alternativ for where to declare the delegate DoCalculate. Is it possible to say something generally where to declare the delegate. Is best within the class or...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.