Tuesday, 21 April 2015

Console Application With Class




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;
            //print Line   
            Console.WriteLine("----------obj1----------");
            //print Line With Data
            Console.WriteLine(emp.EmpName);
            Console.WriteLine(emp.EmpNo);
            Console.WriteLine(emp.Eage);
            Console.WriteLine("------------------------");
            Console.WriteLine("=========obj2===========");
            Console.WriteLine(empNew.EmpName);
            Console.WriteLine(empNew.EmpNo);
            Console.WriteLine(empNew.Eage);
            Console.WriteLine("========================");
            Console.ReadLine();
            //Console.WriteLine("eMP NAME" );
            //Console.ReadKey();
        }
    }

}


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


No comments:

Post a Comment