Monday, 23 September 2013

Interview questions for C#.Net


Interview questions for C#.Net
1. What’s the top .NET class that everything is derived from?
  • System.Object.
2. Does C# support multiple-inheritance?
  • No. It supports only user interfaces.
3. Who is a protected class-level variable available to?
  • It is available to any sub-class (a class inheriting this class).
4. Are private class-level variables inherited?
  • Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.
5. Describe the accessibility modifier "protected internal" ?
  • It is available to classes that are within the same assembly and derived from the specified base class.
6. What does the term immutable mean?
  • The data value may not be changed. Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.
7. What’s the difference between System. String and System.Text.StringBuilder classes?
  • System. String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
8. What’s the advantage of using System.Text.StringBuilder over System. String?
  • String Builder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.
9. Can you store multiple data types in System.Array?
  • No.
10. What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
  • The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The Copy To () method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identical object.
11. How can you sort the elements of the array in descending order?
  • By calling Sort() and then Reverse() methods.
12. What’s the .NET collection class that allows an element to be accessed using a unique key?
  • HashTable.
13. What class is underneath the Sorted List class?
  • A sorted Hash Table.
14. Will the finally block get executed if an exception has not occurred?
  • Yes.
15. What’s the C# syntax to catch any possible exception?
  • A catch block that catches the exception of type System. Exception. You can also omit the parameter data type in this case and just write catch {}.
16. Can multiple catch blocks be executed for a single try statement?
  • No. Once the proper catch block processed, control is transferred to the finally block (if there are any).
17. Explain the three services model commonly know as a three-tier application.
  • Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources).
Questions on Classes
18. What is the syntax to inherit from a class in C#?
  • Place a colon and then the name of the base class.
    Example: Class MyNewClass : MyBaseClass
19. Can you prevent your class from being inherited by another class?
  • Yes. The keyword “sealed” will prevent the class from being inherited.
20. Can you allow a class to be inherited, but prevent the method from being over-ridden?
  • Yes. Just leave the class public and make the method sealed.
21. What’s an abstract class?
  • A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.
22. When do you absolutely have to declare a class as abstract?
  • 1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
    2. When at least one of the methods in the class is abstract.
23. What is an interface class?
  • Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes.
24. Why can’t you specify the accessibility modifier for methods inside the interface?
  • They all must be public, and are therefore public by default.
25. Can you inherit multiple interfaces?
  • Yes. .NET does support multiple interfaces.
26. What happens if you inherit multiple interfaces and they have conflicting method names?
  • It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.
27. What’s the difference between an interface and abstract class?
  • In an interface class, all methods are abstract - there is no implementation. In an abstract class some methods can be concrete. In an interface class, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers.
28. What is the difference between a Struct and a Class?
  • Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval. Another difference is that structs cannot inherit.

CLR Architecture


Introduction
Common Language Runtime (CLR) is platform dependent, where as Intermediate Langage (IL) code is platform independent. When dotnet application is executed the request will goto operating system. Operating system will create memory process, and IL instructions will be loaded. Operating system will load CLR to process IL instructions.
CLR (mscoree.dll)
The program used for calling CLR is called 'Runtime Host'. Runtime Host for desktop application is windows API function-"corbindtoruntime". Runtime Host for web based application is "Asp.Net worker process".
CLR is a runtime engine with collection of services:
'Assembly Resolver' will read manifest of exe file, it will identify private assemblies and shared assemblies required for application execution. It will forward request to 'Assembly Loader'
Assembly loader will load assemblies from application folder or GAC into application process. 'Type Checker' will verify types used by application with CLS or CTS standards. This provides Type Safety.
'Debug Manager' will activate debugger utility for line by line execution. It allows modification of code without terminating application.
'Exception Manager' will handle exceptions thrown by application. If there is no catch block (that is solution from developer), the application will be terminated.
'Com Marshals' will provide communication with Com component from dotnet application. This provides COM Interoperatability.
'Thread Support' service wil manage multiple threads with in application process. This provides Multi-Threading.
'Garbage Collector' will release unused objects memory. This provides automatic memory management
IL to native compiler is called JIT (Just in Time) compiler. This will process IL instructions into operating system native code.

Passing Parameters to a method in C#.Net


Introduction
Passing Parameters to a method is explained here.C#.Net supprots to pass the parameters in three ways
1. CallByValue
2. CallByRef
3. CallbyOut
When formal argument is modified, if modifications are reflected on actual arguments,then the concept is called as CallByRef.
When formal arguments are modified, if modifications are not reflected in actual arguments, then the concept is called as CallByValue
By default all the variables will be passed by value.
To pass a variable by reference, ‘Ref’ keyword is used.
Ref keyword must be used along with formal and actual arguments.
The variables passing by ref must be initialized.
CallByOut: Out is a keyword. Out and Ref are almost same. Ref variables must be initialized,but Out variables can be passed without initialization also. Even if Out variable is initialized, the value will not be passed.
Summary:
CBV: Value will be passed.
CBR: Value and Address will be passed
CBO: Only address will be passed.

All about KEYWORDS,IDENTIFIERS and DATA TYPES in C#.Net


Introduction
KEYWORDS : 
Keywords are the words which are language specific. A keyword is an essential part of a language definition. These words cannot be used as identifiers. Identifiers are nothing but names given to various entities used in a program. The examples of keywords are event, byte, break, using, class..etc

IDENTIFIERS : 
Identifiers are program-defined tokens. Identifiers are names of various program elements like classes, methods, variables, namespaces, interfaces...etc. in the code that uniquely identify an element. Now let us see what these entities are.

class contains some common properties and behaviors of an object. A method defines how an object behaves. Variables are placeholders for storing the values used in a program according to the type of data to be stored. Namespace help in organizing the classes so that they can be found easily. When two classes of are of same name, namespaces help in distinguishing these classes. That is different namespaces can be uesd to access these classes. Once a namespace is imported, we don't have to qualify items in that namespace by listing the entire namespace when we refer to them. An interface separates the definition of an objects from their implementation.
There are certain rules for C# identifiers :
  • They can have alphabets,digits, and underscore characters
  • They must not begin with digits
  • Upper case and lower case letters are distinct because C# is a case sensitive language
  • Keywords cannot be used as identifiers
DATA TYPES : C# is a strongly typed and rich language; therefore every variable in C# is associated with a Data type. Data types specify the type of values that can be stored in a variable. There are number of data types available in C# that allows a programmer to select the type appropriate to the requirement of the application.
The data types in C# are primarily categorized in three parts :
  • Value Types
  • Reference Types
  • Pointer Types
DataTypes

VALUE TYPES : Value types are of fixed length and stored on the stack in memory. When a value of a variable is assigned to another variable, that value is actually copied. This means that two identical copies of the value are available in the memory.
We can further categorize value types in two parts : User-defined types and Pre-defined types.

USER-DEFINED TYPES : The value types which are defined by the user is known as user-defined types. There are two user-defined types :
Structure : A structure is simply a composite data type consisting of a number of elements of other data types; it is almost same as classes but is used in context of relatively simple data types as it stores the value on the stack; normally, we refer structure as struct in C#.
Enumerations : An enumeration provides a way for attaching names to numbers in a program, which in turn increases the readability of code; we use enum keyword in C# to declare an enumeration.

PRE-DEFINED TYPES : Pre-defined types are also known as simple types. Pre-defined types are those value types which are already defined in C#. These types are available in C# as shown in below table.

TypeSignedSize in BytesPossible Values(Range)
sbyteYes1-128 to 127
shortYes2-32768 to 32767
intYes4-2147483648 to 2147483647
longYes8-9223372036854775808 to 9223372036854775807
byteNo10 to 255
ushortNo20 to 65535
uintNo40 to 4294967295
ulongNo80 to 18446744073709551615
floatYes4Approximately +/- 1.5*10^-45 to +/- 3.4*10^38 with 7 significant figures
doubleYes8Approximately +/- 5.0*10^-324 to +/- 1.7*10^308 with 15 or 16 significant figures
decimalYes12Approximately +/- 1.0*10^-28 to +/- 7.9*10^28 with 28 or 29 significant figures
charN/A2Any Unicode character(16 bit)
boolN/A1/2true or false

Pre-defined types can be further sub-divided into three parts as shown below.
  • Numeric Types
  • Boolean Types
  • Character Types
NUMERIC TYPES : It is further divided into the following types:
  • Integral Types : Integral types hold whole numbers for example 123, -123, 3456, etc. The size and sign of the values depend on the integral data type we choose. Integral data type consists of two subtypes: Signed and Unsigned, each of which supports four types of integers. Signed integers support both positive and negative numbers while Unsigned integers holds only positive numbers.
  • Floating Point Types : In addition to whole number a floating point type can also hold a fractional part of a number such as -123.45 and 123.56. It can be further divided into two parts like float and double. To specify a number to be of float type, you must append the character f to the value such as 12.4f. If you omit f, the value will be treated as double. Here is the syntax for floating point variables:
      1. float percent = 67.4f;
        double val = 3.4;
  • Decimal Types : The decimal type is designed for financial and monitory calculations. To specify a number to be of decimal type, you must append the character M(or m) to the value such as 123.45M. If you omit M, the value will be treated as double. Here is the syntax for decimal type variables:
      1. decimal money = 123.45M;
CHARACTER TYPES : Character type(char) stores single character in memory. The char type assumes a size of two bytes but it holds only a single character. Here is the syntax for character type variables:
      char c = 'w';
BOOLEAN TYPES : Boolean type(bool) is used to test a particular condition during the executionof a program. Boolean type takes only two values: true and false. Here is the syntax for a boolean type variable:
      bool cond = true;
REFERENCE TYPES : Reference types are of varied length and stored on the heap in memory. When an assignment between two reference variables occurs, only the reference is copied and the actual value remains the same in memory location. We can further categorize reference types in two parts: User-defined types and Pre-defined types.

USER-DEFINED TYPES : User-defined reference types refer to those types which the user defines using pre-defined types. Following are the user defined reference types:
  • Classes : As we know that C# is purely an object oriented language so the base of all C# programs is the concept of class; classes provide the best approach to group together logically related items and functions that work on them.
  • Interfaces : Interfaces are used as superclasses whose properties are inherited by classes; the concept of an interface came into scene to support multiple inheritance(inheriting from more than one superclass) because in C# a class does not support multiple inheritance; extending the functionalities and behavior of one class into another class into another is called inheritance.
  • Delegates : Delegates are objects which point towards a method which matches its signature (values passed to the method) to that delegate; delegates are reference type used to encapsulate a method with a specific signature; in C++, this task could be performed by having pointer to a function.
  • Arrays : An Array is an ordered arrangement of data elements; in technical words, it contains a number of variables of the same type with the same name at contiguous locations of memory.
PRE-DEFINED TYPES : Pre-defined reference types are mainly of two types:
  • Object Type : The object type is the ultimate base type of all other pre-defined and user-defined data type in C#; you can use the object type to convert a value type on a disk to an object type to be placed on the heap.
  • String Type : String type is for creating and manipulating textual data in C#; you can perform various operations on strings such as copying, comparing, and concatenation on these string objects.
POINTER TYPES : Pointer types are used only in unsafe context. Pointer types do not inherit from the object base class which is an ultimate base class of .NET and we cannot convert pointer types to object type and vice-versa. Here is the syntax for declaring pointer type data types:
datatype* identifier;
In next article we will see All about Collections in C#.Net

Managed and Unmanaged code


Introduction
The code which is executing with the help of CLR is called as managed code. The code which is targeting operating system while execution is called as unmanaged code or Code that runs outside the CLR is referred to as "unmanaged code." COM components, ActiveX components, and Win32 API functions are examples of unmanaged code. Unmanaged code uses registry of operating system. Managed code is faster in execution

About CLR: CLR is common language runtime. It is a standard runtime execution engine for managed code.
While executing the Dot Net application, in the client machine only Dot Net framework software is enough.
Dot Net framework will be installed by default with Dot Net software, if required CLR can be installed separately also.
CLR related files will be stored in C:\windows\system32 folder. In CLR software the most important file name is mscoree.dll.
.dll file is not self executable, it depends on another, it can be reusable, .exe is self executable.
Current Versions Of Dot Net:
  1. Dot Net frame work version - 4.0
  2. Dot Net IDE version - 2010
  3. VC#.Net language version - 4.0
  4. CLR version - 4.0.31106.0
Language Interoperability: It is a concept of developing an application with the help of more than one DotNet programming language. Whenever a program is compiled that will be converted into byte code or MSIL(Microsoft intermediate language code). This byte code follows a standard instruction set which is specified by CLS(Common language specification). CLS specifies the common syntaxes for all the DotNet programming languages.
AppDomain (Application Domain): An application domain can be considered similar to a lightweight OS process, and is managed by the common language runtime.

Managed and Unmanaged code


Introduction
The code which is executing with the help of CLR is called as managed code. The code which is targeting operating system while execution is called as unmanaged code or Code that runs outside the CLR is referred to as "unmanaged code." COM components, ActiveX components, and Win32 API functions are examples of unmanaged code. Unmanaged code uses registry of operating system. Managed code is faster in execution

About CLR: CLR is common language runtime. It is a standard runtime execution engine for managed code.
While executing the Dot Net application, in the client machine only Dot Net framework software is enough.
Dot Net framework will be installed by default with Dot Net software, if required CLR can be installed separately also.
CLR related files will be stored in C:\windows\system32 folder. In CLR software the most important file name is mscoree.dll.
.dll file is not self executable, it depends on another, it can be reusable, .exe is self executable.
Current Versions Of Dot Net:
  1. Dot Net frame work version - 4.0
  2. Dot Net IDE version - 2010
  3. VC#.Net language version - 4.0
  4. CLR version - 4.0.31106.0
Language Interoperability: It is a concept of developing an application with the help of more than one DotNet programming language. Whenever a program is compiled that will be converted into byte code or MSIL(Microsoft intermediate language code). This byte code follows a standard instruction set which is specified by CLS(Common language specification). CLS specifies the common syntaxes for all the DotNet programming languages.
AppDomain (Application Domain): An application domain can be considered similar to a lightweight OS process, and is managed by the common language runtime.

Dot Net Frame Work Main Objectives


Introduction
Microsoft introduced Dot Net programming concepts in the year 1999. Dot Net contains a collection of languages like VC#.Net, VB.Net, VJ#.Net, VC++.Net, ASP.Net(specification)...etc. All the Dot Net programming languages works based on a common platform called Dot Net framework.
Dot Net Framework Main Objectives:
  1. Supports platform independent concepts
  2. Supports language independent concepts
  3. Supports language interoperability concepts
  4. Supports pure OOPs concepts
  5. Supports to develop background processes with the help of windows services
  6. Supports to work with databases with the help of ADO.NET
  7. Supports to develop 3-tier architecture with the help of Dot Net remoting
  8. Supports to develop game programming with the help of multi-threading
  9. Supports to work with link programming
  10. Supports to work with WPF for developing animations
Platform independent concepts: As .exe and .dll files work in any operating system with the help of CLR, hence .Net is called as platform independent. (.exe) is executable file, it consists of executable code, and (.dll) is dynamic link library file it consist of reusable code. .exe and .dll files contains the code in the format of bytecode is also called as MSIL (microsoft intermediate language) code. Machine language is also called as native code. CLR is common language runtime, CLR software converts byte code into native code. Dot Net is platform independent but CLR software is platform dependent. One question arises if we go in detail, that is either Dot Net is pure platform independent or not? Answer is Dot Net is partially platform dependent, as of now CLR software's are not available for DOS operating system and Windows 95. 
Language independent concepts: As Dot Net programming logic can be developed in any Dot Net framework compatible languages; hence Dot Net is called as language independent. Microsoft is introducing approximately 40 languages into Dot Net framework, out of which as of now approximately 24 languages and one specification are released.
Ex: VC#.Net,VB.Net,VC++,VJ#,VF#,PHP,COBOL,PERL,PHYTHON,SMALLTALK,JSCRIPT...etc
One specification is ASP.Net. VC#.Net is case sensitive, VB.Net is not case sensitive, and ASP.Net case sensitivity depends on integrated language.


About DLL Files: We can create DLL files with the help of Dot Net(C#,VB...etc), and also we can create with the help of visual studio 5.0 or 6.0 (VB 5.0/6.0, VC++ 5.0/6.0..etc)
What is DLL as per VB 6.0 or VC++ 6.0?
  • VB 6.0 or VC++ 6.0 DLLs contains the reusable code in the format of machine language.
  • VB 6.0 or VC++ 6.0 DLLs are called as COM(component object model) components.
  • Every COM component must be registered for a class ID.
  • Class IDs are unique.
  • Class ID is a part of registry.
  • As regestry is a part of Windows OS, hence COM components are platform dependent.
What is DLL as per Dot Net?
  • Dot Net DLLs contain the reusable code in the format of byte code.
  • Dot Net DLLs are platform independent.
  • Dot Net DLLs are called as assemblies.
  • A collection of classes is called as Namespace.
  • A collection of Namespaces is called as assembly.
  • A collection of assemblies is called as FCL(Frame Work Class Library) or BCL(Base Class Library).

Static variables and Static methods in CSharp


Introduction
Working With Static Concepts: 
  • Static is a keyword.
  • Static can be used with variables, constructors, methods, classes.
  • Instance variables will be created seperately for every object.
  • Static variables will be created only once while class is loading into the memory, Hence static variables are also called as class variables
  • Static variables are sharable by all the objects.
  • If static variable is public, then it can be accessed directly with ClassName.StaticVariable.
  • Static constructor will be executed only once, while class is loading into the memory.
  • Static constructor is capable to access only static variables.
  • Static methods need to be called with ClassName.MethodName()
class Test
{
    public void print();
    public static void display();            
       
}
Observation: 
Test t = new Test(); -----> possible
t.print(); ------>possible
t.display(); ----->not possible
Test.print(); ----->not possible
Test.display(); ------>possible
Whenever a class contains all static methods, then it is recommended to declare the class as static. Static classes are not instantiatable means not possible to create an object. Following is the example for static variables and methods.
class Test
{
    private int i;    //instance variable
    private static int s;   //static variable
    static Test()   //static constructor
    {
        s=0;
    }
    public Test()  //contructor
    {
        i = i + 1;
        s = s + 1;
        MessageBox.Show(i + " " + s);

    }     
}   

private void button1_Click(object sender, EventArgs e)
{
    Test t1 = new Test();
    Test t2 = new Test();
    Test t3 = new Test();
}

Constructors and Destructors in CSharp


Introduction
A constructor is a special method of a class which is used to intialize the data members of the class. Constructor is a special type of method, which will be executed automatically while creating an object. Destructor is a special type of method, which will be executed automatically while destroying an object. Some of main features of contructor are,
  • It is a sub procedure declared with the new keyword.
  • It doesn't return any value.
  • A class can have multiple constructors
  • It doesn't mandatory to declare a constructor, the compiler invokes it automatically
Differences between constructor and destructor
ConstructorDestructor
Constructor is a special type of method, executed automatically while creating an object.Destructor is a special type of method, executed automatically while destroying an object.
Constrctor name must be same as class name without any return type.Destructor name must be same as class name with a ~(tild) prefix and without any return type and access specifier.
Constructors are overloadable.Destructors are not overloadable.
Generally constructors are required while initializing instance variables, to open files or to open database connections.Generally destructors are used to deallocate the memory or to close the files or to close database connections.
Example on constructor and destructor along with garbage collector concepts:
    class Test
    {
        public Test()
        {
            MessageBox.Show("From Constructor");

        }
        ~Test()
        {
            MessageBox.Show("From Destructor");
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Test t1 = new Test();
        Test t2 = new Test();
        Test t3 = new Test();
    }
  

Observation:
  • Here in the above program constructor executed for 3 times destructor also executed for 3 times.
  • Destructor will be executed after the project is closed.
  • After destructor is executed then within two seconds garbage collector will be loaded into the memory.
  • Garbage collector reclaim|deallocate|free the memory allocated for the current project.
  • Garbage collector will be done with the help of a predefined class called as System.GC

Delegates in C#.Net


Introduction
  • Delegates are objects which point towards a method which matches its signature(values passed to the method) to that delegate.
  • Delegates are reference type used to encapsulate a method with a specific signature.
  • C++ function pointers are called as C#.NET delegates.
  • Delegates holds the address of one method or addresses of many methods.
  • Delegates hides some information like class names and method names.
  • The delegates are divided into two types, singlecast delegate and multicast delegate.
  • Single cast delegate holds the address of one method, and multicast delegate holds the addresses of many methods.
Steps for creating a delegate: 1. Write a class with a set of methods
Syntax:
class Test
{
    public void print()
    {
        logic;
    }
}
2. Create a delegate
Syntax: 
Public delegate void Dname()
3. Create an object for the delegate with the address of a method
Syntax: 
Test t=new Test();
Dname x=new Dname(t.print);
4. Call the delegate object--> x();
Example on single cast delegates: Open windows forms application project
Place a button
Code in general declaration
    class Test
    {
        public void print()
        {
        MessageBox.Show("from print");
        }//print
        }//test
        public delegate void XYZ();

        private void button1_Click(object sender, EventArgs e)
        {
            Test t = new Test();
            XYZ x = new XYZ(t.print);
            x();
    }
Working with Multicast Delegate:
  • Multicast delegate holds a collection of methods.
  • Multicast delegate holds a sequence of methods.
  • A collection of single cast delegates is also called as Multicast delegate.
  • Multicast delegate supports arithmetic + and - operations.
  • + operator adds a method into the sequence.
  • - operator remove a method from the sequence.
Example on Multicast delegate:
Open console application project.
Code in general declaration(Before main method).
    class program
    {
            class Test
            {
                public void m1()
                {
                    Console.Write("GM");
                }//m1
                public void m2()
                {
                    Console.WriteLine("GA");
                }//m2
            }//test
        }//program
        public delegate void Dname();
        
        static void Main()
        {
            Test t = new Test();
            Dname d1, d2, d3, d4, d5, d6;
            d1 = new Dname(t.m1);
            d2 = new Dname(t.m2);
            d3 = d1 + d2;
            Console.WriteLine("from D3");
            D3();
            D4 = D3 + D3;
            Console.WriteLine("from D4");
            D4();
            D5 = D4 - D1;
            Console.WriteLine("from D5");
            D5();
            D6 = D5 - D3 - D2;
            Console.WriteLine("from D6");
            D6();//Null reference
            Console.ReadKey();
    }
       

What is Boxing and Unboxing in C#.Net?


Introduction
Boxing: Converting a value type to reference type is called boxing
Example:
int i = 101;
object obj = (object)i; // Boxing
Boxing happens implicitly, where as unboxing is an explicit conversion.
Boxing is used to store value types in the garbage-collected heap. Boxing is an implicit conversion of a value type to the type object or to any interface type implemented by this value type. Boxing a value type allocates an object instance on the heap and copies the value into the new object.
Unboxing: Converting a reference type to a value typpe is called unboxing. An unboxing operation consists of:
  • Checking the object instance to make sure that it is a boxed value of the given value type.
  • Copying the value from the instance into the value-type variable.
Example:
obj = 101;
i = (int)obj; // Unboxing
Attempting to unbox null causes a NullReferenceException. Attempting to unbox a reference to an incompatible value type causes an InvalidCastException.
Performance according to MSDN:
It is best to avoid using value types in situations where they must be boxed a high number of times, for example in non-generic collections classes such as ArrayList. You can avoid boxing of value types by using generic collections such as List. Boxing and unboxing are computationally expensive processes. When a value type is boxed, an entirely new object must be created. This can take up to 20 times longer than a simple reference assignment. When unboxing, the casting process can take four times as long as an assignment.

Sql Server keyboard shortcuts


Some of the useful keyboard shortcut keys for Sql Server are given here:
Bookmarks: Clear all bookmarks.CTRL-SHIFT-F2
Bookmarks: Insert or remove a bookmark (toggle).CTRL+F2
Bookmarks: Move to next bookmark.F2
Bookmarks: Move to previous bookmark.SHIFT+F2
Cancel a query.ALT+BREAK
Connections: Connect.CTRL+O
Connections: Disconnect.CTRL+F4
Connections: Disconnect and close child window.CTRL+F4
Database objects information.ALT+F1
Editing: Clear the active Editor pane.CTRL+SHIFT+ DEL
Editing: Comment out code.CTRL+SHIFT+C
Editing: Copy. You can also use CTRL+INSERT.CTRL+C
Editing: Cut. You can also use SHIFT+DEL.CTRL+X
Editing: Decrease indent.SHIFT+TAB
Editing: Delete through the end of a line in the Editor pane.CTRL+DEL
Editing: Go to a line number.CTRL+G
Editing: Increase indent.TAB
Editing: Make selection lowercase.CTRL+SHIFT+L
Editing: Make selection uppercase.CTRL+SHIFT+U
Editing: Remove comments.CTRL+SHIFT+R
Editing: Repeat last search or find next.F3
Editing: Replace.CTRL+H
Execute a query. You can also use CTRL+E (for backward compatibility).F5
Books OnlineF1
Help for the selected Transact-SQL statement.SHIFT+F1
Navigation: Switch between query and result panes.F6
Navigation: Switch panes.Shift+F6
Navigation: Window Selector.CTRL+W
New Query window.CTRL+N
Object Browser (show/hide).F8
Object Search.F4
Parse the query and check syntax.CTRL+F5
Results: Display results in grid format.CTRL+D
Results: Display results in text format.CTRL+T
Results: Move the splitter.CTRL+B
Results: Save results to file.CTRL+SHIFT+F
Results: Show Results pane (toggle).CTRL+R
Templates: Insert a template.CTRL+SHIFT+INSERT
Templates: Replace template parameters.CTRL+SHIFT+M
Tuning: Display estimated execution plan.CTRL+L
Tuning: Display execution plan (toggle ON/OFF).CTRL+K
Tuning: Index Tuning Wizard.CTRL+I
Tuning: Show client statisticsCTRL+SHIFT+S
Tuning: Show server trace.CTRL+SHIFT+T
Use database.CTRL+U

Differences between sqlserver 2000, 2005 and 2008 versions


Introduction
The table shows the differences between sqlserver different versions. This can be helpful in interview questions.
Sql server 2000Sql server 2005Sql server 2008
Query analyser and enterprise manager are seperateBoth are combined into SSMS(sql server management studio)Both are combined as SSMS
No XML datatype usedXML datatype is introducedXML datatype is used
We can create maximum of 65,535 databases onlyWe can create maximum of (2^20)-1 databasesWe can create maximum of (2^20)-1 databases
NilException handlingException handling
NilVarchar(max) datatypeVarchar(max) datatype
NilDDL triggersDDL triggers
NilDatabase mirroring(sql DBA)Database mirroring
NilRow number function for pagingRow number function for paging
NilTable fragmentationTable fragmentation
NilFull text searchFull text search
NilBulk copy insertBulk copy update
NilCan't encryptCan encrypt the entire database introduced in 2008
Can't compress the tables and indexesCan compress tables and indexes(introduced in 2005 SP2)Can compress tables and indexes
Datetime datatype used for both date and timeDatetime datatype used for both date and timeDate & time are seperately used for date & time datatype, geospatial and timestamp with internal timezone is used
No varchar(max) or varbinary(max) is availablevarchar(max) and varbinary(max) is usedvarchar(max) and varbinary(max) is used
No table datatype is introducedTable datatype is introducedTable datatype is introduced
No SSIS is includedSSIS is started usingSSIS available in this version
CMS(centralized management server) is not availableCMS is not availableCMS is introduced
PBM(policy based management) is not availablePBM is not availablePBM server is introduced

Disable copy paste right click using javascript in asp.net TextBox


How to Disable copy paste right click using JavaScript in asp.net Textbox. We make two function in JavaScript one for disable right click and other for disable ctrl key. When we create right click on the textbox message will be generating to show disable right click.
Disable right click using JavaScript
function DisableRightClick(event)
 {
     if (event.button == 2)
      {
         alert("Right Clicking not allowed!");
         }
   }

Now calling that method on the onMouseDown event of the TextBox.

onMouseDown="DisableRightClick(event)">

Disable Ctrl key using javascript 
function DisableCtrlKey(e)
        {
            var code = (document.all) ? event.keyCode : e.which;
            var message = "Ctrl key functionality is disabled!";
            if (parseInt(code) == 17)
            {
                alert(message);
                window.event.returnValue = false;
           }
        }

Now calling that method on the onKeyDown event of the TextBox.
onKeyDown="return DisableCtrlKey(event)"
.ASPX Code
<head runat="server">
    <title></title>
    <script language="javascript">
        function DisableRightClick(event)
        {
            if (event.button == 2)
            {
                alert("Right Clicking not allowed!");
            }
        }
        function DisableCtrlKey(e)
        {
            var code = (document.all) ? event.keyCode : e.which;
            var message = "Ctrl key functionality is disabled!";
            if (parseInt(code) == 17)
            {
                alert(message);
                window.event.returnValue = false;
           }
        }
    </script>
    <style type="text/css">
        .style1
        {
            font-family: Verdana;
        }
        .style2
        {
            font-size: large;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        &nbsp;<span class="style1"><strong><span class="style2">Right click and Ctrl key
        </span> </strong><span class="style2">disabled.</span></span><br />
        <br />
        <asp:TextBox ID="TextBox2" onKeyDown="return DisableCtrlKey(event)" runat="server"
            onMouseDown="DisableRightClick(event)">
        </asp:TextBox><br />
        <br />
    </div>
    </form>
</body>


Now run the application and test it with right click and ctrl key.