We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Monday, June 22, 2015

1   Write a program to create an ‘Employee’ class with id, name non-static members and employeeCounter as Static data member. Accept id, name values from user (using Console.ReadLine() method) and assign them to Employee data members. Count how many objects created for Employee class, display the content using Console application.

       class Program
    {
        public class Employee
        {
            int EmployeeId;
            string EmployeeName;
            public static int EmployeeCounter = 0;
            public Employee()
            {
                Console.WriteLine("Enter the Employee Id");
                EmployeeId = int.Parse(Console.ReadLine());
                Console.WriteLine("Enter the Employee Name");
                EmployeeName = Console.ReadLine();
                EmployeeCounter++;
            }
            public void Display()
            {
                Console.WriteLine("Display the Employee Id:{0}", EmployeeId);
                Console.WriteLine("Display the Employee Name:{0}", EmployeeName);
                Console.WriteLine();
            }
        }
        static void Main(string[] args)
        {
            Employee emp1 = new Employee();
            Employee emp2 = new Employee();
            Employee emp3 = new Employee();
            emp1.Display();
            emp2.Display();
            emp3.Display();

            Console.WriteLine("The Employee numbers are:" + Employee.EmployeeCounter);
            Console.ReadLine();
        }
    }

No comments: