tags:

views:

283

answers:

5

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?

+1  A: 

Usually, I just use:

Func<string, string>

these days

LorenVS
While I agree that this generic delegate does take a lot of the work away from having to declare your own delegates (since it can accommodate many of them), it's really not an answer to his question so I can't upvote.
Adam Robinson
I swear I'm the only person who actually downvotes irrelevant answers anymore.
jfar
@jfar: Are you aware that you bear a striking resemblance to Victor Creed (aka Sabertooth) from X Men Origins: Wolverine?
Adam Robinson
@Adam, really? I don't see it.
jfar
Arguably the question is how to make sure that delegate definitions are easy to locate, and arguably using `Func<,>` is a legitimate way to do that since it puts the definition right where you use the delegate. Maybe.
stevemegson
+1, I've never seen this Func thingy.
tpower
Bah, maybe its just me, I guess answering "How do I do 'x'?" with "Why not try 'y'"? can sometimes be valuable.
jfar
This is a relevant (alternate) solution.
Robert Venables
+2  A: 

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.

David Chappelle
+2  A: 
Anton Gogolev
+1  A: 

I personally add it before a closely related class definition. I make good use of namespaces, though, so I don't pollute!

Charlie Salts
A: 

If it's closely related enough to belong in the same file as the class, then you can probably justify nesting it in the class. Then you'll have no trouble remembering which class file it's in.

If there's no single class that's an obvious choice to nest in, creating the one-line file is probably worthwhile since you'll never waste time trying to remember which class file you decided to put it in.

stevemegson