tags:

views:

64

answers:

1

Hi, Learning static classes, I read some examples and would like to ask whether my opinion is correct: Menus - MY opinion: is it because I only need one menu and instances of menu are not making sense?
Constant information - MY opinion: I could have simply const variables, right?
Helper methods - MY opinion: it is because they do not belong to any object and are more "generic"? Thanks

A: 

Did you do any reading/research before you posted here?

Static Classes and Static Class Members (C# Programming Guide)

Static classes and class members are used to create data and functions that can be accessed without creating an instance of the class.

Use a static class as a unit of organization for methods not associated with particular objects. Also, a static class can make your implementation simpler and faster because you do not have to create an object in order to call its methods. It is useful to organize the methods inside the class in a meaningful way, such as the methods of the Math class in the System namespace.

And from Static Classes and Static Class Members (C# Programming Guide)

A static class can be used as a convenient container for sets of methods that just operate on input parameters and do not have to get or set any internal instance fields. For example, in the .NET Framework Class Library, the static System.Math class contains methods that perform mathematical operations, without any requirement to store or retrieve data that is unique to a particular instance of the Math class. That is, you apply the members of the class by specifying the class name and the method name, as shown in the following example.

astander
Yep I did. I would just like to know whether I understood well. The examples I gave were taken from soem article and I add my explanation based on my understanding.
Tommcat
Well, I think the static class with static fields can store data..
Tommcat
Yes, which is *static*
astander
@astander: I don't think you understood the intent of Tommcat's question. He was asking for a narrative when to use static classes and why should one prefer static classes over other possible solutions.
Saul