Monday, August 24, 2020

What is IDisposable in C#?

IDisposable is an interface that contains a single method, Dispose of (), for releasing unmanaged resources, like files, streams, database connections, and so on.

Can we have 2 main methods in C#?

In a C# application, we can have multiple Main methods but only one of them with valid Main signature can be treated as Startup or Entry Point of the application.

Why main method is static in C#?

The Main method states what the class does when executed and instantiates other objects and variables. The main method is static since it is available to run when the C# program starts. It is the entry point of the program and runs without even creating an instance of the class.

What is the static keyword in C#?

In C# terms, “static” means “relating to the type itself, rather than an instance of the type”. You access a static member using the type name instead of a reference or a value, e.g. Guid. NewGuid(). In addition to methods and variables, you can also declare a class to be static (since C# 2.0).

Can we declare constructor as private?

Yes, we can declare a constructor as private. 

If we declare a constructor as private we are not able to create an object of a class. We can use this private constructor in the Singleton Design Pattern.

Can abstract class have constructor?

Yes, Abstract Classes can have constructors!

An abstract class can have a constructor though it cannot be instantiated. But the constructor defined in an abstract class can be used for the instantiation of a concrete class of this abstract class.

Can you have a static method in a non static class?

You can define one or more static methods in a non-static class. Static methods can be called without creating an object. You cannot call static methods using an object of the non-static class.