Hi friends,
I want to know What is static method ,static class and static variable ?
Thank you.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
MuthuMari MPosted May 9, 2012, 2:40 AM
Static variable
To declare a member variable of a class as static, type the static keyword on its left. Here is an example:
public class Book { static string title; }In the same way, you can declare as many static variables as you want.pls refer this url for samples
http://www.functionx.com/csharp/topics/staticcvariables.htm
Static methods have no instances. They are called with the type name, not an instance identifier. They are slightly faster than instance methods because of this. Static methods can be public or private. They cannot use the this instance expression.
Static ModifierKey point: Static methods are called without an instance referencepls refer this url
http://www.dotnetperls.com/static-method
thanks.
SenthilkumarPosted May 8, 2012, 11:23 PM
The static means persists. The static methods are compile time methods and not the run time methods.
Static class:
Static Method and static variable:
The static method can be called without creating instance of the class. Normal class can have the static methods and which uses the static properties. a static class can have only static methods.
A static method, field, property, or event is callable on a class even when no instance of the class has been created. If any instances of the class are created, they cannot be used to access the static member. Only one copy of static fields and events exists, and static methods and properties can only access static fields and static events. Static members are often used to represent data or calculations that do not change in response to object state; for instance, a math library might contain static methods for calculating sine and cosine.
VulpesPosted May 8, 2012, 12:09 PM