Classes and Objects In C#
public void PlayAudio()
{
//implementation logic
}
Declaration Of Class:
<access specifier><keyword:class> <class name: Car>
public class car
if access identifier is not explicitly mentioned a class has internal access identifier as default while methods and properties have private access identifier.
Properties are also called accessors as they offer a way to get and set a field in the class.
Properties can be read-only,write-only or both by declaring get{},set{} or both.
Object :
Object is an instance of a class which is created at run time. It is a memory allocation according to the class of which it is an instance of . It is used to access properties and methods in a class.
Initializing an object
An object is initialized by using the keyword new.
Car c=new Car();
here c is an object of type car.
if we split the above initialization in two lines
Car c ; // it is a declaration which states that c is a variable of type class c;
c=new Car();// now c is an object of class Car
and we can access the properties and methods of the class
c.Color=red; //assigning value to the property of the object
string color=c.Color; //getting the value of the property from the object
c.PlayAudio(); //invoking method