static methods

Not so much disadvantages as just differences. A static method is like a global function. A public method is intended to do some action on a specific instance of a class.

So a Car object might have a method named Start() but you wouldnt make it static because you only start a specific car (for example).

The DateTime object has a static method IsLeapYear(int year) that returns true or false whether the year is a leap year. Its static because you dont want to have to create a DateTime object just to call that function.

Whether your objects have static or just public methods is entirely up to you - its just whatever makes sense.

-Nerseus
 
Static methods are more convenient and eisier to use but I have seen that when I try to create a thread for the method I cannot. Or at least I dont know how. I will post a new post right now about threads.
 
Nerseus...
This brings me to questions that bugged me for a while:

How does the garbage collector handle static vars/methods? Looking at memory resources, is it good or bad to use statics?
Any guidelines?

Thanks!
 
Again, its not good or bad to do anything if its needed. But you probably dont need very many static variables, in general (Ive never had the need for more than 2 or 3). Static methods only take up the memory for the compiled instructions of course, just like any other code.

I dont remember offhand how the garbage collector treats static variables - I would imagine it treats them like any other chunk of memory.

-Nerseus
 
Back
Top