473,385 Members | 1,925 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,385 software developers and data experts.

Where to declare a delegate declaration

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

Dec 4 '07 #1
2 3364
Tony Johansson <jo*****************@telia.comwrote:
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,doublein 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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Dec 4 '07 #2

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP*********************@msnews.microsoft.com. ..
Tony Johansson <jo*****************@telia.comwrote:
>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,doublein this case.
Converter<TInput, TOutputand Action<Tare both available in .NET 2.0.
>
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Dec 4 '07 #3

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

Similar topics

9
by: Wiktor Zychla | last post by:
Hello, I wonder why the delegate declaration needs named parameters? public delegate void MyDelegate( int a, int b ); // ok public delegate void MyDelegate( int, int ); // compiler error...
5
by: Mark Broadbent | last post by:
I have written a class that has a public method which could take some time to complete (20 secs). The idea is for it to raise an event on completion. Should I create a separate thread for this...
4
by: Mark | last post by:
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...
5
by: Sharon | last post by:
I wand to define a delegate that will have the form a property and not a method. Let say I have a property: public int myProp { get { return 0; } set {} }
4
by: Peter Olcott | last post by:
What is the best way to handle this?
5
by: needin4mation | last post by:
Learning about delegates (again, I admit), I think I finally get it, maybe. I can reference any method in any class in the same namespace as long as it has the same signature. Right? But how...
7
by: Andreas Reiff | last post by:
Hey! I have a managed c++ app (actually, the app is mixed managed/unmanaged, but this happens in the managed part) that dynamically generates some program in c# (with CSharpCodeProvider). 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...
7
by: Dave | last post by:
I've got these declarations: public delegate void FormDisplayResultsDelegate<Type>(Type displayResultsValue); public FormDisplayResultsDelegate<stringdisplayMsgDelegate; instantiation:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.