Home
Explore
Tags
Contribute
Home
»
C#
»
C# Events
Statics events in C#
Posted in
C#
|
C# Events
on
March 30, 2020
Tags:
C#
,
Statics
,
Statics events
,
.net
,
Statics events in C#
Here you will learn about statics events in C#.
2894
Introduction
In this article we will learn about the use of Static's events and the background of the static events in C#. There will be a time when every one wanted to the perform some action in there objects to decrease the requirement of the events handlers so that's why we will use the static events.
Why we use the static events
:
In the static events we have use the static modifier and static modifier are used with the property of the program as like the properties ,classes,
operat
ors
, events etc. for example a class declared as a static and contains only static methods.
Example of the static events:
public
class
employee
{
public
string
id;
public
string
name;
public
employee ()
{
}
public
employee(
string
name,
string
id)
{
this
.name = name;
this
.id = id;
}
public
static
int
employeecounter;
public
static
int
addemployee()
{
return
++employeecounter;
}
}
class
Mainclass
:
employee
{
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();
employee
e =
new
employee
(name, id);
Console
.Write(
"enter the current number of employee: "
);
string
n =
Console
.ReadLine();
employee
.employeecounter =
Int32
.Parse(n);
employee
.addemployee();
Console
.WriteLine(
"name:{0}"
, e.name);
Console
.WriteLine(
"id: {0} "
, e.id);
Console
.WriteLine (
"new number of employee: {0}"
,
employee
.employeecounter );
Console
.ReadLine();
}
}
}
Out
p
ut:
Related Articles
Events in C#
DateTime Today and Now Property in C#
Current Date Without Time with Now property in C#
Tomorrow Date Without Time with Now property in C#
Getting Start Date of Last Month in C#
Getting End Date of Last Month in C#
Getting Start Date of current Month in C#
C# String join method
C# String Ends With
C# String Starts With
Categories
C# Array
C# ArrayList
C# Assemblies
C# Class
C# Delegates
C# Dictionary
C# Directory
C# Enumerations
C# Events
C# Exceptions
C# File
C# Generics
C# GUI
C# Interface
C# Iterations
C# Lambda
C# List
C# Namespaces
C# Operators
C# Path
C# String
C# Struct
C# Variable
More Articles
Events in C#
Statics events in C#
© 2020 DotNetHeaven. All rights reserved.
TERMS & CONDITIONS
|
CONTACT US
|
REPORT ABUSE