Books of .Net/Interview Questions Interview Questions and Answers Programs C# Concept OOPS Concept JOBS

Sunday, September 25, 2016

C# Interview Questions and Answers



Que 1) Why we use static class?
Ans - Static class does not allow user to create instances of the class as well as it restrict the user to inherit any data members/functions to derived class. So A static class can make your implementation simpler ,safe and faster because you do not have to create an object in order to invoke its methods.



Que 2) What is dynamic keyword ?
Ans - dynamic type is inferred at run-time and not the compile time.dynamic type variables need not be initialized when declared.Que 3)What is the default access modifier for a Class in C#?
Ans - Default access modifier:- For class: internal For class members: private

Que 4) What are the new features you most likely in c# 6
Ans -
01-Auto-Property Initializers 
02. Primary Constructors. 
03-Using Explicit Constructors 
04-Dictionary Initializers 
05-Add Extensions 
06-Event Initializer 
07-Literals and Separators 
08-Declaration Expressions 
09-Using Statics 
10-Setting Up for Errors 
11-Passing Tests 
12-Conditional Access 
13-await and catch 
14-nameof 


Que 5)Why we need Anonymous method?
Ans -for passing argument to the predicate type parameter , we need to implement the event handler with the same signature as the delegate. this will take sometime and complexity .so to reduce this anonymous method came. with the use of anonymous method you just specify the method implementation without method signature and return type ,the .net itself creates the event handler with the implementation specified in anonymous method. But Later lamda expression minimizes this also...


Que 6)Can a method Return More than one Value?
Ans - Usually Method returns only one value at a time. But in some situation C# Program required to return more than one value from a single method. In Such situation, we have to use Out parameter. Declaring an out parameter in a method is useful when you want a method to return multiple values.

Que 7)When to use StringBuilders?
Ans - string builder gives high performance. it mainly used whenever you add the values in runtime(if you don't know how many values are there). it is mutable and it uses the Append or AppendLine methods for Adding new item.
when you want to add or concanate, substract etc. on string manipulation that time you can use stringbuilder. StringBuilder is faster than string.Que 8)What is the use of using statement in C#
Ans - Auto dispose the objects ,when the execution of block completed. and Importing Namespaces


Que 9)What are the Difference between Structure and Class??
Ans - 
1. Structure is Value Type. Class is Reference Type. 
2. Structure is stored on Stack. Class is stored on Heap. 
3. Structure does not support Inheritance. Class supports Inheritance.
 4. 'this' pointer does not supported by Structure. 'this' pointer is only supported by Classes. 
5. Structure do not require Constructor. Classes require Constructors.
 6. Only Interface Inheritance is possible in Structure.
 7. Default access specifier for Structure is Internal. For Class, default access specifier is Internal .

Que 10) What is the Signification of the "new " keyword in C#? 
Ans - new keyword is use to get an reference of a class, structure . when we use a new operator then a memory block of size of object type(class/reference) is allocated in memory and address of this memory block is assigned to object.It can ve used in method hiding.

You also like below blog.
1)Abstraction and Encapsulation in OOPS

2)Inheritance in OOPS

3)Polymorphism in OOPS

4)Interface in OOPS

5)What is Virtual Function

6)What is Abstract class and Abstract function

7)What is Static Class and Static Members




1) C# Interview Questions and Answers Part3

2)C# Interview Questions and Answers Part 2

3 comments :

  1. Q #09 statement 7 is incorrect default access specifier of class is internal.

    ReplyDelete
  2. Thanks for correction.
    Please like Facebook page to get updates

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete