C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Understanding Static "Members" and "Methods" of Class


Posted Date: 01 Aug 2006    Resource Type: Articles    Category: .NET Framework
Author: DotNetGuts (DNG)Member Level: Diamond    
Rating: Points: 7



Static Members of the class


Static members belong to the whole class rather than to individual object
Static members are accessed with the name of class rather than reference to objects.
Eg:

class Test
{
public int rollNo;
public int mathsMarks;
public static int totalMathMarks;
}

class TestDemo
{
public static void main()
{
Test stud1 = new Test();
stud1.rollNo = 1;
stud1.mathsMarks = 40;

stud2.rollNo = 2;
stud2.mathsMarks = 43;

Test.totalMathsMarks = stud1.mathsMarks + stud2.mathsMarks;
}
}



Static Method of the class


1) Methods that you can call directly without first creating an instance of a class. Eg: Main() Method, Console.WriteLine()
2) You can use static fields, methods, properties and even constructors which will be called before any instance of the class is created.
3) As static methods may be called without any reference to object, you can not use instance members inside static methods or properties, while you may call a static member from a non-static context. The reason for being able to call static members from non-static context is that static members belong to the class and are present irrespective of the existence of even a single object.

--

DotNet Guts


"Lets Make Programming Easy"



Logon to DotNetGuts.2ya.com




Join us @ DotNetGuts@YahooGroups.com








Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Importing and Exporting data to Excel sheet
Previous Resource: Improving scalability by making Asynchronous Requests
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use