Static members of a class are those which can be
accessed without creating an instance of the containing class, similarly static
properties can be assessed directly by prefixing the property name with the
class name and a dot (.). Static
properties should have the keyword static mentioned in their definition.
In the following example we will
define a static property and access
the same directly without creating an instance of the class.
public static class clsEmployee
{
public static string strName;
//
public static string Name
{
get
{
return strName;
}
set
{
strName = value;
}
}
}
The static property can be accessed
directly without creating an instance of the class clsEmployee as follows.
clsEmployee.Name = "Test Name";
clsEmployee.Name = "Test Name";
No comments:
Post a Comment