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.
 
Back
Top