Mega Code Archive

 
Categories / C# Tutorial / Class
 

A class with method and member variables

using System; class Employee {     // constructor     public Employee(string name, float billingRate)     {         this.name = name;         this.billingRate = billingRate;     }     // figure out the charge based on Employee's rate     public float CalculateCharge(float hours)     {         return(hours * billingRate);     }     // return the name of this type     public string TypeName()     {         return("Employee");     }          private string name;     protected float billingRate; } class MainClass {     public static void Main()     {         Employee Employee = new Employee("A", 21.20F);         Console.WriteLine("Name is: {0}", Employee.TypeName());     } } Name is: Employee