Rajesh Thampi

Rajesh Thampi

  • NA
  • 12
  • 520

Generic List | Console printing

Nov 1 2017 3:48 AM

Hi guys

I have a class like following

  1. class Employees  
  2.    {  
  3.        string empName;  
  4.        string deptName;  
  5.        double salary;  
  6.        double bonus;  
  7.   
  8.        public Employees(string eName, string dName, double eSalary, double eBonus)  
  9.        {  
  10.            this.empName = eName;  
  11.            this.deptName = dName;  
  12.            this.salary = eSalary;  
  13.            this.bonus = eBonus;  
  14.   
  15.        }  
  16.    }  

and in my main method I am trying to create a List using the class like following:

  1. class TestGenericList  
  2.     {  
  3.         static void Main()  
  4.         {  
  5.             List myList = new List();  
  6.   
  7.             Employees rajesh = new Employees("Rajesh Thampi""IT", 1125.000, 300.000);  
  8.             myList.Add(rajesh);  
  9.   
  10.             foreach (Employees obj in myList)  
  11.             {  
  12.                 Console.WriteLine(obj);  
  13.             }  
  14.   
  15.               
  16.         }  
  17.     }  
How do you I print each element from the list object at the console?
 
I want to print the output like this

Console.WriteLine("Employee Name: {0}, Department: {1}, Salary: {2}, Bonus: {3}", ?, ?, ?, ?);
 
I am totally outta clue here. Please help :)

Answers (3)