Friday 29 January 2016

What is Marshalling?



Marshalling is medium or gateway to communicate with an unmanaged code from managed code in better way and vice versa, by using pinvoke, and ensures that data is returned back in a safe manner.
It is one of the core services offered by CLR (Common Language Runtime).
Because most of types in unmanaged environment do not have counterparts in managed environment, so we have to create conversion routine that convert manage types into unmanaged types and vice versa.
We call .Net code “Managed code” because it is controlled by CLR. Other code that is not managed by the CLR is called as unmanaged code.

What does mean of Thread Safe?What is Thread safe?



A thread safe is an unfortunate term because it does not have a solid definition. 

Thread safe basically means a bit of code or a piece of code will function correctly even when accessed by multiple threads. Multiple problems can occur if you use non-thread safe code in threaded application. The most common problem is deadlocking. 

Example:-
public class WidgetManipulator
{
   public int TotalWidgets = 0;
   public void AddWidget()
   {
      TotalWidgets++;
      Console.WriteLine("Total widgets = " + TotalWidgets.ToString());
   }
   public void RemoveWidgets()
   {
      TotalWidgets -= 10;
   }
}

This class exposes two methods. One method,addWidgets, add 1 to TotalWidgets fileds and writes the value to console. The second method subtracts 10 from the value of TotalWidgets. Consider a situation what would happen if two threads simultaneously attempt to access the same instance of WidgetManipulator class. One thread call AddWidget at the same time that second thread called RemoveWidgets. In this case, the value of TotalWidgets could be changed by the second thread before an accurate value could be reported by the first thread.

Tuesday 26 January 2016

what is unit testing?

A Unit testing is smallest testable part of an application like function or procedure or classes or interfaces. Unit testing is a method by which individual unites of source code are tested to be determined if they are fit to use.

Monday 25 January 2016

Procedure Vs Function

1.) Unlike Stored Procedure, Function returns only single value.
2.) Unlike Stored Procedure, Function accepts only input parameter.
3.) Unlike Stored Procedure, Function is not used for Insert|Update|Delete data in database.
4.) Unlike Stored Procedure, Function can be nested up to 32 level.
5.) Stored procedure can have 2100 input parameter while Function have up to 1023 input parameter.
6.) Unlike Stored Procedure, User Defined function cannot returns xml data type.
7.) Unlike Stored Procedure, User defined function doesn’t support exception  handling.

Why we go for page rendering in asp.net page life cycle?

Render is not an event. It a method to generate the output to send to the client. Browser understand only html markup so in page rendering All APSX controls are converted into html controls. That’s why we go for page rendering.

Tuesday 19 January 2016

Why we cannot create object of abstract class?


If a class use keyword ‘abstract’ then it cannot be instantiated and can only be used as  base class.

Abstract class is like a template or an empty or partially empty structure, you have to extend it and build it before you can use it.
Example:-  let’s take an example animal abstract class. There are no such things as real animal. There are specific types of animal. You can instantiate cow and elephant and tiger but you cannot instantiate plain animal. So we create derived class from base class with different functionality like ‘makesound()’ but cannot be defined as base class level. So that it is not possible to create object of abstract class.

Monday 18 January 2016

is it possible to create a constructor in Abstract class?

Yes. You can create a constructor in abstract class but it cannot be inherited. You cannot declare abstract constructor because constructor cannot be overridden. You can create public, private and protected constructors for abstract class.