Wednesday, May 6, 2009

.Net Interview Questions

What is the difference between Overload and Override?
Overload is the another version of the same function into the class. There can be different parameters, return type in overload functions (in brief: Same function and different parameters).
Override is entirely overriding the base class function and creating our own version in the child class. Base class and child class function name and return type should be same.

What the way to stop a long running thread ?
System.Threading.Thread.Abort

What is multi-threading?
It is basically trying to do more than one thing at a time within a process.
There are two main ways of multi-threading which .NET encourages: starting your own threads with ThreadStart delegates, and using the ThreadPool class either directly (using ThreadPool.QueueUserWorkItem) or indirectly using asynchronous methods (such as Stream.BeginRead, or calling BeginInvoke on any delegate).

What’s difference between System.SystemException and System.ApplicationException?
The difference between ApplicationException and SystemException is that SystemExceptions are thrown by the CLR, and ApplicationExceptions are thrown by Applications.

What is CODE Access security?
Code Access Security (CAS), in the Microsoft .NET framework, is Microsoft's solution to prevent untrusted code from performing privileged actions.

It performs following function
1. Defines permissions and permission sets that represent the right to access various system resources.
2. Enables administrators to configure security policy by associating sets of permissions with groups of code (code groups).
3. Enables code to request the permissions it requires in order to run, as well as the permissions that would be useful to have, and specifies which permissions the code must never have.
4. Grants permissions to each assembly that is loaded, based on the permissions requested by the code and on the operations permitted by security policy.
5. Enables code to demand that its callers have specific permissions.
6. Enables code to demand that its callers possess a digital signature, thus allowing only callers from a particular organization or site to call the protected code.
7. Enforces restrictions on code at run time by comparing the granted permissions of every caller on the call stack to the permissions that callers must have.

What is Metadata?
Metadata is the complete way of describing what is in a .NET assembly. Digging into the metadata yields the types available in that assembly, viz. classes, interfaces, enums, structs, etc., and their containing namespaces, the name of each type, its visibility/scope, its base class, the interfaces it implemented, its methods and their scope, and each method’s parameters, type’s properties, and so on.

What is Manifest?
The manifest describes the assembly, providing the logical attributes shared by all the modules and all components in the assembly. The manifest contains the assembly name, version number, locale and an optional strong name that uniquely identifying the assembly.

What is the difference between Namespace and Assembly?
Namespace:
1. It is a Collection of names wherein each name is Unique.
2. They form the logical boundary for a Group of classes.
3. Namespace must be specified in Project-Properties.

Assembly:
1. It is an Output Unit. It is a unit of Deployment & a unit of versioning. Assemblies contain MSIL code.
2. Assemblies are Self-Describing. [e.g. metadata,manifest]
3. An assembly is the primary building block of a .NET Framework application. It is a collection of functionality that is built, versioned, and deployed as a single implementation unit (as one or more files). All managed types and resources are marked either as accessible only within their implementation unit, or by code outside that unit.

What is Managed and Unmanaged code?
Managed Code is what Visual Basic .NET and C# compilers create. It compiles to Intermediate Language (IL), not to machine code that could run directly on your computer. The IL is kept in a file called an assembly, along with metadata that describes the classes, methods, and attributes (such as security requirements) of the code you've created. This assembly is the one-stop-shopping unit of deployment in the .NET world. You copy it to another server to deploy the assembly there—and often that copying is the only step required in the deployment.

Unmanaged code is what you use to make before Visual Studio .NET 2002 was released. Visual Basic 6, Visual C++ 6, heck, even that 15-year old C compiler you may still have kicking around on your hard drive all produced unmanaged code. It compiled directly to machine code that ran on the machine where you compiled it—and on other machines as long as they had the same chip, or nearly the same. It didn't get services such as security or memory management from an invisible runtime; it got them from the operating system. And importantly, it got them from the operating system explicitly, by asking for them, usually by calling an API provided in the Windows SDK. More recent unmanaged applications got operating system services through COM calls.

What is JIT (Just-in-time) Compiler ?
Just-in-time compiler is a compiler used to convert the Commmon Intermediate Language (CIL) code into native code (also called machine code) that is processed by machine.

A little description
While compiling of .NET program, its code is converted into Common Intermediate Language code that is done by Common Language Runtime.
But while executing the program this CIL code is converted into Machine code or Native code that is done by JIT Compiler.

What is the location of Global Assembly Cache on the system?
C:\$WINDOWS\assembly

What's the difference between private and shared assembly?
Private Assembly is used inside an application only and does not have to be identified by a strong name.
Shared Assembly can be used by multiple applications and has to have a strong name.

Can you place two .dll files with the same name in GAC (Global Assembly Cache)?
Yes, provided both have different versions.
GAC is a Folder that contains .dll that have strong name. So we can keep myproject.dll and myproject.dll two files into GAC with different version like 1.0.0.0 and 1.0.0.1

What is typed dataset ?
A typed dataset is very much similar to a normal dataset. But the only difference is that the sehema is already present for the same. Hence any mismatch in the column will generate compile time errors rather than runtime error as in the case of normal dataset. Also accessing the column value is much easier than the normal dataset as the column definition will be available in the schema.

Can a DataAdapter.Fill method take DataTable as parameter or it works only for DataSet?
It has 5 different overloads and of course it can take DataSet as well as DataTable as parameter to fill data in from database.

Can you assign GridView.DataSource = DataReader()?
Yes

What is Property?
A property is a method or pair of methods that are exposed to the outside world as if they are fields.

What is Remoting in .NET?
.NET Remoting offers much more complex functionality including support for passing objects by values or by references, callbacks & multiple objects activation ^ life cycle management policy. In order to use Remoting a client need to build using .NET.
What is application domain?
The primary purpose of application domain is to isolate an application from other application. Win32 process provides isolation but in distinct memory address spaces. This is effective but it is expensive and doesn't scale well. The .NET runtime enforces app domain isolation by keeping control over the use of memory.
All memory in the app domain is managed by the .net runtime so the runtime can ensure that app domain do not access each other's memory. Objects in different application domains communicate either by transporting copies of objects across application domain boundries or by using a proxy to exchange messages.

What is RSS?
RSS (Really Simple Syndication/Rich Site Summary) is a light weight XML format for distributing news headlines or site summary & other contents of the website.

What is Satellite Assembly?
It is a often used to deploy language specific resources for an application. These assemblies work in side-by-side execution because the application has a separate product ID for each language & installed satellite assemblies in a language specific sub-directory.
When uninstalling, the application removes only the satellite assemblies associated within a give language & .NET Framework version.

What is MSIL?
MSIL (Microsoft Intermediate Language) is a CPU-Independent instructions set into which .NET Framework programs are compiled. It contains instructions for loading, storing, initializing and calling methods on objects.

What is CLS?
CLS (Common Language Specification) is a set of constructs or constraints that serves as a guide for library writers and compiler writers.It allows libraries to be fully usable from any language supporting the CLS, and for those languages to integrate with each other. The CLS is a subset of common type system. The common language specifications is also important to application developers wh are writing code that will be used by other developers.

What is CTS?
CTS (Common Type System) is a rich type system, build into the common language runtime that supports the types and operations found in most of the programming languages. The common type system supports the complete implementation of a wide range of programming language.

What does aspx stand for?
Active Server Pages Extension

What is Singleton pattern?
Singleton pattern ensures a class has only one instance & provide a global point of access to it. It is achieved by declaring a static variable for the class & checking for null before actually instantiating it.

Where reference and value types variables are stored?
All reference type variables are stored in heap (Random) and all value types variables are stored in stack (Sequential).

What is StringCollection?
StringCollection is a simple resizable collection of strings
Following function shows how to insert and retrive data into/from StringCollection.
public static string GetStringCollection()
{
System.Text.StringBuilder strB = new System.Text.StringBuilder();

// Add strings into StringCollection
System.Collections.Specialized.StringCollection strC = new System.Collections.Specialized.StringCollection();
strC.Add("Ram 1");
strC.Add("Ram 2");
strC.Add("Ram 3");
strC.Add("Ram 4");
strC.Add("Ram 5");

// Retrieve string from StringCollection
System.Collections.Specialized.StringEnumerator coll = strC.GetEnumerator();
while (coll.MoveNext())
{
strB.Append(coll.Current + "");
}
return strB.ToString();
}

What is the use of RCW & CCW?
RCW: Runtime Collable Wrapper takes a COM component, wrap it up and allows .NET client to consume it.
CCW: COM Collable Wrapper wraps a .NET object for consumption by COM client

List few ValueTypes variables.
Below are all ValueTypes variables.
System.SByte
System.Byte
System.Int16
System.Int32
System.Int64
System.Single
System.Double
System.Decimal
System.Char
System.Boolean
System.DateTime

String is a value type or reference type?
String is a reference type variable.

When to use String and StringBuilder class?
Use the String class to concat, join or format methods to join multiple items in a single statement.
Use StringBuilder class to create dynamic strings.

Write a function into Javascript that will toggle display a HTML element.
function ShowHide(id)
{
document.getElementById(id).style.display == '' ? document.getElementById(id).style.display = 'none' : document.getElementById(id).style.display = '';
}

What is CLR (Common Language Runtime)?
This is an execution engine for .NET Framework application. It provides a number of services including
1. Code Management
2. Application memory isolation
3. Verification of type safety
4. Conversion of IL to native code.
5. Access to meta data
6. Managing memory for managed objects
7. Enforcement of code access security
8. Exception handling, including cross-language exceptions.
9. Inter operation between managed code, COM objects and pre-existing DLLs (Unmanaged code and data)
10. Automation of object layout
11. Support for developer services (profiling, debugging etc.)

Difference between Response.Expires and Response.ExpiresAbsolute?
Response.Expires
This property specifies the number of minutes before a page cached in the browser expires ie. if the user returns to the same page before the specified number of minutes the cached version of the page is displayed.
<% Response.Expires = minutes %>

Response.ExpiresAbsolute
Using this property we can set the date and/or time at which page cached in the browser expires.
<% Response.ExpiresAbsolute=#May 15, 1999 18:00:00# %>

What is boxing and unboxing?
Converting a value type to reference type is called Boxing and Converting reference type of value type is Unboxing.

int i = 1;
object o = i; // boxing
int j = (int) o; // unboxing

What is gacutil.exe?
It's a command to install the assembly into the Global Assembly Cache.

How to use trace in libraray classes (like BAL, DAL)?
Use following code to use Trace.Warn, Trace.Write etc.
System.Web.HttpContext.Current.Trace

What is MVC (Model View Controller) pattern?
The Model-View-Controller (MVC) pattern separates the modeling of the domain, the presentation, and the actions based on user input into three separate classes:

Model. The model manages the behavior and data of the application domain, responds to requests for information about its state (usually from the view), and responds to instructions to change state (usually from the controller).

View. The view manages the display of information.

Controller. The controller interprets the mouse and keyboard inputs from the user, informing the model and/or the view to change as appropriate.

What are session management techniques in .NET?
There are three different techniques of managing session in ASP.NET
InProc
Session state is stored locally in memory of ASP.NET worker process.

StateServer
Session state is stored outside ASP.NET worker process and is managed by Windows service. Location of this service is specified by stateConnectionString attribute.

SQLServer
Session state is stored outside ASP.NET worker process in SQL Server database. Location of this database is represented by sqlConnectionString attribute.

No comments:

Post a Comment

 
Locations of visitors to this page