Home / Programs / C# Object and Class Example, Store and Display Employee Information
Programming Example

C# Object and Class Example, Store and Display Employee Information

👁 649 Views
💻 Practical Program
📘 Step by Step Learning
Let us see an example of C# Object and Class where it store and display Employee Information.

Program Code

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();  
  
        }  
    }  

Output

1011 Rambo 880000
1022 Azmi 440000

Explanation

None

How to learn from this program

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.