Console Application With 2 Class
Create Console 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 conApp
{
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)
{
clsCalM CalAvage = new clsCalM();
//This Cording Working like this
//1st set 2 parameters
//2nd Returned value
//Finally Returns value assign by variable
decimal a=CalAvage.cal_Aage(intNUM, intNUM2);
Console.WriteLine(a.ToString());
Console.ReadLine();
}
}
}
}
Create clsCalM Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace conApp
{
class clsCalM
{
public int cal_Aage (int intAge,int intAge2)
{
return (intAge + intAge2) / 2;
}
}
}
Create Console 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 conApp
{
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)
{
clsCalM CalAvage = new clsCalM();
//This Cording Working like this
//1st set 2 parameters
//2nd Returned value
//Finally Returns value assign by variable
decimal a=CalAvage.cal_Aage(intNUM, intNUM2);
Console.WriteLine(a.ToString());
Console.ReadLine();
}
}
}
}
Create clsCalM Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace conApp
{
class clsCalM
{
public int cal_Aage (int intAge,int intAge2)
{
return (intAge + intAge2) / 2;
}
}
}
No comments:
Post a Comment