DotNet ,C Sharp and SQL Interview Questions

DotNet and SQL Interview Questions

1)Say in a structure which is value type. we have added a reference type variable. will it be stored in stack memory or heap

 2)in data-grid you are displaying a table. if you want to know what are the rows which are updated how do you implement it

 3)suppose you want to store you connection string where are you going to store it apart from web.config and appsettings.

 4)in try catch scenario there are two catch blocks one is System defined & other is user defined which will be executed first.

 5)in boxing & unboxing which one is expensive.

 6)difference between catch and throw

 7)you have deployed windows service at client place. say suppose it is giving erroneous results. it is running application. how do you debug it.

 8)there is a webservice deployed at the client place how can you check whether that application is working fine or not.

 9)you have deleted a record from database from your application a at the same time some one i updating the same record. how do you handle the situation.

 1)Say in a structure which is value type. we have added a reference type variable.will it be stored in stack memory or heap

 The reference type will be in the Heap (Always), the struct will just hold a pointer to it, i mean the pointer to the reference type is in stack, and actual object is in heap.
P.S: a value type will be stored in heap or stack based on were it is stored.

 2)in datagrid you are displaying a table. if you want to know what are the rows which are updated how do you implement it.
Datasetobject.getChanges(DataRowState.Modified)

 3)suppose you want to store you connection string where are you going to store it apart from web.config and app-settings.
This question is to see your approach, we can say "use a separate file, in which info is stored in binary form, after encrypting, we can also store it in another database ,
named control DB, which can be accessible only by the middle ware server thorough authentication etc, just we need to think different approaches and say,this does not have a correct answer / wrong answer.

 4)in try catch scenario there are two catch blocks one is system defined & other is user defined which will be executed first.
It purely depends on which exception is thrown, .Net framework will not see them with different eyes.


 5)in boxing & unboxing which one is expensive.
This question is not quite relevant, Boxing will be expensive, when a value type is boxed, memory is allocated in the heap,along with the overheads for reference type.Every reference type's instance has two additional members associated with the instance that the CLR uses to manage the object. The first member is the object’s pointer to the type’s method table, and the second member is a SyncBlockIndex.

 6)difference between catch and throw
Catch is to handle an exception, while throw is to raise an exception


7)you have deployed windows service at client place. say suppose it is giving erroneous results. it is running application. how do you debug it.
-Remote debugging

 8)there is a web service deployed at the client place how can you check whether that application is working fine or not.
this is again a approach type question, Try to access the web service from a client using a proxy Use WSDL to see if Web service returns its definition properly.


 9)you have deleted a record from database from your application a at the same time some one i updating the same record. how do you handle the situation.

 We have to use transaction (isolation) mechanism. something like READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, SERIALIZABLE.you might also look in to shared locks and update locks in SQL server.

 9)you have deleted a record from database from your application a at the same time some one i updating the same record. how do you handle the situation.

You can have TIMESTAMP field in table. Before your are updating the data in table, just needs to check whether the timestamp field is changed or not. if you need further clarification, let me know.

CSharp Interview Questions


What does ‘managed’ mean in the .NET context?

The term ‘managed’ is the cause of much confusion. It is used in various places within .NET, meaning slightly different things.

1.Managed code: The .NET framework provides several core run-time services to the programs that run within it - for example exception handling and security. For these services to work, the code must provide a minimum level of information to the run time. Such code is called managed code. All C# and Visual Basic.NET code is managed by default.VS7 C++ code is not managed by default, but the compiler can produce managed code by specifying a command-line switch (/com+).

2.Managed data: This is data that is allocated and de-allocated by the .NET runtime’s garbage collector. C# and VB.NET data is always managed. VS7 C++ data is unmanaged by default, even when using the /com+ switch, but it can be marked as managed using the __gc keyword.

3.Managed classes: This is usually referred to in the context of Managed Extensions (ME) for C++. When using ME C++, a class can be marked with the __gc keyword. As the name suggests, this means that the memory for instances of the class is managed by the garbage collector, but it also means more than that. The class becomes a fully paid-up member of the .NET community with the benefits and restrictions that brings. An example of a benefit is proper interop with classes written in other languages - for example, a managed C++ class can inherit from a VB class. An example of a restriction is that a managed class can only inherit from one base class.

What is reflection?

All .NET compilers produce metadata about the types defined in the modules they produce. This metadata is packaged along with the module (modules in turn are packaged together in assemblies), and can be accessed by a mechanism called reflection. The System.Reflection name space contains classes that can be used to interrogate the types for a module/assembly.
Using reflection to access .NET metadata is very similar to using ITypeLib/ITypeInfo to access type library data in COM, and it is used for similar purposes - e.g. determining data type sizes for marshaling data across context/process/machine boundaries.
Reflection can also be used to dynamically invoke methods (see System.Type.InvokeMember), or even create types dynamically at run-time (see System.Reflection.Emit.Type Builder).

What is an Application Domain?

An AppDomain can be thought of as a lightweight process. Multiple AppDomains can exist inside a Win32 process. The primary purpose of the AppDomain is to isolate an application from other applications.
Win32 processes provide isolation by having distinct memory address spaces. This is effective, but it is expensive and doesn’t scale well. The .NET runtime enforces AppDomain isolation by keeping control over the use of memory - all memory in the AppDomain is managed by the .NET run time, so the run time can ensure that AppDomains do not access each other’s memory

Can a C# class inherit from a VB Class?

Yes it can, It should be a CLS compliant code.

Strongly typed Class

A class is strongly typed if it only allows a specific type or types in its methods, rather than a
generic type such as an object. Strongly typed classes allow the compiler to ensure that the
proper objects are passed to methods in the class, and can prevent errors that would otherwise
occur only at run time.

Difference between object and Object, string and S

Difference between object and Object, string and String?
The object class is part of the C# language definition, and
all types, be they built-in or specific to your program, ultimately inherit from object.Separate from the language definition is the .NET Framework, containing classes
and name spaces used to generate programs and services of every kind. Within the .NET Framework is the System.Object class. In Microsoft’s C# compiler, the System.Object class is equivalent to the C# object class. So object and Object are different but functionally equivalent . similar discussion applies to the classes string and System.String as well