Ejemplo n.º 1
0
        static void Main1(string[] args)
        {
            List <Employees1> li = new List <Employees1>();
            Employees1        e  = new Employees1();

            // e.EmpId = 100000;
            try
            {
                char choice = 'y';
                while (choice == 'y')
                {
                    Employees1.insertEmployee(li);
                    Console.Write("Do you Want to continue type (y/n) : ");
                    choice = Convert.ToChar(Console.ReadLine());
                }
            }
            catch (InvalidEmpIdException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (InvalidEmpNameException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (InvalidEmpSalException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (FormatException ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Please Enter Valid Input");
            }
            catch (NullReferenceException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }



            Employees1[] arr = li.ToArray();

            foreach (Employees1 el in arr)
            {
                Console.WriteLine(el.EmpId + "  " + el.EmpName + "  " + el.EmpSal);
            }


            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public static void insertEmployee(List <Employees1> li)
        {
            Employees1 emp = new Employees1();

            Console.WriteLine("-------------------------------------------------");
            Console.Write("Enter Employee Id : ");
            int empId = Convert.ToInt32(Console.ReadLine());

            emp.EmpId = empId;
            Console.Write("Enter Employee Name : ");
            string empName = Console.ReadLine();

            emp.EmpName = empName;
            Console.Write("Enter Employee Sal : ");
            decimal empSal = Convert.ToDecimal(Console.ReadLine());

            emp.EmpSal = empSal;
            li.Add(new Employees1(empId, empName, empSal));
            //li.Add(new Employees { EmpId = empId, EmpName = empName, EmpSal = empSal });
        }