I’m new to C#.Till this moment I used to make every global variable – public static.All my methods are public static so I can access them from other classes.
I read on SO that the less public static methods I have,the better.So I rewrote my applications by putting all the code in one class – the form class.Now all my methods are private and there’s no static method.
My question: What should I do,keeping everything in the form class is dump in my opinion.
When should I use public,when private and when static private/public?
I get the public methods as a ‘cons’ ,because they can be decompiled,but I doubt that.My public methods can be decompiled too.What is so ‘private’ in a private method?
EDIT: I’m not asking how to prevent my program to be decompiled,I’m asking whether I should use static,private and public.And also : Is there are problem in putting all the code in the form class so I dont have to use public methods?
private is for class members that you want only access within the class of the body, and in C# members are default set to private unless specified different
examples of when to use private:
public on the other hand is the opposite, there are no restrictions with accessing public members, so when things that don’t matter with the user having access to should be public.
static on the other hand has no relation to the two, because it doesn’t deal with permission to methods, static on the other hand is a constant or type declaration. If the word static is applied to the class then every member in the class must be declared static.
examples of when to use static:
Modifiers in C# Reference will give you more detail of all modifiers in C# and examples of how they should be used