Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I put my C# delegate declaration, in a file of its own?

Tags:

Out of habit I tend to put classes/structs/enumerations in separate files when not nested.

For delegates, it seems like overkill to create a seperate file for a one liner:

public delegate string MyDelegateThatIsNotNestedInAnyClass ( string par ); 

I usually add it to the bottom of the most closely related class file. I was just wondering what other people do?

like image 674
tpower Avatar asked Aug 28 '09 14:08

tpower


2 Answers

I tend to put each type in a separate code file. Doing so will help you navigate in Solution Explorer, though ReSharper rocks with "Go To File"

alt text
(source: jetbrains.com)

and "Go To Type":

alt text
(source: jetbrains.com)

like image 78
Anton Gogolev Avatar answered Sep 16 '22 16:09

Anton Gogolev


I usually add it to the .cs file of the class which implements the delegate function (at the namespace level). If there are several of these, I put it in a separate file.

If I know for sure that only one class will implement the delegate function, I nest it in the implementing class.

like image 32
David Chappelle Avatar answered Sep 16 '22 16:09

David Chappelle