-1

I'm using Visual Studio 2013 to write C# code.

How should I name my classes? In a "English-friendly" way, or in a way thats more IntelliSense- friendly.

For instance, I have a interface called IColorComparer. And a few classes that implement that interface:

QuadraticColorComparer vs ColorComparerQuadratic
DefaultColorComparer vs ColorComparerDefault
TrauerColorComparer vs ColorComparerTrauer

Question: Is there a official naming convention for Classes in C# / VS? Does it take tools like IntelliSense into account?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Trauer
  • 1,981
  • 2
  • 18
  • 40
  • The "standard" is completely up to you (if this is a personal project) or your employer (if this is a work project). However, general consensus would be to name it something useful. – PiousVenom Oct 16 '14 at 17:38
  • Now it's not opinion-based, but it's still poorly researched. Google "naming conventions C#" and you will find more than enough information. – eddie_cat Oct 16 '14 at 17:42
  • Resharper will make your intelli-sense pull up all of those as suggestions when you type in "ColorComparer" regardless of whether the differentiator is at the beginning or the end. – juharr Oct 16 '14 at 17:43

3 Answers3

2

Here are some links provided by Microsoft regarding the naming conventions in C#

General Naming Conventions

https://msdn.microsoft.com/en-ca/library/ms229045(v=vs.110).aspx

Capitalization Conventions

https://msdn.microsoft.com/en-ca/library/ms229043(v=vs.110).aspx

Overall Guidelines for naming

https://msdn.microsoft.com/en-ca/library/ms229002(v=vs.110).aspx

Here is another link provided by "dofactory" for C# coding standards

http://www.dofactory.com/reference/csharp-coding-standards

nityan
  • 316
  • 3
  • 11
1

It usually makes sense to put the differentiator at the start. For example:

  • TextReader / StreamReader / StringReader
  • Stream / FileStream / MemoryStream / NetworkStream

It's like having an adjective to provide more detail: "the red book, the blue book".

One alternative option is to avoid exposing the classes themselves, and instead have:

public static class ColorComparers
{
    public static IColorComparer Quadratic { get { ... } }
    public static IColorComparer Default { get { ... } }
    public static IColorComparer Trauer { get { ... } }
}

Then you'd just use it as:

IColorComparer comparer = ColorComparers.Quadratic;

Does anything else really need the implementation details? The implementations could even be private nested classes within ColorComparers.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

There is no rule for such naming convention. But of course there are coding standards in c#. Please refer below link which indicates naming conventions standards by Microsoft: Microsoft naming conventions

For your questions answer I would suggest you to use friendly names and more convenient names for classes. For example use

public class ColorComparer

Or

public class CompareColor

Use names that is more friendly to read and understand which will reduce your ans other developers time as well and also help in reducing maintenance cost.

You can ask me your doubts further.

Happy coding

Priyank Sheth
  • 2,352
  • 19
  • 32