What is a class instance in C#?
Experience Level:
Junior
Tags:
C#
Answer
In C#, a class instance is an object that was created based on the class.
The class is like a recipe that defines a logic how to cook a meal. The meal prepared by a recipe is then called a class instance. Or an object.
In the following program there is a class Dog
defined. Based on this class 3 dog objects are created. We are saying that we have created 3 instances of class Dog
.
using System;
namespace MyApp {
class Program {
static void Main() {
var dog1 = new Dog();
var dog2 = new Dog();
var dog3 = new Dog();
}
}
class Dog {
}
}
Related C# job interview questions
-
How can you recognize a property in C#?
C# Junior -
What is a property in C#?
C# Junior -
What is a difference between value type and reference type?
C# Junior -
What is an object reference in C#?
C# Junior -
What C# data types do you know?
C# Junior