放置比较器的好地方是什么?

What's a good place to put Comparers?

EqualityComparer<T>...它应该去哪里?嵌套在 class 它正在比较?还是在它自己的文件中?或者在包含所有其他自定义 Comparers?

的文件中

是否有普遍认可的编码指南,它们在这种情况下有何建议?

虽然有些约定确实会随着时间而改变,但 MSDN 上提供的 .NET 1.1 C# coding conventions 是一个很好的起点。

关于nested classes

Do not use nested types if … [the] type must be instantiated by client code. If a type has a public constructor, it probably should not be nested. The rationale behind this guideline is that if a nested type can be instantiated, it indicates that the type has a place in the library on its own. You can create it, use it, and destroy it without using the outer type. Therefore, it should not be nested. An inner type should not be widely reused outside of the outer type without a relationship to the outer type.

关于 C# 源代码文件的组织,通常的做法是将每个 class 放在单独的 .cs 文件中,并与 class 同名。这使您在浏览存储库时很容易找到 class,并且通常有助于一目了然地理解代码的组织。 This has been discussed on SO as well

此规则并未得到严格执行,而且我看到很多人在特定情况下偏离了它。但是,除非您真的有特定需要将 class 放在一起,否则我建议为每个单独的 .cs 文件。

所以总结一下。如果你有一个主 class Foo 和一个比较器,FooComparer,你将有一个单独的 class 文件,Foo.csFooComparer.cs