Skip to main content
gamedev.net
🔒 Locked

c# delegates

Started by Yratelev Nov 3, 2004 at 11:28 AM 2 replies 350+ views
Original Post
Yratelev
Yratelev
Hi, I seem to be having trouble passing delegates as parameters in functions. Im trying this: public delegate int Behavior(Queue q, Vertex[] v, Clock c); class MyClass { public MyClass(object r, int n, Behavior h) { this.h = h; } static public int testbehavior(Queue q, Vertex[] v, Clock c) { //stuff goes here } public static Main() { new MyClass(null, 0, testbehavior); } } compile error: Method 'Screensaver.Screensaver.testbehavior(System.Collections.Queue, Screensaver.Vertex[], Screensaver.Clock)' referenced without parentheses any ideas? thanks Yratelev
Yratelev
Washu
Washu
A delegate is a form of an object, hence you must create it.

public delegate int Behavior(Queue q, Vertex[] v, Clock c);

class MyClass
{

public MyClass(object r, int n, Behavior h)
{
this.h = h;
}


static public int testbehavior(Queue q, Vertex[] v, Clock c)
{
//stuff goes here
}

public static Main()
{
new MyClass(null, 0, new Behavior(testbehavior));
}
}
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
Yratelev
Yratelev
Thank you!

Yratelev
Yratelev
Arild Fines
Arild Fines
Quote:
Original post by Yratelev
Hi, I seem to be having trouble passing delegates as parameters in functions. Im trying this:

[...]

This code compiles in C# 2.0.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.