Home

Hi All.

I am still under the process of covering all the topics. Keep coming back as there will be lots of new ques added everyday which will help you guys in your job interviews.

I have also added real time scenarios that i have experienced while implementing each concepts. So every topic contains the interview ques and also real time problems that can occur.

Also you guys can send me any ques that can be added to the list.Hope it helps everyone to prepare for interview and also get to know about the language.

Good Luck !!!

MISC

Retrieve the image content from database

When the data from image field is extracted from database it is in form of byte array.Below is the code to convert an object to a byte array-

byte[] data= (byte[])ds.Tables[0].Rows[0][0];



Check if user has clicked a check box in a datagrid

foreach (DataGridViewRow row in dataGridView1.Rows)

{

if (row.Cells[0].Value != null &&

Convert.ToBoolean(row.Cells[0].Value) == true)

{

//the user has clicked the check box..retrieve the values accordingly

} }


Restore databse from a .bak file
Execute the following command .Specify the path where .bak file is located.

RESTORE DATABASE Test

FROM DISK = <File Location>

WITH REPLACE, MOVE '<MDFFileName>' TO 'c:\Program Files\Microsoft SQL Server\CADS.MDF',

MOVE '<LDFFileName>' TO 'c:\Program Files\Microsoft SQL Server\\CADS_Log.LDF'


The <MDFFileName> and <LDFFileName> file names can be obtained by executing the follwoing query


RESTORE FILELISTONLY

FROM DISK = <File Location>

GO

Sometimes you will see an error stating no access.some other process is using the database..Execute the below command that time

Alter Database System

  SET SINGLE_USER With ROLLBACK IMMEDIATE  


 Restore database using .ldf amd .mdf files

sp_attach_db 'Database_Name','c:\backupDB.mdf','C:\backupLogs.ldf'

Windows Service

How to find out if a service present in different machine has been stopped or started
 
Use ServiceController Class present in System.ServiceProcess namespace to determine the status of the service. Have a timer in the application which is monitoring the service. The timer should poll service to determine its status.

 
ServiceController c = new ServiceController("<servicename>", "<machine name>");


Does windows service pick up any changes made to app.config when its running ?

No. The service needs to be  restarted to pick up any new changes made to the config file.

Debug a windows service 

 Below are the three methods


1.Create a new test class. Then call the functions from test class.

2.Add a line    System.Diagnostics.Debugger.Break();  wherever you want to debug.At runtime a new instance will be created and debugging can be carried out in separate windows.


3.Please refer 
 http://aspalliance.com/1316_Working_with_Windows_Service_Using_Visual_Studio_2005.6


How to install a windows service

Go to visual studio command prompt. Navigate to path where the exe that you want to install is present.

To install, type
installutil  projectname.exe

To uninstall, type
installutil /u projectname.exe

 

WebService

Calling Webservice Asyncronously in windows application

Calling webservice async in Windows Application
1.Create a web service.
2.Add web reference to your windows app. In order to do this Click add service reference -> advanced setting>add web reference.
This is needed bc Async methods will not be generated if you add a normal web reference.
The remaining can be done by below article


Web Service Completed Events Firing Twice

For this initialize your webservice object to null in beginning. And later when you use its method instantiate it.
eg-
Webservice
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string SendData()
{
  return "Data Sent";
}
} 

WebMethod referred in  windows app

public class TestClass
{

<ServiceNameGiven>. Service1 objService=null; //intialize it to null intially
 public void TestMethod()
{
//now instantiate it.
 <ServiceNameGiven>. Service1 objService=new <ServiceNameGiven>. Service1();
}
} 

Timeout issue in webservice 

Error message-
 

The request channel timed out while waiting for a reply after 00:00:02.1500000. Increase the timeout value passed to the call to Request or increase the SendTimeout value on the Binding. The time allotted to this operation may have been a portion of a longer timeout



This issue is caused because of some operation that takes longer time than that configured in your webservice and your client setting . to fix this –make the following setting

1.In your webservice add the following settings-

The setting is in web.config file
 
<configuration>
 <system.web>
    <httpRuntime maxRequestLength="8096"
        useFullyQualifiedRedirectUrl="true"
        executionTimeout="1800"/> //set for 30 min
  </system.web>
</configuration>

2.On your client side(the application that is consuming the webservice)
Change the sendTimeout = "00:30:00" //desired time you want.
This wil be in app.config file
Returning value from a asyn webservice

Below is the webservice example-
Webservice
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string SendData()
{
  return "Data Sent";
}
}

Calling app--windows app
1.Add webreference to the given service.
2. intialialize the webservice object in the onload

<AddedwebServiceName>.Service1 obj= new <AddedwebServiceName>.Service1()

Create a event handler for the completed function exposed by webmethod
<AddedwebServiceName>.SendDataCompleted += EventHandler

3.Call the asyn function in any event like button click
<AddedwebServiceName>.SendDataAsync

4.Add the functions which will be invoked when a function is completed

  public void EventHandler(object sender, localhost.SendDataCompletedEventArgs e)
{
 //this will give you the result.since webmethod returns a string this functions will give string value.
string result =e.result

}

Steps to take care when changing the default class name of webservice

1. suppose your newly added webservice generated the below class for you


public class Service1 : System.Web.Services.WebService
{
}


change the class name to desired class name eg-

public class MyWebservice: System.Web.Services.WebService
{
}

2. Search for "Codebehind in your solution. it openes up Service1.asmx with below line
"<%@ WebService Language="C#" CodeBehind="service1.asmx.cs" Class="<namespace>.service1" %>"

Change the Class in the above tag to <Namespace>.Mywebservice(or as desired)




The test form is only available for requests from the local machine 

If you want to test your simple webservice by clicking on "Invoke" button  it should be enabled for remote access.
The invoke button wont be available if your webservice is accessed remotely however it will be available locally.
To enable this setting add foll to your config file-

<configuration>
    <system.web>
    <webServices>
        <protocols>
            <add name="HttpGet"/>
            <add name="HttpPost"/>
        </protocols>
    </webServices>
    </system.web>
</configuration>



Method overloading in webservice

Remember webservice cannot have two webservice with same name and same parameters(this cannot be don’t anyhow).

 However method overloading is possible.The methods that are being overloaded should have an external name given by “MessageName”

[WebMethod( MessageName = "AddInt")]
Public void Add(int a,int b)()
{
}

[WebMethod( MessageName = "AddFloat")]
Public void Add(float a,float b)()
{
}

This solution will work in older version of dot net. But in .Net 2.0 it will give an error saying the webservice does not confirm to (WS-I) Baisc Profile 1.1..

To solve this set 

[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

At the beginning of the code to

[WebServiceBinding(ConformsTo = WsiProfiles.None)] 


How do you call a same webservice when its hosted in multiple server dynamically at runtime

When a webservice is added to the client WSDL is generated. This WSDL will have a URL of the webservice. So the added webreference is associated with a single URL.

Now if the same webservice present in some other server needs to be called then this URL needs to be changed. This can be done dynamically at run time.
Before calling the webservice change the URL to the URL where the calling webservice will be located.
eg-
string path = "http://" + IpAddress + WebServiceURlPath;
 <WebserviceObject>.Url = path;


Windows Authentication in WebService
In order to achieve this perform the following steps

1.Change the authentication mode to “Windows” in web.config file in the webservice.

<authentication mode="Windows" />

2.Just before calling any webservice methods on the client side set the “Credentials” property of webservice.

Eg-
<webserviceName>.Credentials = new System.Net.NetworkCredential(UserName, Password);

3.Make changes in IIS to enable Windows Authentication.
Navigate to the website where your service is hosted in IIS Manage and disable “Anonymous Authentication “ and enable “Windows Authentication”.


1.What is WebService?
Webservice are functionalities or web APIs exposed over the web.
It can be developed in any language. It is platform independent
Webservice communication takes place via SOAP(Simple Object Access Protocol).So any language capable of communicating via SOAP can consume webservice.
Webservice are used in SOA architecture.

2. What are different components in Webservice ?

ASMX file- This file provides access to the webservice.

DISCO(Discovery of Webservice) files- This are used to locate the webservice. They contain the path where the webservice is located.

WSDL(Webservice Description Language)- these are used to describe the webservice. They give details about the methods exposed by the webservice and the parameters they take.
They can be accessed by appending “?WSDL” to the webservice path.

UDDI(Universal Description, Discovery and Integration)  -It is a repository where different webservice can be located.


SOAP(Simple Object Access Protocol) –Its a XML based protocol which is used be send request and get response back from the webservice.


4.How do you deploy a webservice ?
Webservice are deployed in IIS either manually or through a set up project.

Manual deployment
1.Create a new virtual directory in IIS. Point the path of the virtual directory to a <Sample >folder sotred in the hard disk.

2.The <Sample>folder will contain bin folder,asmx file and web.config of the webserive.

3.The service can now be accessed by typing following in the browser
http://<ip of the machine where service is hosted>/<virtual directory name>/<asmx file name>.asmx
 



XML


What is XML Serialization ?

Xml serialization allows reading and write in the xml using dot net objects.

Adding configuration file in a 3 tier architecture

1.Add a single app.config file in the UI Layer
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>

    <add key="Server1" value="10.250.1.32" />
    <add key=" Server 2" value="10.251.1.54" />
   
   </appSettings>
</configuration>

1.      Add the system.configuration dll refererence to the projetc where you want to access these values
using System.Configuration;
//access values using below code
String ipaddress= ConfigurationSettings.AppSettings.Get("MDT1");

The requested operation requires elevation

Start your  VS2008/2005  by clicking  Run As administrator. It worked for me !!

Accesing multiple database using same connection in sql

suppose you want to connect to database DB1 and DB2 in a join statement where connectionstring is same,it can be done
as follows-

Method1
connectionstring-Data Source=P06-INF-WS-1\SQLEXPRESS;User ID=sa;Password=sa
select * from DB1.dbo.Table1 tb1 join on DB2.dbo.Table2 tb1 where
tb1.id=tb2.id
Method2
Data Source=P06-INF-WS-1\SQLEXPRESS;Database=DB1;User ID=sa;Password=sa
select * from Table1 tb1 join on DB2.dbo.Table2 tb1 where
tb1.id=tb2.id
Table1 is assumed to be in DB1 as its specified in the connection string

Ever wondered why Code coverage shows not enabled for the code

1.Creating a test class for your project

Create a test class only when you have completed your coding bc the test class are created based
on your business logic..hence if you add/remove any functions there it wont be reflected in your test
class.

a.Go to Test->New Test in VS.Select Unit test Wizard and give it a appropriate name.All the test
functions wil be autogenerated for you.

b.Right click on solution and select add new file.Select Test Run Configuration in the general tab.

This file will end with .testrunconfig wherein you can specify different rules for your test to run.

If you want to check how much coverage you have achieved open this file and select Code Coverage-

Check the files for which you want to see the coverage.

c.Check if a .vsmdi file is created . if not then goto Test->Select Active Test Run configuration and
select the file you want to associate.

You can have many .testrunconfig files and associate them to a .vsmdi file which will be picked up by
you test class.

c. After writing all the test class select test->Run->All Test in solution. Remember to run test rather
then just clicking F5

d.Click on test->Windows->Code coverage Results.

You can see the code coverage only if all your test case are passed.

Schedule deleting of files of previous day in a particular folder

Schedule deleting of files of previous day in a particular folder

Although this can be achieved using .bat files i find it very complex.
Hence my approach is to write a vbscript and schedule it to run everyday at
particular time.

//VBScript code

Option Explicit

On Error Resume Next

Dim oFSO, oFolder, sDirectoryPath

Dim oFileCollection, oFile, sDir

Dim iDaysOld

'Specify Directory Path From Where You want to clear the old files

sDirectoryPath = ""

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oFolder = oFSO.GetFolder(sDirectoryPath)

Set oFileCollection = oFolder.Files

For each oFile in oFileCollection

iDaysOld =datediff("d",oFile.DateLastModified,date())

If iDaysOld>0 Then

oFile.Delete(True)

End If

Next

Set oFSO = Nothing

Set oFolder = Nothing

Set oFileCollection = Nothing

Set oFile = Nothing

Steps to schedule it via schedular in windows 7-

1.Go to Administrative Tools->Task Schedular.

2.create new task.Give it a name in General Tab.

3.In the trigger tab set the schedule it to occur daily at a particular
time.

4.In Action tab give the path where the .vbs is stored.

5.In the settings tab click “Run task as soon as possible after a scheduled
start is missed”.

Commonly encountered problems-

1.What if the system is logged of for days ..

Solution: Either active the notication facility in task schedular and
delete the files manually or

Create one more task indicating that the .vbs should run whenver the user
logs into the system.

2.what if the user has stord some files today in that path and logged
of...when he logs in again wouldnt that folders get deleted—

Solution: No the code is such that it will delete only files from previous
days.So even if schdule is missed the second task will delete the files.

Replace multiple values in a string

Replace multiple values in a string

using System.Text.RegularExpressions;

string Name=”India’an/dt/heWorl’d”;
//specify the characters to be replaced.here it will be replaced by blank
Regex.Replace(actualvalue[0].Trim(), @"[/,’ ]"," ").ToString()

Ouput- India an dt heWorl d

Split a string based on first occurrence of character

Split a string based on first occurrence of character

Suppose you have a string wherein a particular character is repeated many times but u want to split
it only at the first occurance

String value=”Name:Chaithra:Age-10”

string[] actualValue = value.Split(new char[] { ':' }, 2);

output-
actualValue[0]= Name
//observe that it has not split again.

actualValue[1]= Chaithra:Age-10

State Management

1.What is state management in asp.net ?
asp.net is a stateless technology.The process of maintaining the contents of the page when it moves from on page to another or when it is sent to the server is called state management.it can be done in two ways-
a)In-proc
b)out-proc

LINQ

1.What is LINQ ?
LINQ stands for language integrated query. Its a part of .Net 3.5 framework.It provides quering capabilities in .Net languages.it intergrates databse model into programming model.logic can be used to retrieve data with sql like statements in C#.

2.What are diff area in which LINQ can be used ?
LINQ is divided into 3 categories --
a)linq to objects--this includes mainly quering collections which implemet IEnumerable interface.
b)linq to ADO.NET
  •  linq to SQL
  •  linq to DataSet
  •  linq to Entities(ORM model)
c)linq to XML 

3.When not to use LINQ ? 
a)It should not be used in C# if the same logic is achieved by simple c# coding. 
b)linq to sql involves performance overhead hence should be used efficiently.

4.Use LINQ to query the numbers greater than 5 from a collection of array.int[] nums = new int[] {0,4,2,6,3,8,3,1};
var result = from n in nums
             where n > 5
             orderby n             //orders in asc order
             select n;

5. What is ORM ?

it stands for object relational mapping wherein it provides the user with the ability to change and manipulate the objects without having to worry about how the objects are related to their datasource.


 

Answer a Ques !!!

1.Why C# does not support multiple inheritance ?

Polymorphism

1..What is Polymorphism.explain diff types.
Ability to take more than one form is called poymorphism.Diff types are-
Compile time/Design time polymorphism
this is also called method overloading.The method will have same name but diff parameters.
Run time polymorphism
this is also called overriding.its achieved by virtual and override keywords 

2.What is method overloading ?
Having different methods with same name but different parameters inn a single class is called method overloading.methods can be overloaded based on following-
a)diff no of paramteres.
              public void method(int a)
              public void method(int a,int b)
b)diff types of parameters.
              public void method(int a)
              public void method(float a)
c)diff order of parameters.
             public void method(int a,float b)
             public void method(float b,int a)

3.When should we use method overloading?
When you need couple of methods to take different parameters but do the same thing.
eg-Draw(circle c),Draw(triangle t)... the basic function is drawing but they draw diff structures. in CLR console.writeline() does the same thing.

4.What is method overriding?
Its a feature which is used in inheritance chain and it provides its own implementation to an already existing method in base class. its achived by using virtual and override keyword.
class A
{
     public virtual void method()
     {
     }
}
class B:A
{
    public override void method()
     {
     }
}
The appropriate methods are invoked at runtime when proper references are allocated.

5.Advantages of polymorphism.
a)invoking child class functions dynamically
b)maintenance of code becomes easy.

6.Whats the diff bt new and override keyword in inheritance chain ?

new keyword completely hides the base class implementation and creates a
new method.It can be concluded that the method defined is independent of
base class method.

override keyword overrides the base class implementation. it helps in existence of different diff versions of method and appropriate version is called dynamically.Objects of derived class will cal this method instead of base class method.

7.Will the foll code compile ? why ?
a)
class A
{
     public void method()
     {
     }
}
class B:A
{
     public override void method()
     {
     }
}
No.Because you can override the base class method only if its marked as virtual

b)
class A
{
     public void method()
     {
     }
}
class B:A
{
     public new void method()
     {
     }
}
Yes.Because new keyword defines its own implementation and its not related to base class method in any way.

c)
class A
{
     public void method(ref int a)
     {
     }
     public void method(out int a)
     {
     }
}
No.methods cannot be overloaded based on the ref and out parameter.

d)
class A
{
     public virtual void method()
     {
     }
}
class B:A
{
     public void method()
     {
     }
}
class C:B
{
     public override void method()
     {
     }
}
No.Class C is overriding method in its base class B. it can do so only if method in base class is marked as virtual.

e)
class A
{
     public virtual void method()
     {
     }
}
class B:A
{
     public new void method()
     {
     }
}
class C:B
{
     public override void method()
     {
     }
}

No.Class C is overriding method in its base class B. it can do so only if method in base class is marked as virtual.

8.Whats the disadvantage of using virtual keyword?
a)Appropriate function calls are determined only at runtime.
b)since virtual keyword is used derived classes may ignore that base class implementations.

9.Whats the output of foll code
a)
class A
{
     public virtual void method()
     {
      //print A
     }
}
class B:A
{
     public override void method()
     {
      //print B
     }
}
class C:B
{
     public new void method()
     {
       //Print C
     }
}
A objA = new A();
objA .method()                              //Output:A

objB= new B()
objB.method()                               //Output:B
                          
objC= new C()
objC.method()                               //Output:B(bc of new keyword)


10.Why static methods cannot have virtual keyword ?
The idea of using virtual keyword is  to achieve polymorphism i.e calling appropriated functions dynamically at runtime, But static methods are attached to the class names and to invoke them you have to go through the classes. And they are decided at compile time hence there is no point in having virtual keyword to static methods.

11.Can properties be marked as virtual ?
Yes





Diff bet ween== and Equals ?

In our daily programming we have come across these expressions many times. here is when you should choose one over the other.Both these  operator perform the same function i.e comparing the equality but the way they do it depends on who is using them.
For value types both == and Equals mean the same ,they compare the value present in both the types.eg
                int a=5;int b=5;
                a==b
                a.equlas(b)
Both these return True as they are comparing the value inside them and both the variables have same value.

For Reference types  ==  checks whether they are pointing to the same reference and equals checks if both the reference contains the same value.
eg:
        
StringBuilder s1 = new StringBuilder(“Name”);
StringBuilder s2 = new StringBuilder(“Name”);
Console.WriteLine(s1 == s2);
Console.WriteLine(s1.Equals(s2));
Will display:
False
True

Inheritance

  1.what is inheritance ?
The method of constructing one class from another is called Inheritance.The derived class inherits all the properties and methods from the base class and it can add its own methods also.

2.Are constructors and destructors inherited ?
No

3.Advantages of Inheritance.
a)Code re usability-Public and protected methods can be used in derived classes
b) Extensibility- base class can be extended as per business logic in derived classes.
c)Polymorphism

4.What are diff types of inheritance?
a) Single inheritance --Class B is derived from base class A. A->B
b)Multiple inheritance ---Class C derives from both A and B.  A,B->C
c)Multilevel inheritance--Class B derives from Class base class A.class C derives from B.  A->B->C
d)Hybrid inheritance --class B and C derives from same base class A.  A->B,C

5.Is multiple inheritance possible in C#.Why?
No. because
a)Its not supported by CLR since its support many diff language and not all languages can have multiple inheritance concept. 
b)Because of the complexities involved where method name can clash when two diff classes have same method name.This is resolved by pointers in C++ but its not possible in c#.


Instead interfaces can be used to achieve the same.


6.Is circular inheritance possible. like A:B ,B:A ?
No


7.How do you prevent a class from being inherited ?
a)Make the class as sealed.
b)Add private constructors to the class.


8. Can derive class have public modifier when there are no modifiers specified on the base class?
No. bc derived class cannot be more accessible that base class.


9.why c# does not support inheritance by structure?
Because structures are mainly used for light weight process. And if they are allowed to be inherited then they have to act as base class which is not possible as they are value types.


10.Does structs inherit from interfaces?
Yes structs can inherit only from interface.


11.What do you mean by sealed keyword ?
If you mark a class as sealed it means that you cannot inherit from it but you can create objects of that class.


12.can you mark method as sealed ?
Yes.But for a method to be marked as sealed you need to have override keyword also.



13.what do you mean by upcasting and downcasting ?
class DerivedClass :BaseClass

Upcasting--assigning a derived class object to a base class.This is implicit.
BaseClass b= new DerivedClass.


Downcasting--assigning baseclass object to derived class. This is explicit and it throws run time error .
a)BaseClass b = new BaseClass()
   DerivedClass d= b  //will give compile time error.
  
b) d=(DerivedClass)b  //will give runtime error.


c)b=d;
   d=(DerivedClass)b;
   d.method()             //will always call derivedclass method

   //there is no point in taking so much of pain and using this kind of code !!!


14.

 

 

Exception

1.What are the two diff types of error?
Run time error and Compile time error

2.What is the base class from which all the exceptions are derived ?
System.Exception class

3.What are the two main kind of exceptions class?
System Exception-- Mainly used for inbuilt exceptions like Null Ref Exception,Overflow Exception,Argument ....etc
Application Exception-This class is used for user defined exceptions.

4.How to you handle error in C#?
By using try ,catch and finally blocks.
try-contains the code which might throw an exception
catch-deals with various error conditions
finally-does the cleaning up.

5.Does finally get executed if the code throws an error ?
Finally is always executed.

6.Is it mandatory for a piece of code to have catch or finally when try block is there ?
Yes. If a try block is there then either catch or finally has to be there or else a compiler error is generated.

7.Can finally bock have return statement ?
No,a compile time error is generated. Thats bc finally contains the clean up code.

8.Can there be many catch statements for a single try block ?
Yes.But the rule is most specific exceptions should be caught first.

9.Will the foll code compile ?
           try
            {
                throw new SystemException();
            }           
            catch(Exception e)
            {
            }
            catch(ArgumentException e)
            {
            }
No.It gives the foll error
A previous catch clause already catches all exceptions of this or of a super type ('System.Exception')

10.Whats the syntax for catching all kinds of exception.
try{}
catch         //no parameters specified
{
}
it will catch exceptions thrown by managed as well as unmanaged code.


11.All the foll catch block uses the same exception parameter 'e'. Is it valid?
catch(Exception e) {}
catch(ArgumentException e) {}
Yes,bc the parameter passed to catch block wil be within its scope only.


12.What are diff exception properties ?
a)Helplink-- provide link to help files which give more info on the exception raised.

b)Message--gives the text that describes the exception.
Suppose catch(Exception e)
                {
                       throw new Exception("Failure")
                }
then e.Message will give output as "Failure".

c)Source--provides the name of assembly from where exception is raised.
d)Target Site--name of method thats trows an error
e)Stack Trace--provides stack flow of the exception.
f)Inner Exception--When exception is thrown from one catch to another the message from first catch is passed as inner exception to second catch.

13.What is checked and unchecked operator.
checked--checks  for the error and throws an exception.
unchecked--does not check for the error .truncates the data and prints it..used mainly while casting.

14.Does foll code work ?
try {}
catch(Exception e) {}
catch(Exception e) {}

No,two catch block cannot have same exception classes.

 15.Whats the diff bt throw and throw e ?
throw-- throws the exception.
               throw is internally compiled to rethrow 
throw e--throws the exception and resets the stack trace to current catch
                  location.

                  internally compiled to throw which taken an exception parameter as
                  input.

16.What is the output of foll programs
   a)       try
            {
                throw new SystemException("This is wrong");
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);            
                return;
            }
            finally
            {
                Console.WriteLine("i am inside finally");
                Console.Read();
            }

output--   This is wrong
                     i am inside finally.

b)        try
            {
                throw new SystemException("This is wrong");
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
            finally
            {
                Console.WriteLine("i am inside finally");
                Console.Read();
            }

output  - This is wrong.
                   Application crashes bc the throw is not being caught anywhere and
                  hence finally wont be executed.

c)public class A
  
    {
        public void methodA()
        {
            try
            {
                B test = new B();
                test.methodB();
            }
            catch (Exception e)           
            {
                throw e;
                Console.WriteLine("Exception from Class A");
            }
            finally          
            {
                Console.WriteLine("Inside Class A Finally");
            }
        }
    }

    public class B
    {
        public void methodB()
        {
            try
            {
                throw new Exception("Exception from Class B");
            }
            catch (Exception e)
            {
                throw;
                Console.WriteLine("Exception from Class A");
            }
            finally
            {
                Console.WriteLine("Inside Class B Finally");
            }
        }
    }

output--inside class B finally.


Not able to see the line number in exception stack trace in remote machine

While building a project make sure .pdb files are generated. copy these files in the folder where you have installed your application in remote machine .
If pdb files are not generated check if the setting is enabled for your project-

Solution->Properties->Build->Advanced Build Settings->Debug Info->pdb-only