There is a Statement that:
Methods are called by objects and not by reference.
But I don't understand, what is the Difference between reference and Object.
Consider the Example:
Animal a=new Animal();
(or)
Base b=new Derived();
There is a Statement that:
Methods are called by objects and not by reference.
But I don't understand, what is the Difference between reference and Object.
Consider the Example:
Animal a=new Animal();
(or)
Base b=new Derived();
I can explain like below
This is an object
public class Person
{
public string Name { get; set; }
public string Surname { get; set; }
public String SayHello()
{
return "Hello";
}
}
You cannot access directly Name, Surname and SayHello from Object like below,
Person.Name = "Onur";
Person.Surname = "Tekir";
Person.SayHello();
You should create instanca of an object. This instance is a reference of object
Person person = new Person();
Now, you can access properties and methods of reference of Person object,
person.Name = "Onur";
person.Surname = "Tekir";
person.SayHello();