Where to declare a delegate declaration

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

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 outside the class. Or is just a matter of taste?

Alt 1
delegate double DoCalculate(double num);
class RocketCalculator
{
... ... ...
}

Alt 2
class RocketCalculator
{
public delegate double DoCalculate(double num);
... ... ...
}

//Tony
 
Tony Johansson said:
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 outside the class. Or is just a matter of taste?

Alt 1
delegate double DoCalculate(double num);
class RocketCalculator
{
... ... ...
}

Alt 2
class RocketCalculator
{
public delegate double DoCalculate(double num);
... ... ...
}

If you're using .NET 3.5, I'd just stick to the Func and Action
delegates where possible, eg Func<double,double> in this case.

Otherwise, I personally like to have a "Delegates.cs" file containing
all of the delegates for a single namespace. I don't *usually* nested
them inside other classes, as it tends to make the code using them
slightly awkward.
 

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

Back
Top