Programming Example
C# Object and Class Example, Store and Display Employee Information
Let us see an example of C# Object and Class where it store and display Employee Information.
using System;
public class Employee
{
public int id;
public String name;
public float salary;
public void insert(int i, String n,float s)
{
id = i;
name = n;
salary = s;
}
public void display()
{
Console.WriteLine(id + " " + name+" "+salary);
}
}
class TestEmployee{
public static void Main(string[] args)
{
Employee e1 = new Employee();
Employee e2 = new Employee();
e1.insert(1011, "Rambo",880000f);
e2.insert(1022, "Azmi", 440000f);
e1.display();
e2.display();
}
}
1011 Rambo 880000
1022 Azmi 440000
First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.
After understanding this example, try to rewrite the same program without looking at the code. Then change some values or logic and run it again. This helps improve confidence and keeps learners engaged on the page for longer.