You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Private constructor prevents instantiation from other classes
230
+
privateSingleton() { }
231
+
232
+
publicstaticSingletonInstance
233
+
{
234
+
get
235
+
{
236
+
return_instance;
237
+
}
238
+
}
239
+
240
+
publicvoidDoSomething()
241
+
{
242
+
Console.WriteLine("Singleton instance is working.");
243
+
}
244
+
}
214
245
```
215
246
216
247
### Q8. What is Property?
@@ -234,7 +265,10 @@ A property is a member of a class that provides a mechanism to read, write, or c
234
265
### Q9. What is the difference between Property and Function?
235
266
236
267
-**Property:** Used to access or modify the value of a field. It appears like a field but is actually a method behind the scenes.
237
-
-*Example:*`public string Name { get; set; }`
268
+
-*Example:*
269
+
```csharp
270
+
publicstringName { get; set; }
271
+
```
238
272
239
273
-**Function (Method):** Performs an operation and may return a value or perform a task. Methods can take parameters and may include logic that properties generally do not.
240
274
-*Example:*
@@ -299,16 +333,32 @@ In this example, `Dog` inherits the `Eat` method from `Animal` and has its own m
299
333
### Q12. What are the different types of Inheritance?
300
334
301
335
1.**Single Inheritance:** A class inherits from a single base class.
302
-
-*Example:*`class Derived : Base { }`
336
+
-*Example:*
337
+
```csharp
338
+
publicclassDerived : Base { }
339
+
```
303
340
304
341
2.**Multiple Inheritance:** A class inherits from multiple base classes. (Not supported in C# directly, but can be achieved using interfaces.)
0 commit comments