What is an object in C#?
In C#, an object is an instance of a class. A class is a blueprint that defines the properties and behaviors of an object. When you create an object in C#, you are instantiating a class, which means you are creating a specific instance of that class.
For example, suppose you have a class called "Person" that has properties such as "Name", "Age", and "Gender", as well as methods that define the behavior of a person object. To create a person object in C#, you would write code like this:
Person john = new Person();
This code creates a new instance of the Person class and assigns it to the variable "john". Now you can access the properties and methods of the "john" object like this:
john.Name = "John";
john.Age = 25;
john.Gender = "Male";
john.SayHello();
In this example, the properties "Name", "Age", and "Gender" are set for the "john" object, and the "SayHello" method is called on the "john" object to execute some behavior defined in the Person class.
In summary, an object in C# is a specific instance of a class that has its own set of properties and behaviors.
No comments:
Post a Comment
If you have any query kindly let me know.