Buy our 600+ interview questions videos package

RSS
May 9

.NET interview questions: - What is shadowing? What is the difference between Shadowing and Overriding?

Shadowing: -

Shadowing replaces the complete element of the parent class. For instance you can see in the below sample code where the clsParent has a variable int “i”, which is replaced by the child class clsChild by a method “i”.

In other words when you refer the parent object “i” it is a variable and when you refer the child object“i” it is a method.

  class clsParent
  {
   public int i=0;
  }
  class clsChild : clsParent
  {
  public  new  void i()
  {
   Console.WriteLine("Hey i became a method");

  }
  }


Difference between Shadowing and Overriding: -

Overriding redefines only the implementation while shadowing redefines the whole element.

Also see our .NET interview questions video on use of C# (Csharp) Shadowing: -

May 7

.NET interview questions: - How can we handle exceptions in .NET? What if we do not catch the exception?

Exceptions are handled by “System.Exception”  base class.  If you want to raise an error from source you need to create the exception object with below code snippet.

  throw new Exception("Customer code cannot be more than 10");

Once the exception is raised if you want to catch the same you need to use the try catch block as shown below.

  try
  {
  // This section will have the code which 
  // which can throw exceptions.    
  }
  catch(Exception e)
  {
  // Handle what you want to
  // do with the exception
  label.text = e.Message;
  }

What if we do not catch the exception?

If you do not catch the error, .NET framework will handle the same and you will get a message box as shown in the below figure.

       image

Also see our .NET interview questions video on exception handling: -

May 2

.NET Design Pattern interview questions: - What are Design Patterns? What is MVC, MVP and MVVM pattern?

Design Patterns are recurring solution to recurring problems in software architecture.

What is MVC, MVP and MVVM pattern?

All the above Design Patterns come in presentation pattern category and help to remove any kind of cluttered code in UI like manipulation of user interfaces and maintaining state. Thus keeping your UI code clean and better to maintain.

MVC pattern divides the architecture in to 3 part model, view and controller. The first request comes to the controller and the controller then decides which view to be displayed and ties up the model with the view accordingly.

MVP (Model view presenter) has the same goals as MVC i.e. separating the UI from the model. It does the same by using a presenter class. The UI talks via an interface to the presenter class and the presenter class talks with the model.

MVVM is an architectural pattern with the focus of removing UI cluttered code. It does the same by using an extra class called as view model. MVVM is mostly suitable for SilverLight and WPF projects because of the rich bindings provided by the technologies.

Also see another .NET Design Pattern interview questions video on Mediator Pattern: -

.NET interview questions: - In a parent-child relationship which constructor will fire first if you create the child class object? And in what instances you will declare a constructor to be private?

Answers: Parent class constructor will fire first.

  public class class1
  {
  public  class1(){}
  }

  public class class2 : class1
  {
  public  class2(){}
  }

Instances in which declaring a constructor to be private: -

When we create a private constructor, we cannot create object of the class.  Private constructors are used when we want only a single instance of the class to be created and externally no one can use the ‘new’ keyword to create the object.

Also see another .NET interview questions video on which constructor fires first: -

.NET interview questions: - What are Events? What is the difference between delegate and events?

Following are various .NET interview questions asked by the interviewer.

Events are higher level of encapsulation over delegates. Events use delegates internally. Delegates are naked and when passed to any other code, the client code can invoke the delegate. Event provides a publisher / subscriber mechanism model.

So subscribers subscribe to the event and publisher then push messages to all the subscribers. Below is a simple code snippet for the same:-

Create a delegate and declare the event for the same.

  public delegate void CallEveryone();
  public event CallEveryone MyEvent;

Raise the event.

  MyEvent();

Attached client methods to the event are fired / notified.

  obj.MyEvent += Function1;

Difference between delegate and events: -

They cannot be compared because one derives from the other.

  • Actually, events use delegates in bottom. But they add an extra layer of security on the delegates, thus forming the publisher and subscriber model.
  • As delegates are function to pointers, they can move across any clients. So any of the clients can add or remove events, which can be confusing. But events give the extra protection / encapsulation by adding the layer and making it a publisher and subscriber model.

Just imagine one of your clients doing this

  c.XyzCallback = null

This will reset all your delegates to nothing and you have to keep searching where the error is.

Apr 9

.NET interview questions: - What is Assembly and Namespace? What are the different types of Assembly? State differences between them?

 Following is .NET interview questions on Assembly and Namespace in .NET.

Assembly: -

Assembly is unit of deployment like EXE or a DLL.

Namespace: -

  • It  logically groupsclasses, for instance System.Web.UI logically groups UI related features like textboxes, list control etc.
  • In Object Oriented world, many times it is possible that programmers will use the same class name. Qualifying NameSpace with class names avoids this collision.

Different types of Assembly: -

There are two types of assembly Private and Public assembly. A private assembly is normally used by a single application, and is stored in the application’s directory, or a sub-directory beneath. A shared assembly is stored in the global assembly cache, which is a repository of assemblies maintained by the .NET runtime.

Shared assemblies are needed when we want the same assembly to be shared by various applications in the same computer.

Difference between NameSpace and Assembly: -

Following are the differences between namespace and assembly:

  • Assembly is physical grouping of logical units, Namespace, logically groupsclasses.
  • Namespace can span multiple assemblies while assembly is a physical unit like EXE, DLL etc.
Apr 4

.NET interview questions: - What are similarities and difference between Class and structure? When to use Class or structure?

One of the common .NET interview questions asked during .NET interview: -

Similarities between Class and structure’s: -

Following are the similarities between classes and structures:-

  • Both can have constructors, methods, properties, fields, constants, enumerations, events, and event handlers.
  • Structures and classes can implement interface.
  • Both of them can have constructors with and without parameter.
  • Both can have delegates and events.

Difference between Class and structure’s: -

Following are the key differences between them:-

  • Structures are value types and classes are reference types. So structures use stack and classes use heap.
  • Structures members cannot be declared as protected, but class members can be. You cannot do inheritance in structures.
  • Structures do not require constructors while classes require.
  • Objects created from classes are terminated using Garbage collector. Structures are not destroyed using GC.

When to use Structures or Classes: -

You will use structures when:-

Point 1:- If you want to represent a custom value type. This custom value type is derived from primitive data types (int, double). Some of the example’s of custom types are co-ordinates (which have X, Y), complex numbers (which have real and imaginary components).  You can also term these things as value objects or technical objects. Technical objects do not represent real world objects like customer, supplier, invoice etc.

Point 2:- If you want to have low memory foot print. For instance let’s say you want to plot a graph. To plot a graph you need to have 100’s of objects created so that you can represent co-ordinates.  Now if you create a class and generate those 100’s of objects you end up putting lot of load on your garbage collector. If you create a “struct”, it’s a value type. So they get created and destroyed immediately. Thus putting less load on memory.
For all other scenarios use a class.

ASP.NET interview questions: - Can you explain master pages concept in ASP.NET and how do you create master pages?

Master pages are templates which can be applied to your web pages to bring in consistent look and feel and uniform structure. By creating templates we also avoid lot of duplication of code across web pages.

For example let’s say you want all your web pages in your application to have left menu, banner and footer (Refer figure Master page concept). So you can create a template and then apply that template to your webpages.

image

Creating Master Pages: -

To create a master page you can use the “master page” template from visual studio as shown in the below figure. In order to apply the master template we can use “Web form using master page” template.

image

image

In the master page you can define place holder using “ContentPlaceHolder” control. This is the place where your ASP.NET pages will be plug in their data.

image

Once master page template is created with necessary place holders you can then later in the web pages use the “MasterPageFile” to refer the template and you can use the content place holder to plug data.

For instance you can see the below code snippet of a page which uses master pages. You can also see how the “ContentPlaceHolder1” is used to place a simple text data “Company was established in 1990”.

image

Also see the following ASP.NET interview questions video on ASP.NET Masterpages: -

.NET interview questions : - What is a delegate and how can we create a delegate? What is a multicast delegate?

Delegate is an abstract pointer to a function or method.  In other words you can create a pointer which points to a method or function and then pass that pointer wherever you wish and invoke the function / method.

Creation of a delegate

Creating a delegate is four step process:-

  • Declare a delegate.
  • Create an object reference.
  • Point the reference to the method.
  • Invoke the method via the delegate.

Below is the code snippet for the same.

   // Declare a delegate
   public delegate int PointToAdd(int i, int y);

   // Create a reference pointer
   PointToAdd objpointer = null;

   // Point to the method
   objpointer = Add;

   // Invoke the function/method
   objpointer.Invoke(10,20);


What is a multicast delegate?

Normally when you create a delegate, your delegate points to only one function or method. In case you want to point multiple functions and invoke them sequentially, you need to use the multicast delegate.

To point to multiple function using delegate pointer we need to use “+=” sign as shown in the below code snippet.

    ptrcall += Method1;
    ptrcall += Method2;


See the following .NET interview questions video on Delegate and Events: -

)

Windows Workflow Foundation(WWF) interview questions: - What is WWF? Explain Workflow? What are different types of Workflow in Windows Workflow Foundation?

Windows Workflow Foundation(WWF) is a programming model for building workflow-enabled applications on windows. System. Workflow namespace has all the necessary modules to develop any type of workflow.

Workflow: -

A Workflow is a set of activities, which is stored as model and they depict a process.  Below figure depicts clearly the difference between Workflow and Activity. Every task is an activity and group of activity depicts a complete workflow. Workflow is run by the Workflow runtime engine.

                           image

Workflow model can be written in pure .NET code, pure XAML or Mix of XAML and .NET Code. A workflow model is compiled and can execute under windows, ASP.NET, Web services or windows services application.

Different types of Workflow in Windows Workflow foundation: -

There are two basics type of workflow Sequential Workflow and State machines workflow.

A sequential workflow has clear start and finish boundaries. Workflow controls execution in Sequential workflow. In sequential execution, one task is executed after other. Sequential workflow is more rigid in format and execution path has a determistic nature.

A State machine workflow is more dynamic in nature. Workflow has states and the state waits for events to help it move to next state. In State machine execution path is undetermestic nature.

Below figure shows visual conceptualization of fundamentals. You can see in Sequential workflow the execution path is very determent. Shiv performs the entire task sequentially and these tasks are very determent. Now have a look at the second workflow. Every state goes to other state when it receives some external events. For instance when Shiv is seeing star trek there is an event of flashing news which triggers him to see the flashing new.

                  image

See the following video on working of sample of Windows Workflow Foundation(WWF): -

)

Mar 6

.NET interview questions: - What is Code Access Security (CAS) and how does it work? Is CAS supported in .NET 4.0?

CAS(Code Access Security) is the part of .NET security model which determines whether or not a particular code is allowed to run and what kind of resources can the code access.

CAS working: -

It includes four step process:-

  • First Evidence is gathered about the assembly. In other words from where did this assembly come? , who is the publisher etc.
  • Depending on evidences the assembly is assigned to a code group. In other words what rights does the assembly depending on the evidence gathered.
  • Depending on code group security rights are allocated.
  • Using the security rights the assembly is run with in those rights

image

                                                                 Figure: - CAS in action

Now let’s find out whether CAS is supported in .NET 4.0 or not

CAS is deprecated in .NET 4.0 and two major changes are brought in:-

  • Permission granting is no more the work of CAS; it’s now the work of the hosting model. In other words CAS is disabled in .NET 4.0 by default. The host will decide what rights to be given to the .NET assembly.
  • A new security model i.e. Security transparent model is introduced. The security transparent model puts code in to separate compartments/ boxes as per the risk associated. If you know a code can do something wrong you can compartmentalize the code as ‘Security transparent’ and if you have a code which you trust you can box them in to ‘Security critical’.

Also see following .NET interview questions video on IL code, CLR, CTS, CAS: -

.NET Design Pattern interview questions: - What is Bridge Pattern?

It is structural Design Pattern which let us separate abstraction from implementation.

What is Abstraction and what is Implementation?

Abstraction means hide all unnecessary things. In object oriented programming we create functions and classes and hide all the complex things from the end developer.
Implementation means actual definition of our abstraction.

Whether it is programming or real life, in general scenario our abstraction is tightly coupled with our implementation. Example – We call function (Abstraction) written inside remote control class which will call function (implementation) written inside TV in turn. In this example we create object of TV class inside RemoteControl class. Bridge pattern is all about decoupling two of them.

How we can decouple them?

There is a very common principle in object oriented design “Program to an interface not to concrete class.”  When we write our program which obeys to this principle our program become loosely coupled.

What does mean by interface here?

It means we should always have a parent of a class (which is going to get used somewhere else. In the Remote Control and TV example TV should have parent like ITV or AbstractTV). That parent is referred as interface in the principle definition.

Why we should decouple them? 

So that both can vary independently. Changing one should not affect other. Example – Just like we take any RemoteControl and attach it to any TV and vice versa.

Step by Step Demo on Bridge Pattern

  1. Create RemoteControl and TV class as follows

    image
  2. Write the code in such a way that “Program to an interface not to concrete class” principle won’t get violated.
  •       Decouple Implementation from the abstraction    

                 image

                image

Now client can pass any TV of his choice.

  • Decouple Abstraction code from client code. For that we will do same thing. 

            image

            image

Finally we separated Abstraction from Implementation and now both can vary independently. This is BRIDGE PATTERNS.

Hope you have enjoyed here. If interested to join any technical class including MVC, WCF, Design patterns, WPF, BI, UML, TFS visit www.sukesh-Marla.com or contact SukeshMarla@Gmail.com

Also see following video on .NET Design Pattern interview questions on Mediator Pattern: -

.NET interview questions: - How can we handle exceptions in .NET?

Following is the .NET interview questions on handing exception.

Exceptions are handled by “System.Exception” base class.  If you want to raise an error from source you need to create the exception object with below code snippet.

    throw new Exception("Customer code cannot be more than 10");


Once the exception is raised if you want to catch the same you need to use the try catch block as shown below.

     try
     {
     // This section will have the code which 
     // which can throw exceptions.    
     }
     catch(Exception e)
     {
     // Handle what you want to
     // do with the exception
label.text = e.Message; }


How can I know from which source the exception occurred?

“System.Exception.StackTrace”allows you to identify series of call which lead to this exception.

What if we do not catch the exception?

If you do not catch the error, .NET framework will handle the same and you will get a message box as shown in the below figure.

        image

Also click and see the following .NET interview questions video on difference between Throw and Throw ex: -: -

.NET interview questions: - What is the difference between .NET 1.X, 2.0, 3.0, 3.5 and 4.0?

One of the basic and most favorite .NET interview questions of the interviewer.

Below is the list of top differences between the framework versions. Please remember the list is much bigger than what I have put down. But for interview perspective I have taken top 5 in each one of them so that we can remember the important ones.

Also click and see the following .NET interview questions with answers video on what is downcasting and upcasting.

.NET interview questions: - Explain Nuget?

One of the frequent .NET interview questions asked during interview is on Nuget.

The amount of frameworks and libraries from both Microsoft (MVC, EF etc) and Non-Microsoft open sources (NUNIT, Log4Net etc) are huge in numbers. These frameworks and libraries keep updating to newer versions and it’s very difficult to keep a track of the same.

As a visual studio developer if you need to reference these frameworks or libraries, you need to do the following:-

  • Search the library URL.
  • Install the library or probably unzip it at some place.
  • Reference the DLL in your visual studio project.
  • If library demands alsomake appropriate changes to the App.config or Web.Config file.

image

In case you want to revert back you need to follow the above process in a vice-versa fashion.

This is where “Nuget” makes our life easy. “Nuget” is a visual studio extension which helps us to search, locate the library, download them, reference them in our VS project and also make appropriate changes to App and Web config files.

                  image

So once you click on “Manage Nuget Package” , you can go and search the framework and click on install. Below is a simple image where I have searched the new version of Entity framework and now we need to just click on the install button to add the same to your visual studio project.

image

In case you are new to Nuget and do not know how to use it please see this video for basics