Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A few C# naming convention questions

1) What's the policy for declaring a variable? Should you always use the keyword private, or is it OK to skip it?

string MyVar1;

vs.

private string MyVar1;

The only reason I see is that Microsoft one day can change the default access modifiers to public instead of private.

Where does it say that private is optional? Any references to MSDN?

2) Naming policy for constants?

I have always used caps when writing a constant, but a friend told me that it's against the Microsoft naming policy, is it?

const string MYVAR1;

vs

const string myVar1;

3) Pascal or Camel?

Personally I think that Camel just looks ugly.

like image 306
Patrick Avatar asked Aug 05 '09 14:08

Patrick


People also ask

A few untuk apa?

“A few” digunakan dengan countable nouns (kata benda yang bisa dihitung), contohnya book (buku), house (rumah), person (orang), dan lain-lain.

Apa bedanya a few dan few?

A Few Vs Few “A few” menunjukkan jumlah yang sedikit, namun konotasinya positif. Sedangkan determiner “few” menunjukkan konotasi negatif alias “kurang”. Penggunaan “a few” mengimplikasikan makna “some” (beberapa), sedangkan penggunaan “few” merujuk pada makna “not a lot” (tidak banyak) atau kurang dari yang diharapkan.

Kapan menggunakan a few dan a little?

Jika few digunakan dalam kata benda yang bisa dihitung atau countable noun. Namun little digunakan untuk kata benda yang tidak bisa dihitung atau uncountable noun.


1 Answers

1) The private keyword is optional. I highly doubt that Microsoft will ever change the default visibility of fields as this would be a massive, breaking change (not to mention a stupid one). Omitting the private keyword is merely a matter of personal taste.

2) Don't use "shouty" constants - follow the convention of the framework and use pascal casing (e.g. ThisIsAConstant is preferable over THIS_IS_A_CONSTANT).

like image 173
Andrew Hare Avatar answered Nov 10 '22 06:11

Andrew Hare