What is the correct notation notation for classes, functions, variables, etc. In c #?

I am a web developer, I do not have formal calculations, I have written code for several years, but every time I need to create a new class / function / variable, I spend about two minutes just deciding on a name, and then how to enter his.

For example, if I write a function to sum a bunch of numbers. Should I call him

Sum() GetSum() getSum() get_sum() AddNumbersReturnTotal() 

I know there is a right way to do this, and a link to a good final source is all I ask: D

Closed as a duplicate of C # Coding Standard / Best Practices

+4
source share
7 answers

Classes must be in the designations of camels with the first letter with a capital letter

 public class MyClass 

Functions and methods in C # should act in a similar way, with the exception of private methods

 public void MyMethod() private void myPrivateMethod() 

Variables I usually do a little differently:

Elemental variables

 private int _count; 

Local variables

 int count; 
+3
source

Are you looking for StyleCop .

+5
source

I agree to the difference between calculations and differences: get () should be used for values ​​that are already calculated or are otherwise trivial to retrieve.

In addition, I would suggest in many cases to add a noun to the name so that it accurately determines how much you are calculating. Unless, of course, the noun you would add is a class name or type.

+3
source

All of the above.

I believe the official C # guidelines say call it calculateSum (), since getSum () will be used if the sum was an instance variable. But it depends on the coding style used and how any existing code is written in the project.

+1
source

Fortunately, I do not believe that this is a standardized way. I choose the one that I like, which therefore also seems to be standard with all the other source code that I saw, uses and runs with it.

0
source

Sum() , if it is publicly available and does the work itself.

GetSum() if it is open, and it retrieves information from another place.

sum () / getSum () as above, but for internal / private methods.

(Hmm ... This is a bit vague as you slightly shift the value of β€œSum.” So, try again.

XXX if xxx is a process (total values). GetXXX if xxx is a thing. (sum of values)

0
source

Method names are verbs. Class, field, and property names are nouns. In this case, Sum can pass as a verb or noun ...

AddNumbersReturnTotal matches the definition above, but it's a little longer. Out of kindness to the guy who gets my code (usually me!), I try to avoid including unnecessary words in identifiers, and I try to avoid words that make typos easily.

0
source

All Articles