Sign in to follow this  
Followers 0
Colin McGregor

C# Real World Help

8 posts in this topic

When i originally learned C# i learned basically with notepad and a compiler and I was taught to use camel case (thisVariablesName) for public, underscore (_thisVariablesName) for private and pascal (ThisVariablesName) for method names. Now im using a book to learn WPF and WinForms C# programming and the 2 books i have is using pascal for public variables and for methods and camel case for private.

My question is once i get employment in the real world with development is there a common way that most companies use? or is the books right and im doing it wrong originally?

Eg:

public int thisVariablesName;

private int _thisVariablesName;

public void ThisVariable()

{

}

Share this post


Link to post
Share on other sites

For private variables, I do it the same way as your public variables (camel case without the underscore), as I normally don't have any public variables anyway. Sometimes companies have their own specific paradigm which they tell will you, but if they don't, code similar to the rest of the code so yours will fit in (like if curly braces go to the next line or not and such).

For the most part though it's not a big deal (there isn't a right and wrong).

Share this post


Link to post
Share on other sites

+1 to what Dr_Asik said.

If you use a product called ReSharper you can set the rules up in there and share them between a team.

GE

Share this post


Link to post
Share on other sites

+1 for resharper.

A developer friend recommended it to me. I couldn't live without it now. It's awesome for LINQ stuff <3+

As observed by others, what rules you use are less important than using a set consistently. Just learn what your company expects and do it >.<

Share this post


Link to post
Share on other sites

The most important rule IMHO: Do not use Hungarian notation, ever.

Share this post


Link to post
Share on other sites

The most important rule IMHO: Do not use Hungarian notation, ever.

Not to start an argument, but I think it's worth mentioning that there are values to Hungarian Notation. I should also state that I have spent 20 years using VB where Hungarian is used quite often. The real answer here is that each place you work will have patterns and that each pattern has it's benefits and it's issues. Learning to deal with change is part of the development cycle.

Good luck.

Share this post


Link to post
Share on other sites

I use camel case

myVariable for private

Pascal MyVariable for the public

And underscore for reserved words. ie) _object

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.