Miria
Miria

Reputation: 479

Confused about right naming convention

Some time ago I read following rules:

However then I have seen that in using properties, the property should be Pascal and that private field camel. So I am confused, what is the correct, standard naming convention?

Upvotes: 1

Views: 982

Answers (5)

nicodemus13
nicodemus13

Reputation: 2298

But what to do with a private property..? Resharper doesn't have a sensible solution, personally I use _PascalCase.

And protected properties? Same as private properties, I guess.

Upvotes: 0

brunnerh
brunnerh

Reputation: 184516

What MSDN says

Do use Pascal casing for all public member, type, and namespace names consisting of multiple words.

Note that this rule does not apply to instance fields. For reasons that are detailed in the Member Design Guidelines, you should not use public instance fields.

Do use camel casing for parameter names.

Since this has been mentioned: A recommendation for underscores as prefix for private fields does not seem to be included in the conventions on MSDN, but the .NET classes are written in that style.

Upvotes: 1

Shekhar_Pro
Shekhar_Pro

Reputation: 18430

The most common convention I have seen is to use Pascal case for Everything except variable where you should use Camel case and sometimes prefix them with a underscore (_) if its a private field.

Upvotes: 0

Mirko
Mirko

Reputation: 4282

There is no hard and fast naming convention, all kinds of folks go back and forth on private naming, public naming is always Proper (Pascal) case. I prefer _camelCase for private fields as it makes it easier to see that it is just that, but many people choose just this.camelCase instead. With the new .NET syntax if you need only simple properties you can of course avoid that altogether now with the use auf automatic properties:

public string MyPublicProperty { get; set; }

Upvotes: 1

manojlds
manojlds

Reputation: 301147

Private fields are usually in camel case with a "_" ( underscore ) prefixed.

Also refer the following for .NET naming conventions:

http://10rem.net/articles/net-naming-conventions-and-programming-standards---best-practices

PS: One thing though, establish a convention for yourself or your team if need be, and STICK to it.

Upvotes: 0

Related Questions