A class consists of data and behavior. Class data is represented by its fields and behavior is represented by its methods.
using System;
class Customer
{
//data
string _firstName;
string _lastName;
//overloading constructor
public Customer()
: this("No First Name Provided", "No Last Name Provided")
{
}
//constructor - does not have return type and the name is the same with class
// it is called automatically when you create an instance of class, and it initializes class fields
// it is not mendatory
public Customer(string FirstName, string LastName)
{
_firstName = FirstName; //this._firstName = FirstName;
_lastName = LastName;
}
//behavior
public void PrintFullName()
{
//use this keyword for readability
Console.WriteLine("Full Name = {0}", this._firstName + " " + this._lastName);
}
//destructor - has the same name as the class with ~ symbol in front of them
//not having parameters and return a value
~Customer()
{
//Clean up code
}
}
class Program
{
static void Main(string[] args)
{
Customer C1 = new Customer("Rody", "Choi"); //creating an object
C1.PrintFullName();
Customer C2 = new Customer();
C2.PrintFullName();
}
}