473,480 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using Static Methods Adv?

can any one give advantages and disadvantages to using static methods in a
class.

shall we use complete static methods in a class ?

thanks
Oct 17 '06 #1
5 3829

"chandu" <na*************@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
can any one give advantages and disadvantages to using static methods in a
class.

shall we use complete static methods in a class ?
Read here: http://msdn2.microsoft.com/en-us/library/79b3xss3.aspx

Without going into details (as it's all a bit app-specific) I have "normal"
classes for each of the objects my app works with. They are normal so I can
create any number of instances of them, and they have their own methods that
work with the data within.
I also have a static class that holds a lot of the logic for the program
that is independant of the objects and their instances... one example is a
method to write information out to a log file.
From within my instanced object methods, I can simply use:

clsMain.WriteLog(Message);

instead of

clsMain MainClassInstance = new clsMain();
MainClassInstance.WriteLog(Message);

so I save a line of code each time... there is more to it than that of
course, and the MS Site gives a good readup.

James
Oct 17 '06 #2
chandu wrote:
can any one give advantages and disadvantages to using static methods in a
class.

shall we use complete static methods in a class ?
If you want to use complete static methods in a class, you can declare
that class as static too (supported in .Net 2.0).
>
thanks

Oct 17 '06 #3
Hi chandu,
Static methods and non-static methods are really meant for different
things. Use static methods when you don't need an instance of the
class, or access to members of an instance. "Static" implies
class-level scope, not instance-level scope.

Also, it's worth remembering that you cannot make static methods
virtual or abstract (and therefore they cannot be overridden).

John

chandu wrote:
can any one give advantages and disadvantages to using static methods in a
class.

shall we use complete static methods in a class ?

thanks
Oct 17 '06 #4
My Idvice would be use static methods only of they don't need to access any
class (static) fields. Good example is the System.Math class. As soon as you
fill the need to preserve some internal state (class fields) that is a sign
that this method shouldn't be static. However this is just a guidline there
a many cases that this doesn't apply. Good example for an excption is the
singleton design pattern.
--
HTH
Stoitcho Goutsev (100)

"chandu" <na*************@hotmail.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
can any one give advantages and disadvantages to using static methods in a
class.

shall we use complete static methods in a class ?

thanks

Oct 17 '06 #5
chandu wrote:
can any one give advantages and disadvantages to using static methods in a
class.
What is the advantage and disadvantage of using a screwdriver instead
of a hammer ?

Depends a lot on what you are trying to do.

Same with static and non static methods.

If you need a static method you should use a static method.

If you need a non static method you should use a non static method.

If you are new to programming then you may often be in doubt about
what you need.

But try and think about whether the call is related to the
class or to the instance.

Arne

Oct 17 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2044
by: Michael Sparks | last post by:
Anyway... At Europython Guido discussed with everyone the outstanding issue with decorators and there was a clear majority in favour of having them, which was good. From where I was sitting it...
4
7993
by: Neil Zanella | last post by:
Hello, I would like to know whether it is possible to define static class methods and data members in Python (similar to the way it can be done in C++ or Java). These do not seem to be mentioned...
9
1957
by: Simon Harvey | last post by:
Hi all, In my project I have made a number of helper methods static. As I understand it, this will create the problem that multiple threads could access the static method at the same time and...
0
3456
by: Jim dunn | last post by:
HI I am having problems with C# with regards to its compatibility with win32 API methods, I am trying to read from a windows CE comm port using C# and imported methods from coredll.dll, it seems...
3
9721
by: Mauzi | last post by:
hi, this may sound odd and noob like, but what is the 'big' difference between static and non-static funcitons ? is there any performace differnce? what is the best way to use them ? thnx ...
3
2088
by: Jay | last post by:
Why are there static methods in C#. In C++ static was applied to data only (I believe) and it meant that the static piece of data was not a part of the object but only a part of the class (one...
12
3546
by: chandu | last post by:
hello, i want to know usage of static methods in a class. is it advantageous or disadvantage to use more static methods in a class. thank u
6
3661
by: semkaa | last post by:
Can you explain why using ref keyword for passing parameters works slower that passing parameters by values itself. I wrote 2 examples to test it: //using ref static void Main(string args) {...
6
1852
by: burningodzilla | last post by:
Hi all - I'm preparing to dive in to more complex application development using javascript, and among other things, I'm having a hard time wrapping my head around an issues regarding "inheritance"...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
6956
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5342
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4783
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4485
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2997
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
183
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.