Click here to Skip to main content
15,895,848 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
can any one tell me what is reason behind the make object of a class in c#. while we can do the same work to make method as static why we use one more line to add(creating object). By creating method static we can also use the method as making as object
Posted

Creating and using objects is a fundamental concept of OOP. See, for instance What Is an Object?[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Sep-15 14:50pm    
This is the only reasonable answer on this page, a 5.
It's very bad to catch a bait created by some unreasonable question and put yourself in the position where you feel like finding excuses for some good established technology of a feature.
—SA
Using non-static methods allows the methods to operate on multiple objects of a class all having different properties. See https://msdn.microsoft.com/en-us/library/aa288436(VS.71).aspx[^].
 
Share this answer
 
If the method *can* be static then making it static will help with code reasability and performance. The only thing you might have a problem with is unit testing. If you need the method to be stubbed, or mocked in some way then you'll struggle to mock a static method. If unit testing isn't an issue for you, or it is but you don't need to mock your methods then making them static is best.
 
Share this answer
 
If you don't want to maintain state of your class than you are good with static class. otherwise you should create non-static class.

Math class behavior does not depend on values we are passing into it's method or time we are calling that method.

But suppose you have class which will behave differently if we pass object with four properties and if we pass object with five properties. four properties object will be calling a different method and other object is calling different method.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900