Twitter Facebook LinkedIn RSS Pinterest
  • You are here :
  • Home
  • CSharp


Technical Article Section -


is a process where you show only “relevant” data of an object from the user

Like - Mobile phone , we just need to know what button is used to make a call but how calls are connected is all abstracted away from the user.


Abstract class is used to achieve abstraction.

Encapsulation Is a process of hiding “irrelevant” data of an object from the user using these five modifiers i.e public, private, internal, protected and protected internal.

Inheritance Is the property by which object of derive classes passes copies of data member and function to the base class.

Polymorphism Refers an entity into many forms like static[overloading-early binding/compile time binding] and dynamic[override-late binding/run time binding] Class is a group of related methods and variables. And in C# default modifier is Internal and it doesn’t exist in reality. Like class , you don’t have any figure.

Class is a group of related methods and variables. And in C# default modifier is Internal and it doesn’t exist in reality. Like class , you don’t have any figure.

Object is an instance of a class and it exist in reality like “Mohan” is object of Class class.

Static Class- A class having static keywords which can be used without creating any instance of it.

  1. It only contains static data member and functions.
  2. It can’t be instantiated.
  3. It can’t contain constructor, only contains static constructor.

Constructor is a special type of function having same name as class name with no return type. And used to initialize the value.

Static Constructor This is used to initialize static data member only. And it can not be parameterized as programmer does not have the control.

Private Constructor It is commonly used in class that use static data member only and prevent to create object of it.

  1. Declaration of empty constructor prevent the automatic generation of default Constructor.
  2. If we don’t mention modifier with constructor it will become Private default.

Static V/S Private Constructor

  1.  A class can have multiple private constructor whereas only one static constructor.
  2. Static Constructor can’t have modifier whereas private is having.
  3. Static Constructor can execute only one time whereas private can called more time.

Static V/S Sealed V/S Abstract

Some of Inheritance Example

Is the property by which object of derive classes passes copies of data member and data function to the base class.

Some of Polymorphism Example 



Abstract Class

The purpose of an abstract class is to provide a common functionality so that multiple derived classes can share the same and if you have a requirement where you want to provided common functionality to your derive classes and other methods should be open to being overridden,we can go with abstract classes. 


The purpose of an interface is like each of the child classes is free to provide its own implementation. 

Abstract Class V/S Interface

  1. Abstract class can contains method [concrete method] implementation along with abstract method where as interface can only contains methods declaration.
  2. By using interface we can go with multiple inheritance whereas with abstract class we can not go with multiple inheritance.
  3. An abstract class can have constructor declaration while an interface can not.
  4. An abstract Class is allowed to have all access modifiers for all of its member declaration while in interface  we can not declare any access modifier(including public) as all the members of interface are implicitly public
  5. An abstract class can declare or use any variables while an interface is not allowed to do so.


So if an interface implements no functionality then why should we USE them? 

Using Interface based design concept provides loose coupling, component-based programming. 

Loose Coupling means reducing dependencies of a class that use a different class directly. In tight coupling, classes and objects are dependent on one another. In general, tight coupling is usually bad because it reduces flexibility and re-usability of code and it makes changes much more difficult. 

Like let's take a vehicle. All vehicles have similar items, but are different enough like some vehicles have 2 wheels, some have 4 wheels and can even have 1 wheel, 

Though these are differences they have something in common, they're all movable, they all have some short of engine, they all have doors, but each of these items may vary. so we can create an interface of a vehicle that has these properties, then we inherit from that interface to implement it. 

Follwoing are the some code sample related to above 


Ref V/S Out


Extension Method 


Interview Questions and Answers +

Can we Overload main() method in C#?

Yes, We can overload main() method. A C# class can have any number of main() methods. But to run the C# class, class should have main() method with signature as “public static void main(String[] args)”. If you do any modification to this signature, compilation will be successful. But, You will get run time error as main method not found.

Can we declare main() method as private in C#?

Yes. You can mark the main() method as public,private or protected. If you want to initiate entry point by any external program,then you might need to make it public so it is accessible. You can mark it as Private if you know there is no external usage for the application then it is better to make it private so no external application access it.

Can We Declare main() Method As Non-Static in C#?

No, If you will declare the main method as non static keyword then you will get a runtime error.”the program does not contain a static ‘Main’ method suitable for an entry point”.

Can we change return type of main() method in C#?

Yes, we can. From the msdn ( “If the return value from Main is not used, returning void allows for slightly simpler code. However, returning an integer enables the program to communicate status information to other programs or scripts that invoke the executable file. The following example shows how the return value from Main can be accessed.”


Can main() method take an argument other than string array?

No. The parameter of the Main method is a String array that represents the command-line arguments.Command line arguments commonly get used when you need to pass information to your application at runtime. If you don’t have any parameter to pass then

Can we run C# class without main() method?

No. The Main method is the entry point of a C# console application or windows application. (Libraries and services do not require a Main method as an entry point.) When the application is started, the Main method is the first method that is invoked.

There can only be one entry point in a C# program. If you have more than one class that has a Main method, you must compile your program with the /main compiler option to specify which Main method to use as the entry point.