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();
//Work With Method
Employee empMethodCall = new Employee();
empMethodCall.ViewEmpDetails("Gayantha"); //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 Meathord
public void ViewEmpDetails(string strName) //Methord with Parameter
//public void ViewEmpDetails() //Methord without Parameter
{
EmpNo = "1000";
//EmpName = "SUNIL"; //Methord without Parameter
EmpName = strName; //Methord with Parameter
Console.WriteLine(EmpNo);
Console.WriteLine(EmpName);
Console.ReadLine();
}
}
}
No comments:
Post a Comment