Do you know that? 45% feel secure as a freelancer next

See right interview answers on 30 common job interview questions


Collapse | Expand

1. Advantages of CLR procedure over T-SQL procedure

  •  The use of the CLR procedure makes it possible to do the complex database operations without having an in-depth knowledge of T-SQL. 
  •  It also enables focusing the business layer towards the database in orderto increase the server performance by avoiding unnecessary server trips. 
  •  Also, with the help of the .NET Base Class Libraries, the complex logical operations can be effectively performed. 
  •  It deals with automatic garbage collection, memory management, exception handling, etc. due to which it is known as Managed Procedure. 
  •  The concepts of the OOP can also be applied. 
  •  It provides the ability to leverage the features of .NET Code Access Security  (CAS) to prevent assemblies from performing certain operations.

2. C#.Net support multiple inheritance, comment

No, but we can use interface instead. 

3. Can you inherit private class-level variables?

Yes, they can be inherited but they  are not accessible in the derived class, so it looks as if it is not inherited. 

4. Can you override private virtual methods?

 First of all private methods in the inherited class can't be accessed, so there is no question of overriding of private virtual methods. 

5. Canprivate virtual methods be overridden in C#.NET?

No, moreover, you cannot access  private methods in inherited classes,
They have to be protected in the   base class to allow any sort of access. 

6. CLR Triggers

A CLR trigger could be a Date Definition or Date Manipulation Language trigger or could be an AFTER or INSTEAD OF trigger.

Methods written in managed codes that are members of an assembly need to be executed provided the assembly is deployed in SQL 2005 using the CREATE assembly statement.

The Microsoft.SqlServer.Server Namespace contains the required classes and enumerations for this objective. 

7. Define abstract class in C#.NET.

Abstract class cannot be  instantiated.
Same concept in C++ known as pure   virtual method. 
A class that must be   inherited and have the methods over-ridden. 
Aclass without any implementation. 

8. Define assembly.

An assembly is the primary unit of  a .NET application. It includes an assembly manifest that describes the  assembly. 

9. Define Constructors?

A constructor is a member function with the same name as its class. The constructor is invoked whenever an object of its associated class is created.It is called constructor because it constructs the values of data members of the class.

10. Define Delegate.

Delegates are kind of similar to the function pointers. But they are secure and type-safe.
A delegate instance encapsulates a static or an instance method. 
Declaring a delegate defines a reference type which can be used to encapsulate a method having a specific signature. 

11. Define destructors?

A destructor is called for a class object when that object passes out of scope or is explicitly deleted.A destructors as the name implies is used to destroy the objects that have been created by a constructors.Like a constructor , the destructor is a member function whose name is the same as the class name but is precided by a tilde.

12. Define Interface class in C#.NET.

It isan abstract class with public abstract methods with no implimentation.

13. Define polymorphism?

Polymorphism means one name, multiple forms. It allows us to have more than one function with the same name in a program.It allows us to have overloading of operators so that an operation can exhibit different behaviours in different instances.

14. Define protected class-level variable in C#.NET.

It can be inherited by the classes  in the same namespace. 

15. Define protected internal.

This type of member is available to  derived classes and classes within the same Assembly. 

16. Define satellite assembly.

Satellite assembly is created to  write a multilingual or multi-cultural application in .NET. It allows  distributing the core application separately from the localized modules. 

17. Describe Anonymous functions in detail.

Ans: Anonymous means no name. An anonymous function is, an unnamed block of code that is passed to a delegate constructor. One advantage of using an anonymous function is that there is no need to declare a separate method whose only purpose is to be passed to a delegate. An anonymous method is created by following the keyword delegate with a block of code.
Example:
using System;

namespace Test
{
delegate void AnonymousDemo();
class Demo
{
static void Main()
{

AnonymousDemo DelObj = delegate
{
// This is the block of code passed to the delegate.

Console.WriteLine("Hello anonymous method");
}; // notice the semicolon
DelObj();
}
}
}

18. Describe delegate in detail.

A delegate is an object that can refer to a method. It means that it can hold a reference to a method. The method can be called through this reference or we can say that a delegate can invoke the method to which it refers. The same delegate can be used to call different methods during the runtime of a program by simply changing the method to which the delegate refers. The main advantage of a delegate is that it invokes the method at run time rather than compile time. Delegate in C# is similar to a function pointer in C/C++.
A delegate type is declared using the keyword delegate. The prototype of a delegate declaration is given below:

  delegate ret-type name(parameter-list);

Important Note:A delegate can call only those methods that have same signature and return type as delegate.
Example:
delegate string StrDemo(string str);
This delegate can only call those methods that have string return type and take argument as string.

Example on Delegate.
using System;
// Declare a delegate type.
namespace Test
{
delegate string StrDemo(string str);
class DelegateDemo
{
// Replaces spaces with **.
public string ReplaceSpaces(string s)
{
Console.WriteLine("Replacing spaces with *.");
return s.Replace(' ', '*');
}
// Remove spaces.
public string RemoveSpaces(string s)
{
string temp = "";
int i;
Console.WriteLine("Removing spaces.");
for (i = 0; i < s.Length; i++)
if (s[i] != ' ') temp += s[i];
return temp;
}

}
class MyClass
{
static void Main()
{
DelegateDemo obj = new DelegateDemo();
StrDemo strOp = new StrDemo(obj.ReplaceSpaces);
string str;
str = strOp("This is a test.");
Console.WriteLine("Resulting string: " + str);
Console.WriteLine();
strOp = new StrDemo(obj.RemoveSpaces);
str = strOp("This is a test.");
Console.WriteLine("Resulting string: " + str);
Console.WriteLine();

Console.ReadLine();
}
}
}

Output:

Replacing spaces with *.
  Resulting string: This*is*a*test.
  Removing spaces.
  Resulting string: Thisisatest.

19. Describe Event in .Net.

Ans.It is an important feature of C# that is based upon delegate. An Event is a message sent by an object such as control (Button, Checkbox, Radio button,etc.) or other part of the user interface, that the program responds to by executing code. It is an automatic notification that some action has occurred.
Events are members of a class and are declared using the eventkeyword. The general prototype of an event declaration 

event event-delegate event-name;

  Example:

using System;
namespace Test
{
// Declare a delegate type for an event.
delegate void MyEventHandler();
// Declare a class that contains an event.
class MyEvent
{
public event MyEventHandler SomeEvent;
// This is called to fire the event.
public void OnSomeEvent()
{
if (SomeEvent != null)
SomeEvent();
}
}
class EventDemo
{
// An event handler.
static void MyHandler()
{
Console.WriteLine("Event occurred");
}
static void Main()
{
MyEvent evt = new MyEvent();
// Add MyHandler() to the event list.
evt.SomeEvent += MyHandler;
// Fire the event.
evt.OnSomeEvent();
}
}
}

20. Describe how a .Net application is compiled and executed.

From the source code, the compiler generates Microsoft Intermediate Language (MSIL) which is further used for the creation of an EXE or DLL. The CLR processes these at runtime. Thus, compiling is the process of generating this MSIL.

The way you do it in .Net is as follows:
Right-click and select Build / Ctrl-Shift-B / Build menu, Build command
F5 - compile and run the application. 
Ctrl+F5 - compile and run the application without debugging. 

 Compilation can be done with Debug or Release configuration. The difference    between these two is that in the debug configuration, only an assembly is    generated without optimization. However, in release complete optimization is    performed without debug symbols. 

21. Describe Lambda Expressions in brief.

Ans. An anonymous function can be created in another way that is called Lambda Expressions. The lambda expression provides a powerful alternative to the anonymous method.

The Lambda Operator

All lambda expressions use the new lambda operator, which is denoted by the symbol =>. This operator divides a lambda expression into two parts. On the left the input parameter (or parameters) is specified. Right hand side is the body of the lambda. The => operator is sometimes pronounced as ''goes to'' or ''becomes.'' There are two types of lambda expression in C#. What type of lambda expression is created, it is determines by the lambda body. The two types are 

- Expression lambda
- Statement lambda

An expression lambda contains single expression. In this case, the body is not enclosed between braces. Statement lambda contains block of statements enclosed by braces. A statement lambda can contain multiple statements and include loops, method calls, and if statements.

Example:
using System;
namespace Test
{
delegate int Increment(int n);
// a delegate that takes an int argument 

class SimpleLambdaDemo
{
static void Main()
{
// Create an Increment delegate instance that refers to
// a lambda expression that increases its parameter by 3.
Increment incr = count => count + 3;
// Now, use the incr lambda expression.
Console.WriteLine("Use increment lambda expression: ");
int x = 10;
while (x <= 20)
{
Console.Write(x + " ");
x = incr(x); // increase x by 3
}
Console.WriteLine("\n");

}
}
}

22. Describe multicast event handling with example.

Ans

using System;
namespace Test
{
// Declare a delegate type for an event.
delegate void MyEventHandler();
// Declare a class that contains an event.
class MyEvent
{
public event MyEventHandler SomeEvent;
// This is called to fire the event.
public void OnSomeEvent()
{
if (SomeEvent != null)
SomeEvent();
}
}
class ButtonClass
{
public void Buttonhandler()
{
Console.WriteLine("Event received by button object");
}
}
class CheckBoxClass
{
public void Chkhandler()
{
Console.WriteLine("Event received by checkbox object");
}
}
class EventDemo
{
static void Handler()
{
Console.WriteLine("Event received by EventDemo");
}
static void Main()
{
MyEvent evt = new MyEvent();
ButtonClass btnObj = new ButtonClass();
CheckBoxClass chkObj = new CheckBoxClass();
// Add handlers to the event list.
evt.SomeEvent += Handler;
evt.SomeEvent += btnObj.Buttonhandler;
evt.SomeEvent += chkObj.Chkhandler;
// Fire the event.
evt.OnSomeEvent();
Console.WriteLine();
// Remove a handler.
evt.SomeEvent -= btnObj.Buttonhandler;
evt.OnSomeEvent();
}
}
}

Output:

Event received by EventDemo
  Event received by button object
  Event received by checkbox object
  Event received by EventDemo
  Event received by checkbox object

Important points regarding event.

Events can be specified in interfaces. Implementing classes must supply the event.
Events can be specified as abstract
An event can be specified as sealed.
An event can be virtual.

23. Describe the accessibility modifier "protected internal" in C#.

The Protected Internal access modifier can be accessed by:
Members of the Assembly
The inheriting class
The class itself

Its access is limited to the types derived from the defining class in the current assembly or the assembly itself. 

24. Describe the three major components that make up a Web Service.

  •  SOAP (Simple Object Access Protocol) 
  •  UDDI (Universal Description, Discovery and Integration) 
  •  WSDL (Web Services Description Language)

25. Difference between // comments, /* */ comments and /// comments.

// comments - It is Single-line  comment
/* */ comments - It is multi-line comment
/// comments - It is XML documentation comments. 

26. Difference between an interface and abstract class

 In the interface all methods must be abstract;
In the abstract class some methods  can be concrete. 
In the interface no  accessibility modifiers are allowed, which ispossible in abstract  classes. 

27. Difference between an interface and abstract class

Some methods in the abstract class  can be concrete whereas all methods in the interface are abstract. 

28. Difference between System.String and System.StringBuilder classes.

System.String is immutable;
System.StringBuilder was designed   with the purpose of having a mutable string where a variety of operations  canbe performed. 

29. Difference between the System.Array.CopyTo() and System.Array.Clone().

System.Array.CopyTo() performs a  deep copy of the array
System.Array.Clone() performs a shallow copy of the array 

30. Explain assert().

Assert method is in debug  compilation. It takes a boolean condition as a parameter. It shows error dialog  if the condition is false and if the condition is true, the program proceeds  without interruption. 

31. Explain how Obfuscator works.

  •  Obfuscators protect the source code from being hacked. Encryption and Decryption are processes from where you can get the data back. 
  •  However these differ from what obfuscation is. In obfuscation, a program become out of the reach of hackers although it functions the same way it is supposed to. 
  •  Optimizations too get applied to the process of obfuscation in order to make  the program fast.

32. Explain how to add controls dynamically to the form using C#.NET.

The following code can be called on some event like page load or onload of some image or even a user action like onclick

protected void add_button(Button button)
{
try
{
panel1.Controls.Add(button); // Add the control to the container on a page
}
catch (Exception ex)
{
label1.Text += ex.Message.ToString();
}
}

33. Explain how to Handle Exceptions in .NET 2.0.

The different methods of handling the exceptions are:

  •  1.
  try
  {
  // code
  }
  catch(Exceptiontype *etype_object)
  {
  // code
  } 
  •  2.
  try
  {
  // code
  }
  catch(Exceptiontype *etype_object)
  {
  throw new Custom_Exception();
  }

34. Explain how to Implement an Object Pool in C#.NET.

using System;
using System.Collections;

namespace ObjectPool
{
class ObjQueue
{
private static int maxSize = 2;
private static readonly Queue objPool = new Queue(maxSize); 
public MyClass GetMyClass()
{
MyClass oMyClass;
if (MyClass.Counter >= maxSize && objPool.Count>0)
oMyClass = RetrieveFromPool();
else
oMyClass = GetNewMyClass();
return oMyClass;
}
private MyClass GetNewMyClass()
{
MyClass myObj = new MyClass();
objPool.Enqueue(myObj);
return myObj;
}
protected MyClass RetrieveFromPool()
{
MyClass myObj;
if (objPool.Count>0)
{
myObj = (MyClass)objPool.Dequeue();
MyClass.Counter--;
}
else
myObj = new MyClass();
return myObj;
}
}
class MyClass
{
public static int Counter = 0;
public MyClass() { ++Counter; }
private string _Firstname;
public string Firstname
{
get { return _Firstname; }
set { _Firstname = value; }
} 
}}

35. Explain how to implement Delegates in C#.NET

Here is an implementation of a very simple delegate that accepts no parameters.

public delegate void MyDelegate();// Declaration
class MyClass
{
public static void MyFunc()
{
Console.WriteLine("MyFunc Called from a Delegate");
}
public static void Main()
{
MyDelegate myDel = new MyDelegate(MyFunc);
myDel();
}
}

36. Explain how to sort the elements of the array in descending order.

You can do so by calling Sort() and  then Reverse() methods.

37. Explain serialization.

Serialization is a process of  converting an object into a stream of bytes. .Net has 2 serializers namely  XMLSerializer and SOAP/BINARY Serializer. Serialization is maily used in the  concept of .Net Remoting. 

38. Explain the purpose of Dispose method.

Dispose method is used to destroy  the objects from the memory. 

39. Explain the purpose of tracing levels in System.Diagnostics.TraceSwitcher.

Five levels range from none to  Verbose, allowing fine-tuning the tracing activities. 

40. Explain the role of the DataReader class in ADO.NET connections.

DataReader class returns a  read-only dataset from the data source when the command is executed. 

41. Explain the use of static members with example using C#.NET.

Static members are not associated with a particular instance of any class. 
They need to be qualified with the class name to be called. 
Since they are not associated with object instances, they do not have access to non-static members.
i.e.: "this" cannot be used, which represents the current object instance.

42. Explain the use of virtual, sealed, override, and abstract.

The virtual keyword enables a class to be overridden. If it has to be prevented from being overridden, then the sealed keyword needs to be used. If the keyword virtual is not used, members of the class can even then be overridden. However, its usage is advised for making the code meaningful.

The override keyword is used to override the virtual method in the base class. Abstract keyword is used to modify a class, method or property declaration. You cannot instantiate an abstract class or make calls to an abstract method directly.

An abstract virtual method means that the definition of the method needs to be given in the derived class.

43. Explain with code sample how to Implement a Web Service in .NET

Following is a VBScript example

"WebMethod()" converts the functions in your application into web services

Example:

<%@ WebService Language="VBScript" Class="KmToMConvert" %>

Imports System
Imports System.Web.Services

Public Class KmToMConvert :Inherits WebService
<WebMethod()> Public Function KilometerToMeter(ByVal Kilometer As String) As String 
return (Kilometer * 1000)
end function
end class

44. Give a Character Type Example ?

Consider an example in which we declare one variable of type char, initialize it with value 'a', then 'b', then 'A' and print the Unicode values of these letters to the console:

// Declare a variable

char ch = 'a'; 

// Print the results on the console 

Console.WriteLine( "The code of '" + ch + "' is: " + (int)ch); ch = 'b';

Console.WriteLine( "The code of '" + ch + "' is: " + (int)ch); ch = 'A'; 

Console.WriteLine( "The code of '" + ch + "' is: " + (int)ch);

// Console output: 

// The code of 'a' is: 97 

// The code of 'b' is: 98 

// The code of 'A' is: 65

45. Give a Nested "if" Statements example ?

Here is an example of using nested if structures:
int first = 5;
int second = 3;
if (first == second)
{
Console.WriteLine("These two numbers are equal.");
}
else
{
if (first > second)
{
Console.WriteLine("The first number is greater.");
}
else
{
Console.WriteLine("The second number is greater.");
}
}
In the example above we have two numbers and compare them in two steps: first we compare whether they are equal and if not, we compare again, to determine which one is the greater. Here is the result of the execution of the code above:
The first number is greater.

46. Give an Arithmetical Operators ? Example?

Here are some examples of arithmetic operators and their effect:
int squarePerimeter = 17;
double squareSide = squarePerimeter / 4.0;
double squareArea = squareSide * squareSide;
Console.WriteLine(squareSide); // 4.25
Console.WriteLine(squareArea); // 18.0625
int a = 5;
int b = 4;
Console.WriteLine(a + b); // 9
Console.WriteLine(a + (b++)); // 9
Console.WriteLine(a + b); // 10
Console.WriteLine(a + (++b)); // 11
Console.WriteLine(a + b); // 11
Console.WriteLine(14 / a); // 2
Console.WriteLine(14 % a); // 4
int one = 1;
int zero = 0;
// Console.WriteLine(one / zero); // DivideByZeroException
double dMinusOne = -1.0;
double dZero = 0.0;
Console.WriteLine(dMinusOne / zero); // -Infinity
Console.WriteLine(one / dZero); // Infinity

47. How can I produce an assembly?

An assembly can produce from a .Net compiler.
For Example, the following C# program:
public class CDemo 
{ 
public CDemo() 
{ 
System.Console.WriteLine( "Hello from CDemo" );
} 
}
Can be compiled into a dll as: 
Csc/t:library cdemo.cs

Now the contents of assembly can be view through opening the ''IL Disassembler'' tool of .Net SDK.

Also compiling source into modules and then using assembly linker (al.exe) for combining them to generate assembly.

48. How can you allow class to be inherited and prevent the method from being over-ridden?

 Declare the class as public and make the methods sealed. 

 The method declaration with a sealed modifier is called as a sealed method. The same method must also include the override modifier. With the use of sealed modifier, a derived class is prevented from futher overriding the method. 

49. How can you overload a method?

Different parameter data types,  different number of parameters, different order of parameters. 

50. How Do Exceptions Work?

If during the normal program execution one of the methods throws an exception, the normal flow of the program is interrupted. In the example above this happens when the StreamReader is initialized. Let’s take a look on the following line:
TextReader reader = new StreamReader("WrongTextFile.txt");
If this line triggers an error, the reader local variable will not be initialized and it will have its default value of null. None of the lines that follow in the method will be executed. The program will be interrupted until the CLR finds a handler that can process the exception.

51. How do I spawn a thread?

We need to create an instance of a System.Threading.Thread object and passing it an instance of a ThreadStart delegate that will be executed on the new thread.

For example: 

class MyDemoThread 
{ 
public MyDemoThread( string initData ) 
{ 
m_data = initData; 
m_thread = new Thread( new ThreadStart(ThreadMain) ); 
m_thread.Start(); 
} // ThreadMain() is executed on the new thread. 
private void ThreadMain() 
{ 
Console.WriteLine( m_data ); 
} 
public void WaitUntilFinished() 
{ 
m_thread.Join(); 
private Thread m_thread; 
private string m_data; 
}
In this case creating an instance of the MyDemoThread class is sufficient to spawn the thread and execute the MyDemoThread.ThreadMain() method: 
MyDemoThread t = new MyDemoThread( "Hello, world." ); 
t.WaitUntilFinished();

52. How do you inherit derived class from a base class in C#.NET? Name the Top .NET class that everything is derived from.

By usingcolon and then the  name of the base class. 

53. How does .NET remoting work?

  •  .NET remoting is a process of sending messages through channels. 
  •  Standard channels in remoting are HTTP and TCP. 
  •  TCP is used for LANs only while HTTP can be used for LANs or WANs (internet). 
  •  Support can provided for many message serialization formats. Examples are SOAP (XML-based) and binary. 
  •  By default, the HTTP channel uses SOAP and the TCP channel uses binary. channela can use any serialization format. 
  •  There are two styles of remote access:

1) SingleCall. Every request from a client is serviced by a new object. The object is thrown away on completion of request.
2) Singleton. Single server object processed all request from clients.

54. How does assembly versioning work?

  •  There is an assembly's version called the compatibility version. 
  •  Version number is defined by four numeric parts (e.g. 5.5.3.11). 
  •  Both the name and the version of the referenced assembly are included in each reference to an assembly. 
  •  The two parts of assembly is normally seen as incompatible, but if third part is different than assemblies are deemed as 'may be compatible', and if the only fourth part of an assembly is different than assembly is compatible. 
  •  We can specify version policy in the application configuration file. 
  •  We cannot apply versioning to private assemblies; it is applied only to shared  assemblies.

55. How does C# differ from C++?

  •  C# doesn't support multiple inheritances while C++ does. 
  •  We can use switch statement with string values in C# while in C++ only Character and integer values supported. 
  •  Casting is Safer in C# than C++. 
  •  C# doesn't require semicolon on completion of class definition while C++ use. 
  •  In C#, Command line parameter acts differently as compared to C++.

56. How does C#.NET Generics and C++ Templates compare?

C# generics and templates in C++ are more or less similar syntactically.

  •  C# Generic types are strong typed. C++ Templates are loosely typed. 
  •  C# Generic types are instantiated at the runtime. C++ templates are instantiated at the compile time. 
  •  C# Generic types do not permit the type parameters to have default values. C++  templates do.

57. How does object pooling and connection pooling differ?

In Object pooling, you can control the number of connections.

In connection pooling, you can control the maximum number reached.

When using connection pooling, if there is nothing in the pool, a connection is created since the creation is on the same thread.

In object pooling, the pool decides the creation of an object depending on whether the maximum is reached which in case if it is, the next available object is returned. However, this could increase the time complexity if the object is heavy. 

58. How Does the "switch-case" Statement Work?

The structure switch-case chooses which part of the programming code to execute based on the calculated value of a certain expression (most often of integer type). The format of the structure for choosing an option is as follows:
switch (integer_selector)
{
case integer_value_1:
statements;
break;
case integer_value_2:
statements;
break;
// …
default:
statements;
break;
}
The selector is an expression returning a resulting value that can be compared, like a number or string. The switch operator compares the result of the selector to every value listed in the case labels in the body of the switch structure. If a match is found in a case label, the corresponding structure is executed (simple or complex). If no match is found, the default statement is executed (when such exists). The value of the selector must be calculated before comparing it to the values inside the switch structure. The labels should not have repeating values, they must be unique.
As it can be seen from the definition above, every case ends with the operator break, which ends the body of the switch structure. The C# compiler requires the word break at the end of each case-section containing code. If no code is found after a case-statement, the break can be omittedand the execution passes to the next case-statement and continues until it finds a break operator. After the default structure break is obligatory.
It is not necessary for the default clause to be last, but it’s recommended to put it at the end, and not in the middle of the switch structure.

59. How does the XmlSerializer work? What ACL permissions does a process using it require?

The XmlSerializer constructor generates a pair of classes derived from XmlSerializationReader and XmlSerializationWriter by analysis of the classes using reflection. 

Temporary C# files are created and compiled into a temporary assembly and then loaded into a process.

The XmlSerializer caches the temporary assemblies on a per-type basis as the code generated like this is expensive. This cached assembly is used after a class is created

Therefore the XmlSerialize requires full permissions on the temporary directory which is a user profile temp directory for windows applications.

60. How is method overriding different from method overloading?

When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same name within the class.

61. How is the DLL Hell problem solved in .NET?

DLL Hell problem is solved in .NET  with the introduction of Assembly versioning. It allows the application to  specify not only the library it needs to run, but also the version of the  assembly. 

62. How to achieve polymorphism in C#.NET?

Polymorphism is when a class can be used as more than one type through inheritance. It can be used as its own type, any base types, or any interface type if it implements interfaces.

It can be achieved in the following ways:
Derived class inherits from a base class and it gains all the methods, fields, properties and events of the base class.

To completely take over a class member from a base class, the base class has to declare that member as virtual.

63. How to add a ReadOnly property in C#.NET?

Properties can be made read-only by having only a get accessor in the implementation.

public class X
{
public X(int id)
{
x_id = id;
}
public int ID
{
get
{
return x_id;
}
}
} 

64. How to allow class to be inherited, but prevent the method from being over-ridden?

You can do so by declaring the class public and making the method sealed.

65. How to prevent a class from being inherited in C#.NET?

The sealed modifier is used to prevent derivation from a class. An error occurs if a sealed class is specified as the base class of another class. A sealed class cannot also be an abstract class.

66. How to prevent your class from being inherited?.

You can use keyword 'sealed' in the  class definition to prevent class from being inherited. 

67. Is is possible to force garbage collector to run?

Yes, we can force garbage collector  to run using System.GC.Collect(). 

68. Is it possible to inherit multiple interfaces in C#.NET?

Yes 

69. It is a bad idea to throw your own exceptions. comment

Throwing your own exceptions means  there is some design problem in the program. So, instead write proper code that  can handle the error. 

70. List down difference betweenoverriding and overloading.

When overriding, you change the method behavior for a derived class.
Overloading simply involves  having a method with the same name within the class.

71. Method overriding vs. overloading

Overloading means having a method  with the same name within the class
Through overriding, you change the method behavior for a derived class. 

72. Name the class from where everything is derived in .NET

System.Object.Theobject class is the ultimate base class of all classes in the .NET Framework; it is the root of the type hierarchy.It is often used as a generic argument in class methods - all classes are treatable as Object classes. 

73. Name the namespace used to create a localized application.

System.Globalization
System.Resources 

The classes contained in the System.Globalization namespace are useful for writing globalized (internationalized) applications. It contains classes that define culture-related information such as language, the country/region, the calendars in use, the format patterns for dates, currency, and numbers, and the sort order for strings.

The System.Resources namespace contains classes and interfaces which allow to create, store, and manage various culture-specific resources used in an application.

74. Net. What are different types of configuration files in .Net framework?

The Machine.Config file, which specifies the settings that are global to a particular machine.

This file is located at the following path:
\WINNT\Microsoft.NET\Framework\[Framework Version]\CONFIG\machine.config

The simplest way to add application-specific settings into an application configuration file is to use an application configuration file. 
The file is an XML file and contains add elements with key and value attributes.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ApplicationTitle" value="Sample Console Application" />
<addkey="ConnectionString"value="Server=localhost;Database=Northwind;Integrated Security= false;UserId=sa;Password=;" />
</appSettings>
</configuration>

<authentication> The authentication section controls the type of authentication used within your Web application Windows, Forms or Passport type of authentication can be defined.

Eg: <authentication mode="Windows" />
<allow> or <deny> tags can be used with authorization to allow or deny access to your web application to certain users or roles,
<authorization> 
<allow roles="Administrators,Users" />
<deny users="*" /> 
</authorization>

75. Out of Windows Authentication and SQL Server authentication, which one is trusted?

Windows Authentication is trusted  because the username and password are checked with the Active Directory

76. Steps for creating CLR Trigger

Follow these steps to create a CLR trigger of DML (after) type to perform an insert action:

  •  Create a .NET class of triggering action 
  •  Make an assembly (.DLL) from that Class 
  •  Enable CLR environment in that database. 
  •  Register the assembly in SQL Server 
  •  Create CLR Trigger using that assembly

77. Suppose that you have two interface named IFirstInterface and ISecondInterface.In both the interface same name method SameMethod() is available .As a developer you have to implement SameMethod() separately . How will you do that give example?

using System;
namespace CareerRideTest
{
public interface IFirstInterface
{
void SameMethod();
}

public interface ISecondInterface
{
void SameMethod();
}
class A : IFirstInterface, ISecondInterface
{
public A()
{
Console.WriteLine("I am in class A constructor ");
}

void IFirstInterface.SameMethod()
{
Console.WriteLine("I am in FirstInterface");
}
void ISecondInterface.SameMethod()
{
Console.WriteLine("I am in SecondInterface");
}
}

class MainClass
{
static void Main(string[] args)
{
IFirstInterface objFirst = new A();
objFirst.SameMethod();

ISecondInterface objSecond = new A();
objSecond.SameMethod();
Console.ReadKey();

}
}
}

Output:
I am in class A constructor
I am in FirstInterface
I am in class A constructor
I am in SecondInterface

Note:You cannot write as A objFirst = new A ();
in above program it will give error:

78. Switch statement works differently than in C++, why?

C# does not support an explicit fall through for case blocks.

The following code is not legal and will not compile in C# :

switch(a)
{
case 0: // some code here
case 1: // some code here
default: // some code here
break;
}

To run above code in C#, the code must be modified as shown below

class Demo
{
public static void Main() 
{
int a = 3;
switch(a)
{
case 0: // do some code here
goto case 1;
case 1: // do some code here
goto default;
default: // do some code here
break;
}
}
}

79. System.String vs. System.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. 

80. Trace the output for the following program.

using System;

namespace CareerRideTest
{

private class Demo
{
public void show()
{
Console.WriteLine("Access Modifiers");
}
}

class MainClass
{

static void Main(string[] args)
{
Demo obj = new Demo();
obj.show();
Console.ReadKey();
}
}
}

Elements defined in a namespace cannot be explicitly declared as private, protected, or protected internal. In a namespace class can be declared as public or internal. By default class access specifier is internal.

81. What are attributes?

  •  Attributes describe a type, method, or property in a way that can be queried using a technique call reflection. 
  •  Attributes specify which security privileges a class requires. 
  •  Attributes provide a description, title, and copyright notice to explain an assembly. 
  •  Attribute types derive from the System. Attribute base class and are declared using <> or [] notation. 
  •  Visual studio automatically creates some standard attributes for your assembly when you create a project including title, description, company, guide and version. 
  •  Attribute can also declare requirements or capabilities.

82. What are circular references? Explain how garbage collection deals with circular references.

A circular reference is a run-around wherein the 2 or more resources are interdependent on each other rendering the entire chain of references to be unusable.

There are quite a few ways of handling the problem of detecting and collecting cyclic references.

1. A system may explicitly forbid reference cycles.
2. Systems at times ignore cycles when they have short lives and a small amount of cyclic garbage. In this case a methodology of avoiding cyclic data structures is applied at the expense of efficiency.
3. Another solution is to periodically use a tracing garbage collector cycles.
Other types of methods to deal with cyclic references are:
-Weighted reference counting
-Indirect reference counting

83. What are Custom Exceptions?

Custom Exceptions are user defined exceptions. 

There are exceptions other than the predefined ones which need to be taken care of. 

For example: The rules for the minimum balance in a Salary A/C would be different from that in a Savings A/C due to which these things need to be taken care of during the implementation.

84. What are delegates and why are they required?

The delegates in .NET are like the pointers to the functions in C/C++. The difference is that these are type safe unlike the once in C/C++.

There are situations where in a programmer or an application needs to perform an action on a particular event. Eg: Some user action like click, text change, etc. So when these actions are performed by the user, the delegates invoke the respective functions. 

85. What are Extender provider components? Explain how to use an extender provider in the project.

An extender provider is a component that provides properties to other components.

Implementing an extender provider:

  •  Use the ProvidePropertyAttribute, which specifies the name of the property that an implementer of IExtenderProvider provides to other components, attribute to specify the property provided by your extender provider. 
  •  Implement the provided property. 
  •  Track which controls receive your provided property. 
  •  Implement the IExtenderProvider, which defines the interface for extending  properties to other components in a containe, interface.

86. What are implementation inheritance and interface inheritance?

Implementation inheritance is achieved when a class is derived from another class in such a way that it inherits all its members.

Interface inheritance is when a class inherits only the signatures of the functions from another class.

87. What are namespaces, and how they are used?

  •  In .Net framework namespaces are used to manage classes. 
  •  The Key difference between .Net namespaces and java packages is that namespace doesn't define the physical layout of source file while java packages do. 
  •  Namespace define logical structure of the code. 
  •  Namespaces can be utilized via using keyword, in .net framework, many class have their namespace defined such as System.Net. 
  •  We can create our own C# source files which can relate to multiple projects.

88. What are partial classes?

  •  Derived classes focus more on important portions by splitting a class definition into multiple source files using partial classes. 
  •  In partial class code is hidden in a file named Form.Designer.vb or Form.Designer.cs. 
  •  Partial class files can be viewed by expending all files in solution explorer. 
  •  We can enhance and extend auto-generated code by using partial classes. 
  •  These multiple files get compiled into a single class during compilation.

89. What are the basic concepts of object oriented programming?

It is necessary to understand some of the concepts used extensively in object oriented programming. These include
Objects
Classes
Data abstraction and encapsulation
Inheritance
Polymorphism
Dynamic Binding
Message passing.

90. What are the connections supported in Microsoft SQL Server?

Windows Authentication 
SQL Server authentication 

91. What are the difference between const and readonly?

A const can not be static, while readonly can be static.

A const need to be declared and initialized at declaration only, while a readonly can be initialized at declaration or by the code in the constructor.

A const's value is evaluated at design time, while a readonly's value is evaluated at runtime.

92. What are the difference between Structure and Class?

  •  Structures are Values types while Classes are Reference types. 
  •  In structure values stored in stack while in class value's reference stored in heap. 
  •  In structure direct values is stored while in class reference to a value is stored. 
  •  Inheritance is supported in classes while structure doesn't support. 
  •  We cannot declare destructor in structure whereas in class it is possible. 
  •  We can't have explicitly parameter less constructors in structure whereas classes can have. 
  •  Class can have protected members while structure can't have. 
  •  Structure is declared by using struct keyword while class is declared by using Class keyword. 
  •  Structures don't have memory management while classes have due to garbage collector. 
  •  New operator works in classes while not in structure.

93. What are the different categories of inheritance?

In C# inheritance may be implemented in different combinations as illustrated in figure and they include:
Inheritance in Object Oriented Programming is of four types:
Single inheritance: Contains one base class and one derived class.
Hierarchical inheritance: Contains one base class and multiple derived classes of the same base class.
Multilevel inheritance: Contains a class derived from a derived class.
Multiple inheritances: Contains several base classes and a derived class.

94. What are the different types of statements supported in C#?

C# supports several different kinds of statements are
Block statements, Declaration statements, Expression statements, Selection statements, Iteration statements, Jump statements, Try catch statements, Checked and unchecked
Lock statement.

95. What are the features of C#?

  •  C# is a powerful and simple programming language for writing applications. 
  •  Developers can easily build the web services through any language, on any platform across the internet. 
  •  C# is a hybrid of C++ and VB. 
  •  C# has many C++ features in the area expressions, operators and statements. 
  •  C# introduces improvement in boxing, unboxing, type safety, events, and versioning and garbage collections. 
  •  It reduces programming error in the code due to fewer lines of code. 
  •  C# has a key feature that can split up the implementation into logical pieces called region. 
  •  It support multiline comment feature.

96. What are the File System Classes?

  •  The file system classes are separated into two types of classes: information and utility. 
  •  Information classes derive from the FileSystemInfo base class. 
  •  Information Classes exposes all the system information about file system objects like files, directories and drives and named as FileInfo and DirectoryInfo classes. 
  •  DriveInfo class cannot derive from the FileSystemInfo class; it is an information class which represents a drive in the file system. 
  •  The utility classes have static methods to perform function on file system objects such as file system paths and Directories. 
  •  System.IO namespace contains collection of classes for files, drives and  directories.

97. What are the namespaces used in C#.NET?

Namespace is a logical grouping of class.

Using System;

Using System.Collections.Generic;

Using System.Windows.Forms;

98. What are the types of comment in C#?

There are 3 types of comments in C#.
Single line (//)
Multi (/* */)
Page/XML Comments (///).

99. What are the ways to deploy an assembly?

MSI installer
CAB archive
XCOPY command 

100. What are three test cases you should go through in unit testing?

Positive test cases (correct data,  correct output), negative test cases (broken or missing data, proper handling),  exception test cases (exceptions are thrown and caught properly). 

101. What are value types and reference types?

Value types are stored in the Stack.
Examples : bool, byte, chat, decimal, double, enum , float, int, long, sbyte, short, strut, uint, ulong, ushort.
Reference types are stored in the Heap.
Examples : class, delegate, interface, object, string.

102. What benefit do you get from using a Primary Interop Assembly (PIA)?

A primary interop assembly contains type definitions (as metadata) of types implemented with COM.

Only a single PIA can exist, which needs to be signed with a strong name by the publisher of the COM type library.

One PIA can wrap multiple versions of the same type library. 

A COM type library imported as an assembly can be a PIA only if it has been signed and published by the same publisher.

Therefore, only the publisher of a type library can produce a true PIA, that can be considered as the unit of an official type definition for interoperating with the underlying COM types.

103. What Is a "Loop"?

In programming often requires repeated execution of a sequence of operations. A loop is a basic programming construct that allows repeated execution of a fragment of source code. Depending on the type of the loop, the code in it is repeated a fixed number of times or repeats until a given condition is true (exists).
Loops that never end are called infinite loops. Using an infinite loop is rarely needed except in cases where somewhere in the body of the loop a break operator is used to terminate its execution prematurely. We will cover this later but now let’s look how to create a loop in the C# language.

104. What Is a "Method"?

A method is a basic part of a program. It can solve a certain problem, eventually take parameters and return a result.
A method represents all data conversion a program does, to resolve a particular task. Methods consist of the program’s logic. Moreover they are the place where the “real job” is done. That is why methods can be taken as a base unit for the whole program. This on the other hand, gives us the opportunity, by using a simple block, to build bigger programs, which resolve more complex and sophisticated problems. Below is a simple example of a method that calculates rectangle’s area:

static double GetRectangleArea(double width, double height)
{
double area = width * height;
return area;
}

105. What is a basic difference between the while loop and do while loop in C#?

The while loop tests its condition at the beginning, which means that the enclosed set of statements run for zero or more number of times if the condition evaluates to true. The do while loop iterates a set of statements at least once and then checks the condition at the end.

106. What Is a Class?

The class defines abstract characteristics of objects. It provides a structure for objects or a pattern which we use to describe the nature of something (some object). Classes are building blocks of OOP and are inseparably related to the objects. Furthermore, each object is an instance of exactly one specific class.
We are going to give as an example a class and an object, which is its instance. We have a class Dog and an object Lassie, which is an instance of the class Dog (we say it is an object of type Dog). The class Dog describes the characteristics of all dogs whereas Lassie is a certain dog.
Classes provide modularity in object-oriented programs. Their characteristics have to be meaningful in a common context so that they could be understood by people who are familiar with the problem area and are not programmers. For instance, the class Dog cannot have (or at least should not) a characteristic "RAM" because in the context of this class such characteristic has no meaning.

107. What is a Constructor?

It is the first method that are  called on instantiation of a type. It provides way to set default values for  data before the object is available for use. Performs other necessary functions  before the object is available for use. 

108. What is a Destructor?

It is called just before an object is destroyed. It can be used to run clean-up code.You can't control when a destructor is called since object clean up by common language runtime.

109. What Is an "Array"?

Arrays are vital for most programming languages. They are collections of variables, which we call elements.

An array’s elements in C# are numbered with 0, 1, 2, … N-1. Those numbers are called indices. The total number of elements in a given array we call length of an array.
All elements of a given array are of the same type, no matter whether they are primitive or reference types. This allows us to represent a group of similar elements as an ordered sequence and work on them as a whole.
Arrays can be in different dimensions, but the most used are the one-dimensional and the two-dimensional arrays. One-dimensional arrays are also called vectors and two-dimensional are also known as matrices.

110. What is an abstract base class?

An abstract class is a class that is designed to be specifically used as a base class. An abstract class contains at least one pure virtual function.

111. What is an abstract class?

  •  We can't create the instance of an abstract class, because abstract classes are incomplete. 
  •  Abstract modifier doesn't supported by interface, Values type and static types. 
  •  We can declare class as abstract by using abstract keyword in beggining of the class definition. 
  •  Abstract class provides similar definition of base class which can be shared by multiple derived classes. 
  •  Abstract class may define abstract methods by using the abstract keyword before the method definition. 
  •  Abstract methods have no implementation, only they can be implemented in the  derived class.
  For Example:
  public abstract class Demo
  {
  public abstract void DoWork(int a);
  }

112. What is an application domain?

  •  An AppDomain is a lightweight activity. 
  •  Goal of Appdomain is to isolate application from each other which is useful in hosting like Asp.net Application. 
  •  The host can destroy the Appdomain without loosing others in the process. 
  •  .Net runtime managed AppDomain memory to ensure that they don't access other's memory. 
  •  AppDomain is useful in creation and destruction of types on the fly. 
  •  AppDomain Created automatically on creation of new application by CLRHost. 

113. What is an Event?

When an action is performed, this  action is noticed by the computer application based on which the output is  displayed. These actions are called events. Examples of events are pressing of  the keys on the keyboard, clicking of the mouse. Likewise, there are a number  of events which capture your actions. 

114. What is an Exception in .NET?

Exceptions are errors that occur during the runtime of a program. 
The advantage of using exceptions is that the program doesn't terminate due to the occurrence of the exception.
Whenever an exception is occurred the .NET runtime throws an object of specified type of Exception. 
The class 'Exception' is the base class of all the exceptions.

115. What Is an Exception?

When we write a program, we describe step-by-step what the computer must do (at least in imperative programming; in the functional programming things look a bit different) and in most of the cases we rely that the program will execute normally. Indeed, most of the time, programs are following this normal pattern, but there are some exceptions. Let’s say we want to read a file and display its contents on the screen. Let’s assume the file is located on a remote server and during the process of reading it, the connection goes down. The file then will be only partially loaded. The program will not be able to execute normally and show file’s contents on the screen. In this case, we have an exception from the normal (and correct) program execution and this exception must be reported to the user and/or the administrator.

116. What is an interface class?

 An interface class is an abstract class with public abstract methods. You can inherit the class and have the methods over-ridden. 

117. What is an internal modifier?

  •  Internal members can access only from within the same assembly (.dll). 
  •  We can declare a class as internal, its member as internal or its fields as internal. 
  •  Use internal keyword before the class declaration to create an internal class. 
  •  Internal type can't access from external program. 
  •  Classes defined within the current assembly can access internal classes.

118. What is an object pool in .NET?

An object pool is a container of objects that holds a list of other objects that are ready to be used.

It keeps track of:

  •  Objects that are currently in use 
  •  The number of objects the pool holds 
  •  Whether this number should be increased

The request for the creation of an object is served by allocating an object from the pool. 

This reduces the overhead of creating and re-creating objects each time an object creation is required. 

119. What Is an Object?

We are going to introduce the concept object in the context of OOP. Software objects model real world objects or abstract concepts (which are also regarded as objects).
Examples of real-world objects are people, cars, goods, purchases, etc. abstract objects are concepts in an object area, which we have to model and use in a computer program. Examples of abstract objects are the data structures stack, queue, list and tree. They are not going to be a subject in this chapter, but we are going to see them in details in the next chapters.
In objects from the real world (as well as in the abstract objects) we can distinguish the following two groups of their characteristics:
- States – these are the characteristics of the object which define it in a way and describe it in general or in a specific moment
- Behavior – these are the specific distinctive actions, which can be done by the object.
Let’s take for example an object from the real world – "dog". The states of the dog can be "name", "fur color" and "breed", and its behavior – "barking", "sitting" and "walking".
Objects in OOP combine data and the means for their processing in one. They correspond to objects in real world and contain data and actions:
- Data members – embedded in objects variables, which describe their states.
- Methods – we have already considered them in details. They are a tool for building the objects.

120. What Is an Operator?and types of operator in C#?

Operators allow processing of primitive data types and objects. They take as an input one or more operands and return some value as a result. Operators in C# are special characters (such as "+", ".", "^", etc.) and they perform transformations on one, two or three operands. Examples of operators in C# are the signs for adding, subtracting, multiplication and division from math (+, -, *, /) and the operations they perform on the integers and the real numbers.

Operators in C#

Operators in C# can be separated in several different categories:
- Arithmetic operators – they are used to perform simple mathematical operations.

- Assignment operators – allow assigning values to variables.
- Comparison operators – allow comparison of two literals and/or variables.
- Logical operators – operators that work with Boolean data types and Boolean expressions.
- Binary operators – used to perform operations on the binary representation of numerical data.
- Type conversion operators – allow conversion of data from one type to another.

121. What is Assembly manifest?

The manifest of an assembly contains assembly's data like version, scope,  security information (strong name),etc. 
It also contains a reference to the resource and classes. 
It is stored in either an .exe or a .dll with Microsoft intermediate language (MSIL) code. 

122. What is boxing?

  •  When Value type is explicitly converted into reference type is called as boxing. 
  •  The reverse process is known as unboxing, when reference type is explicitly converted into value type. 
  •  In boxing process, the Values of variable is stored in Stack is converted in an object reference is stored in heap. 
  •  If the recipient reference type is equivalent to the unboxed type, then the value is copied to the heap. 
  •  Unboxing called the vice versa process of boxing.

123. What is C#.NET Generics?

The classes and the methods can treat the values of different types uniformly with the use if generics.

The usage of generics is advantageous as:

  •  They facilitate type safety 
  •  They facilitate improved performance 
  •  They facilitate reduced code 
  •  They promote the usage of parameterized types 
  •  The CLR compiles and stores information related to the generic types when they  are instantiated. (The generic type instance refers to the location in memory  of the reference type to which it is bound for all the instances of the generic  type.)

124. What is C#?

C# (pronounced "C sharp") is a simple, modern, object-oriented, and type-safe programming language used with XML-based Web services on the .NET platform and designed for improving productivity in the development of Web applications. It will immediately be familiar to C and C++ programmers. C# combines the high productivity of Rapid Application Development (RAD) languages.

125. What is Custom Control?

  •  A Custom control inherits from System.Windows.Controls.Control class. 
  •  They are compiled code (Dlls), faster to use, difficult to develop, and can be placed in toolbox. 
  •  Custom controls can be derived from different custom controls according to requirement. 
  •  Custom controls can be reused on multiple places easily. 
  •  Provide more flexibility in extending the control's behavior. 
  •  Custom controls are loosely coupled control in respect to code an UI. 
  •  Custom controls can be used just by drag and drop into the form. 
  •  Custom controls have dynamic layout.

126. What is Delegates?

Delegates are a type-safe, object-oriented implementation of function pointers and are used in many situations where a component needs to call back to the component that is using it.

127. What is difference between Class And Interface?

Class 

is logical representation of object. It is collection of data and related sub procedures with defination.

Interface : 

is also a class containg methods which is not having any definations.Class does not support multiple inheritance. But interface can support.

128. What is difference between constants, readonly and, static ?

Constants: The value can’t be changed.
Read-only: The value will be initialized only once from the constructor of the class.
Static: Value can be initialized once.

129. What is encapsulation?

The wrapping up of data and functions into a single unit (called class) is known as encapsulation. Encapsulation containing and hiding information about an object, such as internal data structures and code.

130. What is GAC (global assembly cache)?

GAC, global assembly cache is an area of memory reserved to store the assemblies  of all .NET applications that are running on a certain machine. 

 It shares assemblies among multiple .NET applications. The assemblies must have a strong name and must be publicly shared to be installed in the GAC. 

131. What is Jagged Arrays?

A jagged array is an array whose elements are arrays.
The elements of a jagged array can be of different dimensions and sizes.
A jagged array is sometimes called an array–of–arrays.

132. What is Managed code?

  •  Manage Code are the codes which require common language runtime for its execution. 
  •  Managed code target the services of the common language runtime in .Net framework. 
  •  Managed code must provide the metadata necessary for the runtime to provide services like memory management, cross-language integration, code access security, and automatic lifetime control of objects. 
  •  Managed code provides services like cross-language integration, code access security, memory management and automatic lifetime control of objects by supplying necessary metadata for runtime. 
  •  Codes executed by Microsoft intermediate language are Managed code.

133. What is serialization?

Serialization is the process of converting an object into a stream of bytes.
De-serialization is the opposite process of creating an object from a stream of bytes.
Serialization / De-serialization is mostly used to transport objects.

134. What is shadowing?

There are two ways of shadowing either through scope or through inheritance. 

  •  Hiding a method of child class and giving a new implementation is known as shadowing from inheritance. 
  •  Shadowing through inheritance is the default when a derived class implements a method of base case which is not declared as overridden in the base class. 
  •  Derived class member's signature, return type, access level may differ from base class. 
  •  Shadowing can be obtained by using the new keyword. 
  •  Shadowing is one of the polymorphism's concepts.

135. What Is the Console?

The Console is a window of the operating system through which users can interact with system programs of the operating system or with other console applications. The interaction consists of text input from the standard input (usually keyboard) or text display on the standard output (usually on the computer screen). These actions are also known as input-output operations. The text written on the console brings some information and is a sequence of characters sent by one or more programs.
For each console application the operating system connects input and output devices. By default these are the keyboard and the screen but they can be redirected to a file or other devices.

136. What is the difference between an abstract method & virtual method?

An Abstract method does not provide an implementation and forces overriding to the deriving class (unless the deriving class also an abstract class), where as the virtual method has an implementation and leaves an option to override it in the deriving class. Thus Virtual method has an implementation & provides the derived class with the option of overriding it. Abstract method does not provide an implementation & forces the derived class to override the method.

137. What is the difference between an event and a delegate?

  •  Events are the reason of happening and delegates are the address of function. 
  •  In .Net, Delegates looks like an interface with a single method and you can make a call to it by delegate's instance. 
  •  By event's you can let other people know that something going on. 
  •  Events is declared by using ''event'' keyword whereas delegate is declared by  using ''delegate'' keyword as below
  Public event <nameofth handler>;
  Public delegates <type> <delegatename>; 
  •  Adding a public multicast delegate field is same as adding a public event to a  class.

138. What is the difference between class and an Interface?

Abstract classes can have implementations for some of its members, but the interface can't have implementation for any of its members.

Interfaces cannot have fields where as an abstract class can have fields.

An interface can inherit from another interface only and cannot inherit from an abstract class, where as an abstract class can inherit from another abstract class or another interface.

A class can inherit from multiple interfaces at the same time, where as a class cannot inherit from multiple classes at the same time.

Abstract class members can have access modifiers where as interface members cannot have access modifiers.

139. What is the difference between compile time polymorphism and run time polymorphism?

Compile time PolymorphismRun time Polymorphism

Run time Polymorphism also known as method overriding.

Method overriding means having two or more methods with the same name , same signature but with different implementation.

140. What is the difference between const and readonly in C#.NET?

The read only can be modified by the class it is contained in. However, the const cannot be modified. It needs to be instantiated only at the compile time.

141. What is the difference between Custom Control and User Control?

Custom Controls are compiled code (Dlls), easier to use, difficult to create, and can be placed in toolbox. Drag and Drop controls. Attributes can be set visually at design time. Can be used by Multiple Applications (If Shared Dlls), Even if Private can copy to bin directory of web application add reference and use. Normally designed to provide common functionality independent of consuming Application.
User Controls are similar to those of ASP include files, easy to create, can not be placed in the toolbox and dragged - dropped from it. A User Control is shared among the single application files.

142. What is the difference between Debug.Write and Trace.Write? When should each be used?

Debug.Write: Debug Mode, Release Mode (used while debuging a project)
Trace.write: Release Mode (used in Released verion of Applications)

143. What is the difference between Finalize() and Dispose()?

Dispose() is called by as an indication for an object to release any unmanaged resources it has held. 
Finalize() is used for the same purpose as dispose however finalize doesn't assure the garbage collection of an object. 
Dispose() operates determinalistically due to which it is generally preferred.

144. What is the difference between private and public keyword?

Private :

The private keyword is the default access level and most restrictive among all other access levels. It gives least permission to a type or type member. A private member is accessible only within the body of the class in which it is declared.

Public :

The public keyword is most liberal among all access levels, with no restrictions to access what so ever. A public member is accessible not only from within, but also from outside, and gives free access to any member declared within the body or outside the body.

145. What is the difference between public, static and void?

public :The keyword public is an access modifier that tells the C# compiler that the Main method is accessible by anyone.
static :The keyword static declares that the Main method is a global one and can be called without creating an instance of the class. The compiler stores the address of the method as the entry point and uses this information to begin execution before any objects are created.
void : The keyword void is a type modifier that states that the Main method does not return any value.

146. What is the difference between string keyword and System.String class?

String keyword is an alias for Syste.String class. Therefore, System.String and string keyword are the same, and you can use whichever naming convention you prefer. The String class provides many methods for safely creating, manipulating, and comparing strings.

147. What is the role of data provider?

The .NET data provider layer resides between the application and the database. Its task is to take care of all their interactions. 

The .NET Data provider can be demonstrated to be: 

SQL Server data provider 
OLEDB data provider 
ODBC Data Provider 

ADO.NET supports the following OLE DB Providers:

- SQLOLEDB - Microsoft OLE DB Provider for SQL Server.
- MSDAORA - Microsoft OLE DB Provider for Oracle.
- Microsoft.Jet.OLEDB.4.0 - OLE DB Provider for Microsoft Jet. 

148. What is the syntax to inherit from a class in C#?

When a class is derived from another class, then the members of the base class become the members of the derived class.

The access modifier used while accessing members of the base class specifies the access status of the base class members inside the derived class.

The syntax to inherit a class from another class In C# is as follows:

class MyNewClass : MyBaseClass

149. What is the use of enumerated data type?

An enumerated data type is another user defined type which provides a way for attaching names to numbers thereby increasing comprehensibility of the code. The enum keyword automatically enumerates a list of words by assigning them values 0,1,2, and so on.

150. What is the use of GetCommandLineArgs() method in C#.NET?

With GetCommandLineArgs() method, the command line arguments can be accessed. 
The value returned is an array of strings.

151. What is the use of System.Environment class in C#.NET?

The System.Environment class can be used to retrieve information like:
command-line arguments
the exit code
environment variable settings
contents of the call stack
time since last system boot
the version of the common language runtime

152. What is Un-Managed Code?

  •  Code which is perfectly executed by operating system is known as un-managed code. 
  •  C, C++, VB 6.0 are examples of unmanaged code. 
  •  Un-managed code all the time dependent on computer architecture. 
  •  Un-managed code always compile to native code, so require compilation of code for different platform again and again. 
  •  Developers should take care of type safety, security, memory allocations.

153. What is User Control?

  •  A User control inherits from System.Windows.Controls.UserControls class. 
  •  User control defines UI as XMAL. 
  •  User control has fixed UI and can't have different look in every project. 
  •  They are tightly coupled controls. 
  •  We can't add them to the toolbox. 
  •  They are less flexible as compared to Custom controls.

154. When dowe declare a class as abstract in C#.NET?

When at least one of the methods in  the class is abstract. 

155. Why are strings in C# immutable?

  •  When string values changes it means string is immutable, in this whenever we assign new value to string it occupies new memory reference for its new value by creating new string instance. 
  •  String is declared by using String Keyword. 
  •  Always use mutable string defined in System.Text.StringBuilder whenever its values will change. 
  •  Inefficient use of memory and garbage collection resulted by Immutable string.

156. Why is an Object Pool required?

The request for the creation of an object is served by allocating an object from the pool.

This reduces the overhead of creating and re-creating objects each time an object creation is required. 

157. Why Trim function is used in C#?

The Trim function is used to remove white spaces from the end and start of the instance.

Trim provide following methods as:

1) Trim(): This method of Trim is used to remove both off spaces from start and the end.
2) TrimStart(): This method of Trim is used to remove white spaces from the start of String.
3) TrimEnd(): This method of Trim is used to remove white spaces from the end of the string.