declare delegate inside routine: Possible?

M

Mark

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
 
D

Daniel O'Connell [C# MVP]

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?
 
M

Mark

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
 
D

Daniel O'Connell [C# MVP]

Mark said:
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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top