Search blogs  
Browse by category
RAMESH NAIDU - dotnet developer
Ramesh Babu Akula
Author:Ramesh Babu Akula
Software engineer
C# Modifiers
Friday 29th, August 2008
Modifiers    C#:
1)Static :

1)Use the static modifier to declare a static member, which belongs to the type itself rather than to a specific object.
2)While an instance of a class contains a separate copy of all instance fields of the class, there is only one copy of each static field.

3)It is not possible to use this to reference static methods or property accessors.

4)If the static keyword is applied to a class, all the members of the class must be static.

5)Classes and static classes may have static constructors. Static constructors are called at some point between when the program starts and the class is instantiated.




example:

   
public class Employee4
{
public string id;
public string name;

public Employee4()
{
}

public Employee4(string name, string id)
{
this.name = name;
this.id = id;
}

public static int employeeCounter;

public static int AddEmployee()
{
return ++employeeCounter;
}
}

class MainClass : Employee4
{
static void Main()
{
Console.Write("Enter the employee's name: ");
string name = Console.ReadLine();
Console.Write("Enter the employee's ID: ");
string id = Console.ReadLine();

// Create and configure the employee object:
Employee4 e = new Employee4(name, id);
Console.Write("Enter the current number of employees: ");
string n = Console.ReadLine();
Employee4.employeeCounter = Int32.Parse(n);
Employee4.AddEmployee();

// Display the new information:
Console.WriteLine("Name: {0}", e.name);
Console.WriteLine("ID: {0}", e.id);
Console.WriteLine("New Number of Employees: {0}",
Employee4.employeeCounter);
}
}
/*
Input:
Matthias Berndt
AF643G
15
*
Sample Output:
Enter the employee's name: Matthias Berndt
Enter the employee's ID: AF643G
Enter the current number of employees: 15
Name: Matthias Berndt
ID: AF643G
New Number of Employees: 16
*/




 
Post your valuable comment here
Email:      Password:  
Don't have SiliconIndia ID? Sign up      Forgot your Password?  Retrieve

 Latest postings

DOTNET5
What is the need of abstraction? What is abstraction? What is the abstraction for stack?Abstraction is nothing but binding the code and data Toge... more >>
SQLSERVER FAQS
SQLSERVER 2005 Interview Questions If I want to see what fields a table is made of, and what the sizes of thefields... more >>
SAMPLE .NET APPLICATION IN 3 TIER
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System... more >>
Asp.net Authentication and Authorization
Authentication and AuthorizationAuthentication and Authorization are two interrelated security concepts. In short, authentication is a process of iden... more >>
asp.net
ASP.NET State Management Web form pages are HTTP-Based, they are stateless, which means they don’t know whether the requests are all from the same... more >>
More postings 1  2  3    next >>

Academics

Managerial skills
Managerial skills* *Dr. Binod Kumar Singh, Faculty Member, A... more >>
By
Dr Binod Kumar Singh
One brush should not paint all the painting
How to Draft an Arbitration Agreement? One brush should not pai... more >>
By
rohit dangare
Install Love, It Is Really Quite Simple
Install Love, It Is Really Quite SimpleTech Support: Yes, how can... more >>
By
Shaheena J. Motewala
Environmental depredations of palm oil industry: The way out
It is a known fact that palm oil plantations in Malaysia and Indo... more >>
By
mohan Alembath
Different Types of Air Compressors.
Air Compressor is one of the major energy consuming utility in an... more >>
By
prasanna sutrave

Guest contributors

Vineet Nayar
Vineet Nayar
CEO, HCL Technologies
Rajendra K Misra
Rajendra K Misra
Author is the founder of Change India
Narayana Murthy
Narayana Murthy
Chairman & Chief Mentor, Infosys Technologies.
Sridhar Jayanthi
Sridhar Jayanthi
Vice President of Engineering and Head of India Operations, McAfee
Vikram Shah
Vikram Shah
President - India Operations, NetApp.
 Our sponsors