Showing posts with label .Net Interview Questions. Show all posts
Showing posts with label .Net Interview Questions. Show all posts

Tuesday, July 7, 2009

.Net Interview Questions

1. If A.equals(B) is true then A.getHashcode & B.getHashCode must always return same hash code.
The answer is False because it is given that A.equals(B) returns true i.e. objects are equal and now its hashCode is asked which is always independent of the fact that whether objects are equal or not. So, GetHashCode for both of the objects returns different value.
2. What is an indexer in C#?

Indexer is a special syntax for overloading [] operator for a class. After defining an indexer, array syntaxes can be used for the class objects.
3. What is the use of fixed statement?

The fixed statement sets a pointer to a managed variable and “pins” that variable during the execution of statement.
Without fixed, pointers to managed variables would be of little use since garbage collection could relocate the variables unpredictably. (In fact, the C# compiler will not allow you to set a pointer to a managed variable except in a fixed statement.)
Eg:
Class A { public int i; }
A objA = new A; // A is a .net managed type
fixed(int *pt = &objA.i) // use fixed while using pointers with managed
// variables
{
*pt=45; // in this block use the pointer the way u want
}
4. What is the order of destructors called in a polymorphism hierarchy?

Destructors are called in reverse order of constructors. First destructor of most derived class is called followed by its parent’s destructor and so on till the topmost class in the hierarchy.
You don’t have control over when the first destructor will be called, since it is determined by the garbage collector. Sometime after the object goes out of scope GC calls the destructor, then its parent’s destructor and so on.
When a program terminates definitely all object’s destructors are called.
5. How can you sort the elements of the array in descending order?

int[] arr = new int[3];
arr[0] = 4;
arr[1] = 1;
arr[2] = 5;
Array.Sort(arr);
Array.Reverse(arr);
6. Is it possible to Override Private Virtual methods.

No, First of all you cannot declare a method as ‘private virtual’.
7. What is the difference between shadow and override?
Overriding is used to redefines only the methods, but shadowing redefines the entire element.
8. Is it possible to debug the classes written in other .Net languages in a C# project.
It is definitely possible to debug other .Net languages code in a C# project. As everyone knows .net can combine code written in several .net languages into one single assembly. Same is true with debugging.
9. What is the syntax to inherit from a class in C#?
Place a colon and then the name of the base class.
Example: class NewClassName : BaseClassName
10. Describe the accessibility modifier “protected internal”.
It is available to classes that are within the same assembly and derived from the specified base class.
11. What is a satellite Assembly?
An assembly containing localized resources for another assembly.
12. How to declares a two-dimensional array in C#?

Syntax for Two Dimensional Array in C Sharp is int[,] ArrayName;
13. What does it meant to say “the canonical” form of XML?

The purpose of Canonical XML is to define a standard format for an XML document. Canonical XML is a very strict XML syntax, which lets documents in canonical XML be compared directly.
Using this strict syntax makes it easier to see whether two XML documents are the same. For example, a section of text in one document might read Black & White, whereas the same section of text might read Black & White in another document, and even in another. If you compare those three documents byte by byte, they’ll be different. But if you write them all in canonical XML, which specifies every aspect of the syntax you can use, these three documents would all have the same version of this text (which would be Black & White) and could be compared without problem. This Comparison is especially critical when xml documents are digitally signed. The digital signal may be interpreted in different way and the document may be rejected.
14. What are Delegates?

Delegates are just like function pointers in C++, except that they are much safer to use due to their type safety. A delegate defines a function without implementing it and another class then provides the implementation. Events in C# are based on delegates, with the originator defining one or more callback functions.
15. What is C#?

C# ( pronounced as C-sharp ) is a new Java like language from Microsoft. Microsoft says that C# is a language with the power of C++ and simplicity of Visual Basic. C# supposed to be the best language for Microsoft’s .NET programming.
16. What is the difference between Java and .NET garbage collectors?

Sun left the implementation of a specific garbage collector up to the JRE developer, so their performance varies widely, depending on whose JRE you’re using. Microsoft standardized on their garbage collection.
17. Why do one get a syntax error when trying to declare a variable called checked?
Syntax Error is thrown because the word checked is a keyword in C#.
18. If a method is marked as protected internal how can it be accessed?
Method marked as Protected internally can be accessed by the Classes within the same assembly, and classes derived from the declaring class.
19. What is boxing?

Encapsulating a copy of a value type in an object.
20. How can I make sure my C# classes will interoperate with other .NET languages?

Make sure your C# code conforms to the Common Language Subset (CLS). To help with this, add the [assembly:CLSCompliant(true)] global attribute to your C# source files. The compiler will emit an error if you use a C# feature which is not CLS-compliant.

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.
 
Locations of visitors to this page