AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Tuesday, 8 December 2015

Frequently asked questions in c# interview


Here I am giving some frequently asked interview questions in c#. I hope it will helpful for your interview preparation.

Question 1: What is the base class in .net from which all the classes are derived ?
Answer: System.Object

Question 2: What are sealed classes and sealed methods?
Answer:
Sealed classes
Sealed classes are used to restrict the inheritance feature of object oriented programming (OOP). Once a class is defined as a sealed class, the class cannot be inherited. Sealed class can be a derived class but can't be a base class. The sealed class cannot also be an abstract class.

public sealed class BaseClass
  {
     public void Display()
      {          
             //Some Code
      }
  }
 public class Derived : BaseClass
 {
      // this Derived class can;t inherit BaseClass because it is sealed
  }
Sealed Methods
If you don't want to "further overriding" a method then make sealed method.

class BaseMain {
   public virtual void Test() { ... }
}
class Subclass1 : BaseMain {
   public sealed override void Test() { ... }
}
class Subclass2 : Subclass1 {
   public override void Test() { ... } // FAILS
   // If `Subclass1.Test` was not sealed, it would compiled correctly.
}

Question 3: What is the difference between ref & out parameters?
Answer: An argument passed as ref must be initialized before passing to the method whereas out parameter needs not to be initialized before passing to a method.

Question 4: What is the difference between Array and Arraylist?
Answer: In an array, we can have items of the same type only. The size of the array is fixed. An ArrayList is similar to an array but it doesn’t have a fixed size.

Question 5: What is the difference between Finalize() and Dispose() methods?
Answer:Dispose() is called when we want for an object to release any unmanaged resources with them. On the other hand Finalize() is used for the same purpose but it doesn’t assure the garbage collection of an object.

Question 6: What is Run time Polymorphism?
Answer:Run time polymorphism also called as late binding or method overriding or dynamic polymorphism. Run time polymorphism or method overriding means same method names with same signatures.

Question 7: What is Compile Time Polymorphism?
Answer:Compile time polymorphism means we will declare methods with same name but different signatures because of this we will perform different tasks with same method name. This compile time polymorphism also called as early binding or method overloading.

Question 8: What are delegates?
Answer:Delegate is a type which holds the method(s) reference in an object. It is also referred to as a type safe function pointer.

Question 9: What is the difference between a Struct and a Class?
Answer:Structs are value-type variables and classes are reference types. Structs stored on the stack, causes additional overhead but faster retrieval. Structs cannot be inherited.

Question 10: What is difference between constants and read-only?
Answer:Constant variables are declared and initialized at compile time. The value can’t be changed after wards. Read-only variables will be initialized only from the Static constructor of the class. Read only is used only when we want to assign the value at run time.

Question 11: What is View State Chunking?  
Answer:View state chunking is new in ASP.NET, version 2.0.The ViewState property retains values between multiple requests for the same page. When an ASP.NET page is processed, the current state of the page and controls is hashed into a string and saved in the page as a hidden field. If the data is too long for a single field (as specified in the MaxPageStateField-Length property), then ASP.NET performs view state chunking to split it across multiple hidden fields.

0 comments :

Post a Comment

  • Popular Posts
  • Comments