Wednesday, 22 April 2015

Console Application With Class,Object Method ,condition and Operator

Console Application With Class
Create Consol Application Called conApp

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace conApp
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a Object For Employee
            //With out object cannot accessing or Access Data
            Employee emp = new Employee();
            emp.EmpName = "Saman";
            emp.EmpNo = "E00001";
            emp.Eage = 30;
            //Same(Employee) Object Thought Create Another one
            Employee empNew = new Employee();
            empNew.EmpName = "Sarath";
            empNew.EmpNo = "R00001";
            empNew.Eage = 33;



            //Work With MEthod
            Employee empMethodCall = new Employee();
            empMethodCall.ViewEmpDetails(empNew);  //With Parameter
            empMethodCall.ViewEmpDetails(emp);  //With Parameter
            //empMethodCall.ViewEmpDetails();          //Without Parameter 
        }
    }

}


Create Employee Class
Add Class call Employee

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace conApp1
{
    public class Employee
    {
        private string empNo;

        public string EmpNo
        {
            get { return empNo; }
            set { empNo = value; }
        }
        //public string EmpNo { get; set; }
        public string EmpName { get; set; }

        private int eage;
        public int Eage
        {
            get { return eage; }
            set { eage = value; }
        }

         
        //Create A Method This Method create with Object Parameter 
public void ViewEmpDetails(Employee obj) //Method with Parameter
        {
            Console.WriteLine(obj.EmpNo);
            Console.WriteLine(obj.EmpName);


            //Work With Operators
            //this is if condition with equal Operator
            if (obj.EmpName == "Sarath")
            {
                intNUM = int.Parse(Console.ReadLine());
            }
            else if (obj.EmpName == "Saman")
            {
                intNUM2 = int.Parse(Console.ReadLine());
            }
            Console.WriteLine("========================");
            Console.ReadLine();
            //this is if condition with not equal Operator
            if (intNUM2 != 0)
            {
                Console.WriteLine("Ave: Age  :- " + ((intNUM + intNUM2)/2));
                //Calculation Part handle  
                Console.ReadLine();
            }
        }


    }
}

No comments:

Post a Comment