December 29, 2012

Static Members


Static Members

  • static class , a method , members can be defined with the help of static keyword.
  • After defining a member as a static, member can be directly invoked by using class.
  • so static members are accessed without creating a instance of class.
  • They are slightly faster than instance methods
  • Static class contains only static methods and static members only.
  • So instance of the static members can not be created with new keyword.


            Eg : System.Math class is a static method.

            Another Example

namespace Persons
{

    public static class Employee
    {

        public static string ManagerName()
        {
            return "Sandeep";
        }
    }
}


In Code behind file.


protected void Page_Load(object sender, EventArgs e)
{

     string sManagerName = Persons.Employee.ManagerName();

}


No comments:

Post a Comment