Top 29 c# interview questions and answers for freshers |PDF

 

c# interview questions and answers for freshers

If you are a C# .Net Developer looking for a job , this post will surely help you crack the technical interview  . In this post we cover the C# interview questions and their answers that must know .

Let’s get Started !!

C# Introduction : C# is a simple, modern, general-purpose, object-oriented programming ,manged and type safe language developed by Microsoft that is compiled .NET framework to generate MSIL (Microsoft Intermediate Language ).

What kind of Applications you can make with C# ?

  • WEBSITES : You can make ASP .Net or MVC websites using C#.
  • DESKTOP : C# is the best language to make desktop applications for Microsoft Windows .
  • WEB SERVICES : Interact through different components available on Internet get Universally acceptable response
  • MOBILE APPS : You can make Windows , Android as well as iOS Applications using C# in Xamarin.

Top 29 c# interview questions and answers for freshers !!

1. What is object-oriented programming (OOP) Language?

Object-oriented programming (OOP) is a programming language model organized around objects rather than “actions” and data rather than “logic”.

2. What is difference between C# and .Net Framework ?

.NET framework provides the base or the ground for the applications written in C# , Visual Basic , Visual C++ , F# and many other manged languages supported by the .Net framework to get converted into MSIL ( Microsoft Intermediate Language ) and get executed.

3. Can only Visual Studio Supports .NET framework ?

No , visual studio is the most widely used IDE(Integrated Development Environment)for .NET Framework , but some IDE’s like Mono , Sharp Develop also supports .NET Framework.

READ MORE : Top 22.5 Html interview questions and answers for freshers pdf

4. Explain the Major Principles of OOPs .(One of the Most Asked Interview Question for beginners )

  • Encapsulation :  Encapsulation is the hiding of data implementation by restricting access to accessors and mutators.
  • Abstraction :

“An abstraction denotes
the essential characteristics of an object that distinguish it from all
other kinds of object and thus provide crisply defined conceptual
boundaries, relative to the perspective of the viewer.” — G. Booch,
Object-Oriented Design With Applications, Benjamin/Cummings, Menlo
Park, California, 1991.

  • Polymorphism :  Polymorphism means one name, many forms.  Polymorphism
    manifests itself by having multiple methods all with the same name, but
    slighty different functionality.

 

  • Inheritance : Objects can relate to each other with either a “has a”, “uses a” or an “is a” relationship.  “Is a”
    is the inheritance way of object relationship.

5. What are the Advantages of .NET Framework ?

  • Modern, general-purpose programming language
  • 100 % Object oriented.
  • Component oriented.
  • Easy to learn.
  • Structured language.
  • It produces efficient programs.
  • It can be compiled on a variety of computer platforms.
  • Part of .Net Framework.
  • Standardized

6. What are Classes ?

A set or category of things having similar properties or attributes but differentiated from others by kind, type, or quality.

7. What are Objects ?

Objects are the instance of a class , that are created dynamically in C# with the help of clr .

To understand this better let us take an example , A general car has four wheels , one engine , 4-5 seats , and some other properties which can be instantiated by  Mercedes , BMW or Audi , which are objects if the class car.

8. What is CLR ?

CLR stands for Common Language Runtime , it is an integral part of .NET framework , it provides the runtime environment which runs code and provide services that make the development process easier.

Features of the CLR :

It manages the memory , thread execution , code execution , code safety, verification , compilation and other system services . These features are intrinsic to the manged code that runs on CLR .

8. How to implement Multiple Inheritance In C# ?

C# .NET Framework does NOT support Multiple Inheritance , but instead we have interfaces that can be used to get similar results of Multiple Inheritance.

9. Difference between Abstract Class and Interface ? (One of the Most Asked C# Interview Question for beginners)

FeatureInterfaceAbstract class
Multiple inheritanceA class may inherit several interfaces.A class may inherit only one abstract class.
Default implementationAn interface cannot provide any code, just the signature.An abstract class can provide complete, default code and/or just the details that have to be overridden.
Access ModfiersAn interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as publicAn abstract class can contain access modifiers for the subs, functions, properties

 

One Liner : Interfaces are fully abstract which means they have deceleration not definition.

10. How can we sort the elements of the array in descending order?

Using Sort() methods followed by Reverse() method.

11. What are generics in C#.NET?

Generics are used to make reusable code classes to decrease the code redundancy, increase type safety and performance. Using generics, we can create collection classes. To create generic collection, System.Collections.Generic namespace should be used instead of classes such as ArrayList in the System.Collections namespace. Generics promotes the usage of parameterized types.

12. What are delegates?

Delegates are same are function pointers in C++ but the only difference is that they are type safe unlike function pointers. Delegates are required because they can be used to write much more generic type safe functions.

13. What are the different ways a method can be overloaded?

Methods can be overloaded using different data types for parameter, different order of parameters, and different number of parameters.

14. What is the difference between Overloading and Overridding ?

Overloading : Also called static polymorphism or static binding , we have two or more methods that may have  data types for parameter, different order of parameters, and different number of parameters.

Overriding : In this method overriding or run time polymorphism we can override a method in base class by creating similar function in derived class this can be achieved by using inheritance principle and using “virtual &override” keywords.

15. What is the importance of “using” in C# .NET  ?

The using block is used to obtain a resource and use it and then automatically dispose of when the execution of block completed.

16. Is circular inheritance possible in C# ?

NO , it is not possible in C#

17.  What are collections ?

To cover the demerits of arrays (fixed size must be declared ) , we have collections which are similarly used to group similar kind of data except that their size can be changed we can add or remove elements form the collections .

18. Can “this” be used within a static method?

We can’t use ‘This’ in a static method because we can only use static variables/methods in a static method.

19.  What is Connection String ?

Connection String is generally a string value that contains three properties to define the database , path and the security mode of the server .

20. Difference between Window Authentication & SQL Server Authentication ?

  • Window Authentication : We are not responsible for  the introduction to the server , OS will respond to the current user introduction or connection .
  • SQL Server Authentication :We are responsible for our own introduction to the server , we need ID and Password for the connection .

21. Name two types of connection modes in ADO .NET

  • Connected mode
  • Disconnected mode

22. What are Jagged Arrays ?

A jagged array is nothing but array of arrays . It may have arrays of different sizes and data types .

23. Explain Foreach Loop Syntax

24. What is Boxing and Unboxing in C# ?

When we typecast our datatypes  from Value Data Type to Reference Data Type it is called Boxing , and the opposite Reference Data Type to Value Data Type is called Unboxing .

25. Give example of Value & Reference Data Types

  • Value Type : Int , Float , Bool , Double , Long , Short
  • Reference Type : Object , Class , String , Array

26.  Difference between Var and Dynamic ?

VarDynamic
Introduced in C# 3.0Introduced in C# 4.0
Statically typed – This means the type of variable declared is decided by the compiler at compile time.Dynamically typed – This means the type of variable declared is decided by the compiler at runtime time.
Need to initialize at the time of declaration.

e.g., var str=”I am a string”;

Looking at the value assigned to the variable str, the compiler will treat the variable str as string.

No need to initialize at the time of declaration.

e.g., dynamic str;

str=”I am a string”; //Works fine and compiles

str=2; //Works fine and compiles

Errors are caught at compile time.

 

Errors are caught at runtime

 

Intellisense is available .Intellisense is not available since the type and its related methods and properties can be known at run time only

27. How can we set class to be inherited, but prevent the method from being over-ridden?

Declare the class as public and make the method sealed to prevent it from being overridden.

28. Which are Access Modifiers available in C#?
All types and type members have an accessibility level, which controls whether they can be used from other code in your assembly or other assemblies.

You can use the following access modifiers to specify the accessibility of a type or member when you declare it:

  • Public: The type or member can be accessed by any other code in the same assembly or another assembly that references it.
  • Private: The type or member can be accessed only by code in the same class or struct.
  • Protected: The type or member can be accessed only by code in the same class or struct, or in a class that is derived from that class.
  • Internal: The type or member can be accessed by any code in the same assembly, but not from another assembly.

29. How to write comments in C# ?

 

Hope these Interview Questions help you crack the interview , Don’t forget to  Subscribe   if you liked our content !!

Download this C# Interview Questions list Pdf by clicking the PDF icon above the post .

Leave a Reply

Your email address will not be published. Required fields are marked *