Example for Methods and Properties in C#

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. namespace TestingOops  
  7. {  
  8.    class Employee  
  9.    {  
  10.       public int Empage  
  11.       {  
  12.          getset;  
  13.       }  
  14.       public string Empname  
  15.       {  
  16.          get;set;  
  17.       }  
  18.       public string Empphonenumber  
  19.       {  
  20.          get;  
  21.          set;  
  22.       }  
  23.       public double Empsalary  
  24.       {  
  25.          get;  
  26.          set;  
  27.       }  
  28.       public void Bonus(double yearsbouns)  
  29.       {  
  30.          Empsalary = Empsalary + Empsalary * yearsbouns;  
  31.       }  
  32.    }  
  33.    class Program  
  34.    {  
  35.       static void Main(string[] args)  
  36.       {  
  37.          Employee emp = new Employee  
  38.          {  
  39.             Empage=32,  
  40.             Empname="Ujjwal",  
  41.             Empphonenumber="9031-214-542",  
  42.             Empsalary=50000  
  43.          };  
  44.          Console.WriteLine("Employee Name is : \'{0}\' and Age is {1}. {0} gets salary of $ {2} and his phone number is {3}",emp.Empname,emp.Empage,emp.Empsalary,emp.Empphonenumber);  
  45. emp.Bonus(0.05);  
  46.          Console.WriteLine("{0}'s salary after bonus is $ {1}", emp.Empname, emp.Empsalary);  
  47.          Console.ReadKey();  
  48.       }  
  49.    }  
  50. }