Thursday, March 7, 2013

ASP & .Net Interview Questions


ASP & .Net  Interview Questions
                          


1. Advantages of Crystal Reports 

Some of the major advantages of using Crystal Reports are: 

1. Rapid report development since the designer interface would ease the coding work for the programmer.

2. Can extend it to complicated reports with interactive charts and enhance the understanding of the business model

3. Exposes a report object model, can interact with other controls on the ASP.NET Web form

4. Can programmatically export the reports into widely used formats like .pdf, .doc, .xls, .html and .rtf

2. What is the Difference between Web.config and Machine.config?

Scope:
Web.config => For particular application in IIS.
Machine.config = > For All the applications in IIS
Created:
Web.config => Created when you create an application
Machine.config => Create when you install Visual Studio
Known as:
Web.config => is known as Application Level configuration file
Machine.config => is known as Machine level configuration file
Location:
Web.config => In your application Directory
Machine.config => …\Microsoft.NET\Framework\(Version)\ CONFIG



3. What is the Global.asax used for?


The Global.asax (including the Global.asax.cs file) is used to implement application and session level events.

4. What does the "EnableViewState" property do? Why would I want it on or off?


It allows the page to save the users input on a form across postbacks. It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the clients browser. When the page is posted back to the server the server control is recreated with the state stored in viewstate.

5. What is GC in NET Framework?


The .NET Framework's garbage collector manages the allocation and release of memory for your application. Each time you use the new operator to create an object, the runtime allocates memory for the object from the managed heap. As long as address space is available in the managed heap, the runtime continues to allocate space for new objects. However, memory is not infinite. Eventually the garbage collector must perform a collection in order to free some memory. The garbage collector's optimizing engine determines the best time to perform a collection, based upon the allocations being made. When the garbage collector performs a collection, it checks for objects in the managed heap that are no longer being used by the application and performs the necessary operations to reclaim their memory.

6. What is the common language runtime (CLR)?

The common language runtime (CLR) is major component in the .NET Framework and it is the execution engine for .NET Framework applications.

It is responsible for proving the number of services, including the following:

1. Code management (loading and execution)

2. Verification of type safety

3. Conversion of Microsoft Intermediate Language (MSIL) to native code

4. Access to metadata (enhanced type information)

5. Managing memory for managed objects

6. Enforcement of code access security (See what is code access security?)

7. Exception handling, including cross-language exceptions

8. Interoperation between managed code, COM objects, and pre-existing DLLs (unmanaged code and data)

9. Automation of object layout

10. Support for developer services (profiling, debugging, and so on)

7. What is the common type system (CTS)?

The common type system (CTS) is a rich type system, built into the common language runtime (CLR) that supports the types and operations found in most of .NET programming languages. The common type system supports the complete implementation of a wide range of programming languages.

8. What is the Microsoft Intermediate Language (MSIL)?


MSIL is the Machine independent Code into which .NET Framework programs are compiled. It contains instructions for loading, storing, initializing, and calling methods on objects. Combined with metadata and the common type system, MSIL allows for true cross language integration. Prior to execution, MSIL is converted to machine code via CLR’s Just-in-Time (JIT) compiler.

9. What is managed code and managed data?


We can describe this Manage code like, if a code running under the control CLR, then we can call it as Managed Code.

Managed code is code that is written to target the services of the common language runtime (see what is CLR?). In order to target these services, the code must provide a minimum level of information (metadata) to the runtime.

10. What is portable executable (PE)?

The file format defining the structure that all executable files (EXE) and Dynamic Link Libraries (DLL) must use to allow them to be loaded and executed by Windows. PE is derived from the Microsoft Common Object File Format (COFF). The EXE and DLL files created using the .NET Framework obey the PE/COFF formats and also add additional header and data sections to the files that are only used by the CLR.
11. What is Code Access Security (CAS)?

CAS is the part of the .NET security model that determines whether or not a piece of code is allowed to run, and what resources it can use when it is running. For example, it is CAS that will prevent a .NET web applet from formatting your hard disk.

12. Which namespace is the base class for .net Class library?


system.object

13. What is serialization in .NET?


Serialization is the process of converting an object into a stream of bytes.

14. What is Deserialization in .NET?


Deserialization is the opposite process of serialization, creating an object from a stream of bytes.


Exception handling is the process of responding to the occurrence, during computation, of exceptions – anomalous or exceptional events requiring special processing – often changing the normal flow of program execution. It is provided by specialized programming language constructs or computer hardware mechanisms.
Exceptions that occur during destructor execution are worth special mention. If an exception occurs during destructor execution, and that exception is not caught, then the execution of that destructor is terminated and the destructor of the base class (if any) is called. If there is no base class (as in the case of the object type) or if there is no base class destructor, then the exception is discarded.

16. What are the contents of assembly?

In general, a static assembly can consist of four elements:

• The assembly manifest, which contains assembly metadata.
• Type metadata.
• Microsoft intermediate language (MSIL) code that implements the types.
• A set of resources.

17. What are the different types of assemblies?


Private, Public/Shared, Satellite

18. What is the difference between a private assembly and a shared assembly?


1. Location and visibility: A private assembly is normally used by a single application, and is stored in the application's directory, or a sub-directory beneath. A shared assembly is normally stored in the global assembly cache, which is a repository of assemblies maintained by the .NET runtime. Shared assemblies are usually libraries of code which many applications will find useful, e.g. the .NET framework classes.

2. Versioning: The runtime enforces versioning constraints only on shared assemblies, not on private assemblies

19. What is the difference between ref & out parameters?


An argument passed to a ref parameter must first be initialized. Compare this to an out parameter, whose argument does not have to be explicitly initialized before being passed to an out parameter.

20. What is the difference between Array and Arraylist?


As elements are added to an ArrayList, the capacity is automatically increased as required through reallocation. The capacity can be decreased by calling TrimToSize or by setting the Capacity property explicitly.

21. 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."


22. What are indexers?


Indexers are similar to properties, except that the get and set accessors of indexers take parameters, while property accessors do not.

23. What is Interop Services?


The common language runtime(CLR) provides two mechanisms for interoperating with unmanaged code:

• Platform invoke, which enables managed code to call functions exported from an unmanaged library.

• COM interop, which enables managed code to interact with COM objects through interfaces.

Both platform invoke and COM interop use interop marshaling to accurately move method arguments between caller and callee and back, if required.

24. What is RCW?

RCW Means Runtime Callable Wrappers, The common language runtime(CLR) exposes COM objects through a proxy called the runtime callable wrapper (RCW). Although the RCW appears to be an ordinary object to .NET clients, its primary function is to marshal calls between a .NET client and a COM object.

25. What is CCW?


CCW Means COM Callable Wrapper, A proxy object generated by the common language runtime (CLR). so that existing COM applications can use managed classes, including .NET Framework classes, transparently.

What is Pinvoke?


Platform invoke is a service that enables managed code to call unmanaged functions implemented in dynamic-link libraries (DLLs), such as those in the Win32 API. It locates and invokes an exported function and marshals its arguments (integers, strings, arrays, structures, and so on) across the interoperation boundary as needed.


What is side-by-side Execution?


Side-by-side execution is the ability to run multiple versions of an application or component on the same computer. You can have multiple versions of the common language runtime, and multiple versions of applications and components that use a version of the runtime, on the same computer at the same time.




What is the CAS ? .How to implement CAS ?

Code Access Security: It is .net security model that determines whether or not code is allowed to run .

What is an application domain?

Application domain is the boundary within which an application runs. A process can contain multiple application domains.
Application domains provide an isolated environment to applications that is similar to the isolation provided by processes.
An application running inside one application domain cannot directly access the code running inside another application domain.
To access the code running in another application domain, an application needs to use a proxy.
An application domain is a virtual process that serves to isolate an application. All objects created within the same application scope are created within the same application domain. Multiple application domains can exist in a single operating system process, making them a lightweight means of application isolation.



Can we have two files with the same file name in GAC?

Yes, we can add two files with same name in GAC using versioning.

Difference between String and StringBuilder class?


the string class is immutable and therefore very inefficient if you need
to change it once it is constructed. For those cases, StringBuilder is
almost always a better choice. in case of string new object is create every time when we concate string.


What are the differences between .NET Framework 3.0 and 3.5?


- .NET 3.0 is the combination of .NET Framework 2.0 with WCF, WPF, WF and cardspace.
- .NET 3.5 is the combination of .NET Framework 3.0 with New AJAX controls, LINQ, Richer WCF support, Silverlight Support...

What is Runtime Host ?


Ranging from Windows applications, Web applications to Mobile applications, CLR is designed to support various types of applications. .NET Framework provides different types of runtime hosts to manage the execution of application code(to load runtime in to process, create application domain within process, load user code in to application domain) and provides various services to the application.

Runtime hosts included in .Net framework are : ASP.NET, Microsoft Internet Explorer and windows shell.

Which method is used to serialize an object into an XML document from Xmlserializer class?


The "Serialize" method is the first step of serialize process and used to create an XML document

can we assign Null value to Struct variable.

No , We cannot assign null to a struct variable, since structs are value type.

What is the difference between a Struct and a Class?

Structs are Value type variables and are stored on the stack, while Class are Reference type variables and are stored on the heap.
Struct do not support inheritance, while class supports inheritance. However struct can implements interface.
Struct should be used when you want to use a small data structure, while Class is better choice for complex data structure

What is the .NET collection class that allows an element to be accessed using a unique key?


HashTable

What does the term immutable mean?

In object-oriented and functional programming, an immutable object is an object whose state cannot be modified after it is created.
The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory. Ex: String.
Making an object immutable is usually inappropriate if the object contains a large amount of changeable data.
So, For this reason .NET has the System.Text.StringBuilder class which is Mutable and appropriate for large amount of changeable data.


Can you store multiple data types in System.Array?

No, If the System.Array is of Some Particular Data Type.(Primitive Data Type)

yes, If the System.Array is of Object Type.

Ex :

create an array of objects.

int in = 50;
string st = "Fifty";

object [] obj = new object[2];
obj[0] = in;
obj[1] = st;

What exactly a Constructor is doing ?

Constructor Creates as well as Initialized the objects.

If a method is marked as protected internal who can access it?

Access is limited to the current assembly or types derived from the containing class

Why is Global.asax is used for ?


Global.asax is used To implement application & Session level events

What are Jagged Arrarys ?


A jagged array is really an array of arrays.
To create a jagged array, you declare the array of arrays with multiple sets of parentheses or brackets and indicate the size of the jagged array in the first set of brackets (parentheses).

WHat is HttpModule


It's just like a filter. The Modules are called before and after the handler executes.
.


Which casing should be used to declare name of interface, method and Namespace, as per the Microsoft coding standard?


Pascal Casing. Interface name should be declared with using Pascal Casing.
Example: Capitalize the first letter of every word, e.g. MyClassName.

Which casing should be used to declare name of Parameter, as per the Microsoft coding standard?


Camel Casing: Parameter name should be declared using Camel Casing.
Example: Capitalize the first letter of every word except the first word. e.g.myClassName.
How do we store the same named assemblies in GAC? Whether its possible?


Yes it is possible. By different versions of assembly we can store.

Can you please tell me about the typed dataset?

A typed dataset will be having the sehema with them as in an xml format.
It raises the compile time exceptions. Arranging data and giving relationship is possible through this.
What is the class to access FTP?


FtpWebRequest

Tell me a method to access a COM dll in .NET?


We can create a interop dll of COM to access in .NET



Why string is called Immutable data Type?


The memory representation of string is an Array of Characters, So on re-assigning the new array of Char is formed & the start address is changed. Thus keeping the Old string in Memory for Garbage Collector to be disposed.


What is the difference between the value-type variables and reference-type variables in terms of garbage collection?


The value-type variables are not garbage-collected, they just fall off the stack when they fall out of scope, the reference-type objects are picked up by GC when their references go null.
What's the advantage of using System.Text.StringBuilder over System.String?


StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it's being operated on, a new instance is created.




What's a satellite assembly?


When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.

Describe the difference between a Thread and a Process?


A Process is an instance of an running application. And a thread is the Execution stream of the Process. A process can have multiple Thread.
When a process starts a specific memory area is allocated to it. When there is multiple thread in a process, each thread gets a memory for storing the variables in it and plus they can access to the global variables which is common for all the thread.

What is the difference between an EXE and a DLL?


You can create an object of Dll but not of the EXE.
Dll is an In-Process Component whereas EXE is an OUt-Process Component.
Exe is for single use whereas you can use Dll for multiple use.
Exe can be started as standalone where dll cannot be.

What is strong-typing versus weak-typing?


Strong typing implies that the types of variables involved in operations are associated to the variable, checked at compile-time, and require explicit conversion; weak typing implies that they are associated to the value, checked at run-time, and are implicitly converted as required.

How do you generate a strong name?


.NET provides an utility called strong name tool. You can run this toolfrom the VS.NET command prompt to generate a strong name with an option "-k" and providing the strong key file name. i.e. sn- -k < file-name >

What is the difference between a Debug and Release build?

 
The Debug build is the program compiled with full symbolic debug information and no optimization. The Release build is the program compiled employing optimization and contains no symbolic debug information. These settings can be changed as per need from Project Configuration properties. The release runs faster since it does not have any debug symbols and is optimized.


Explain the importance and use of each, Version, Culture and PublicKeyToken for an assembly.


This three alongwith name of the assembly provide a strong name or fully qualified name to the assembly. When a assebly is referenced with all three.
PublicKeyToken: Each assembly can have a public key embedded in its manifest that identifies the developer. This ensures that once the assembly ships, no one can modify the code or other resources contained in the assembly.

Culture: Specifies which culture the assembly supports

Version: The version number of the assembly.It is of the following form major.minor.build.revision.

How to install a strong named assembly to GAC at command prompt?


We can use a developer tool called the Global Assembly Cache tool (Gacutil.exe), provided by the .NET Framework SDK or Use Windows Explorer to drag assemblies into the cache.

To install a strong-named assembly into the global assembly cache at the command prompt, type the following command:
gacutil I Asembly_name

In this command, assembly_name is the name of the assembly to be installed in the GAC.
What is GAC?


The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer. You should share assemblies by installing them into the global assembly cache only when you need to.

Just copy and paste your assembly to the GAC. But assemblies deployed in the global assembly cache must have a strong name. When an assembly is added to the global assembly cache, integrity checks are performed on all files that make up the assembly.


 How to create Key Pair?


You can create a key pair using the Strong Name tool (Sn.exe). Key pair files usually have an .snk extension. To create a key pair at the command prompt, type the following command:
sn k

In this command, file name is the name of the output file containing the key pair. The following example creates a key pair called myKey.snk.
sn -k myKey.snk

What do you mean by ActiveX components?


ActiveX control is a special type of COM component that supports a User Interface. Using ActiveX Control in your .Net Project is even easier than using COM component. They are bundled usually in .ocx files.

Which namespace in .NET is used in networking programming?


System.Net

What is the name of C# command line compiler?


csc.exe
What is an Assembly in .NET?

When you compile an application, the MSIL code created is stored in an assembly.Assemblies include both executable application files(.exe files)& libraries(.dll extension)for use by other application.

In addition to containing MSIL,assemblies also include met information(i.e. information about the information contained in assembly,also called as meta-data)and optional resources(sound and picture file, etc).The meta information enables assemblies to be fully self-descriptive.You need no other information to use an assembly,meaning you avoid situations such as failing to odd required data to the system registry and so on,which was often a problem when developing with other platforms.
What is the base class for all .NET classes?

System.Object

Why HashTable is used?


It is a .NET class that allows an element to be accessed using a unique key. It is mainly used in database programming.

Which namespace is used to create a multi-threaded application?


System.Threading

What is the role of compiler?

Compiler translates a high level language into machine language.

What is the namespace to use LINQ to XML?


System.Xml.XLinq

What are the elements inside an assembly?


A .NET assembly consists of the following elements,
A Win32 File Header
A CLR file header
CIL code
Type Metadata
An assembly manifest
Optional embedded resources
what is Reflection?


Reflection is the feature in .Net, which enables us to get some information about object in runtime. That information contains data of the class. Also it can get the names of the methods that are inside the class and constructors of that object.

program should use the reflection derived from namespace System.Reflection .
using reflection can dynamically load assembly.
what namespace is used for the controls in a mobile web application?

System.Web.UI.MobileControls

Which assembly is used for Mobile web application?


System.Web.Mobile
Which namespace provides classes for Regular Expression?


System.Text.RegularExpressions namespace provides classes for Regular Expression

What is the use of System.SystemException namespace?


System.SystemException provide different classes to handle fatal as well as non fatal errors.

Which class is the base class of all the exception classes?


System.Exception class is the base class of all the exception classes in .NET.

Which namespace is used to work with RSS feeds in .NET?


System.ServiceModel.Syndication namespace is used to work with RSS feeds in .NET.
Which namespace is used to create an Exception Tree?

System.Data.Common.CommandTree namespace provide classes to create an Exception Tree.


What is Covariance and Contravariance ?

Assigning a string to an object from specific type to a more general type is called covariance.

In contrast, assigning an array of objects to an array of strings, from general type to a more specific type, is referred to as contravariance


What is equivalent for regsvr32.exe in .NET?

In .NET we have regasm to register and unregister assemblies through .NET.



What are the Expansions of MSIL, JIT, CLR, CTS, CLS, RCW?


1. MSIL - Microsoft Intermediate Language.
2. JIT - Just-In-Time compiler .
3. CLR - Common Language Runtime.
4. CTS - Common Type System.
5. CLS - Common Language Specification.
6. RCW - Runtime Callable Wrapper.

Which namespace contains the classes that required to serialize an object? Explain Object Serialization?


System.Runtime.Serialization

Object serialization is the process of reducing an object instance into a format that can be either stored to disk or transported over a network.

Explain how to retrieve resources using ResourceManager class?


ResourceManager class is used to retrieve resources at run time.
• Create a ResourceManager with resource file name and the resource assembly as parameters.
• After having created, you can use ResourceManager.GetString method to retrieve a string.
• Use the ResourceManager.GetObject method to retrieve images and objects from a resource file.
What is code security? What are the types?


.NET framework provides the security features to secure code from unauthorized users.

There are two types of code security:
Role based security: This authorizes user.
Code access security: This protects system resources from unauthorized calls.

Define Principal object?


The Principal object represents authenticated users. It contains information about user’s identity and role. You have Principal Permission object in .NET Framework that specifies user and its role. It has Demand method that checks the current user or Principal against the name and role specified in the Principal Permission.


Explain declarative and imperative security?


Security checks can be applied in two ways that is imperatively or declaratively.

Declarative security is applied by associating attribute declarations that specify a security action with classes or methods.

Imperative security is applied by calling the appropriate methods of a Permission object that represents the Principal (for role based security) or system resource (for code access security).

Define context menu?


The menu that you get when you right-click is called the context menu. It is a modular piece of markup code that can move around the page. It consists of two distinct blocks, one is the user interface and another is the script code to connect the UI to it.

Explain the similarities and differences between arrays and collections?


• The Array class is not part of the System.Collections namespace. But an array is a collection, as it is based on the list interface.

• Array has a fixed capacity but the classes in the System.Collections namespace don’t have fixed capacity. That’s why array is a static container, but collection is dynamic container.

• Collections objects have a key associated with them. You can directly access an item in the collection by the key. But to find a specific item in an array, unless you don’t know the index number you need to traverse the array to find the value.

What is break mode? What are the options to step through code?


Break mode lets you to observe code line to line in order to locate error.

The VS.NET provides following options to step through code.
• Step Into
• Step Over
• Step Out
• Run To Cursor
• Set Next Statement

How do we step through code?


Stepping through the code is a way of debugging the code in which one line is executed at a time.

There are three commands for stepping through code:

Step Into: This debugging mode is usually time-consuming. However, if one wants to go through the entire code then this can be used. When you step into at a point and a function call is made somewhere in the code, then step into mode would transfer the control to the first line of the code of the called function.

Step Over: The time consumed by the Step into mode can be avoided in the step over mode. In this, while you are debugging some function and you come across another function call inside it, then that particular function is executed and the control is returned to the calling function.

Step Out: You can Use Step Out when you are inside a function call and want to return to the calling function. Step Out resumes execution of your code until the function returns, and then breaks at the return point in the calling function.


What are the debugging windows available?


The windows which are available while debugging are known as debugging windows.

These are: Breakpoints, Output, Watch, Autos, Local, Immediate, Call Stacks, Threads, Modules, Processes, Memory, Disassembly and Registers.

In .NET, which namespace contains classes used to a)Create a localized application? b)Develop Web Forms? c)Create Web server controls? d)Access Sql Server? e)Read a File?


a)System.Globalization, System.Resources
b)System.Web
c)System.Web.UI.WebControls
d)System.Data.SqlClient
e)System.IO


What is the concept of Automatic Memory Management in ASP.NET?

The .NET framework has introduced a concept called Garbage collector. This mechanism keeps track of the allocated memory references and releases the memory when it is not in reference. Since it is automatic, it relieves the programmers to manage unused allocated memory. This concept of managing memory is known as Automatic Memory Management.

What are the ways to retain variables between requests?


Below there are different ways to retain variables between requests. That is:

Context.Handler: This object can be used to retrieve public members of the webform from a subsequent web page.

Querystring: Querystring is used to pass information between requests as part of the web address. Since it is visible to use, we can't use it to send any secured data.

Cookies: Cookies stores small amount of information on client side. But we can't reply on cookies since many clients can refuse cookies.

View state: View state stores items added to the pages. These properties are as hidden fields on the page.

Session state: Session state stores items that are local to the current session.

Application state: Application state stores items that are available to all users of the application.

Explain how to dynamically clone a menu in .NET?


Below are the steps to dynamically clone a menu in .NET:

• Create an alternate MainMenu object.
• Clone the first menu with the CloneMenu method.
• Create additional menu items related to the application state.
• Then add the new menu items to the MenuItems collection of the top-level menu item cloned. This can be done by using the Add method to specify their order within the collection by their index.
• Then assign the newly created MainMenu object to the form.


What are Merge module projects?

Merge module projects are used for the packaging of files or components that are shared between multiple applications.

A merge module (.msm) file includes files, resources, registry entries, and setup logic. The .msm file is merged into the deployment projects for consistent installation of a component across multiple applications.



Describe XCOPY deployment. Under what conditions is it useful? When can it not be used?

XCOPY deployment is a simple method of deployment where the DOS command XCOPY is used to copy the application directory and any sub directories to the target machine. You can use XCOPY deployment if your application has no dependency on shared files and requires no special actions to be taken upon deployment. If suppose one application requires more complex deployment or references shared assemblies, there you should not use XCOPY.

Define the list of properties, methods and events included in SmtpClient class in the Framework?


Here is some partial list of the members of the SmtpClient class...

1) Properties:
• Host- The name or IP address of your email server.
• Port- The number of the port to use when sending an email message.

2) Methods:
• Send- It enables you to send an email message synchronously
• SendAsync- It enables you to send an email message asynchronously.

3) Events:
• Send Completed- It is raised when an asynchronous send operation completes.

                       
What is Network Load Balancing?


Network Load Balancing is a clustering technology offered by Microsoft as part of all Windows Server 2000 and Windows Server 2003 family operating systems. Network Load Balancing uses a distributed algorithm to load balance network traffic across the number of hosts, helping to enhance the scalability and availability of IP-based services, such as Web, Virtual Private Networking, Streaming Media, Terminal Services, Proxy, etc. It also provides high availability by detecting host failures and automatically redistributing traffic to operational hosts.

How can you change priority and what the levels of priority are provided by .NET?


Thread Priority can be changed by using Threadname.Priority = ThreadPriority.Highest .

Following are different levels of Priority provided by .NET:-
•ThreadPriority.Highest
• ThreadPriority.AboveNormal
• ThreadPriority.Normal
• ThreadPriority.BelowNormal
• ThreadPriority.Lowest



What is an application pool?


1. An application pool is a set of one or more websites in IIS served by the worker process.

2. Each application pool has its own worker process.

3. This process isolation prevents processing from interfacing with one another.

How can you bind the debug failed assembly?


You can bind the debug failed assembly by using Assembly Binding Log Viewer (fuslogvw.exe ) and also you can find out the searched paths.

What is the Difference between Compiler and Translator?


Compiler converts the program from one computer language to another computer language that is translating from a higher level language to a lower level language. A compiler has to cope with any valid syntax in the source language, and generate semantically equivalent code in the target language.

Translator which translate one language to many other language or else we can say a translator is usually translating from a high level language to another high level language, or from a low level language to a high level language. A translator usually has a fixed body of code that is required to translate the program.


In which way you can copy the COM component to the server and register?


These components provides setup program to install or remove them from the system. Suppose the component doesn’t provide a setup program, you can copy it to the server and register it using the MFC RegSvr32.exe utility, as shown below:
RegSvr32 MyComname.dll
Can we create web application with out web.config file?


·        Yes we can create, if there is a web.config file it will take settings from directory level web.config file.
·        if there is no web.config file in application level then it will go for machin.config file for setting. 
·        So we can create web application without web.config file


Which class defines the methods for implementing drawings, shapes, writing strings in a GUI based application?


Graphics class defined by the System.Drawing namespace contains methods
like DrawString, DrawArc, DrawImage, DrawEllipese which are used for implementing
Drawings, shapes, writing strings etc.

What will be the output of this program? using System; class Class2 { Class2() { static int i; i++; Console.WriteLine(i); } static void Main() { Class2 a = new Class2(); Class2 b = new Class2(); } }


Compiler error "Modifier static is not valid for this item"

static variables are declared at Class level.


Can classes be marked as protected or private ?


Yes, a class can be marked as protected but we have to use the concept of nested classes for that .
For a class can be marked as private we have to use the concept of nested classes for that or declare a class in a structure 

example: These are valid examples:
class A
{
protected class B
{
}
}

class C
{
private class D
{
}
}
//Class can also be private inside a structure
struct empz
{
private class Class3
{

}
}

It is OK.

If a class is declared below a namespace it cannot be marked as protected or private.

Do events have a return type?


Yes, events return a delegate.

example: delegate void dd();

event dd myevent;

myevent is the event name and returns the delegate dd

Which encoding does not allow Chinese or Arabic characters?


NOTE: This is objective type question, Please click question title for correct answer.


What are the differences between an interface and an abstract class.


Both interface and an abstract class cannot be instantiated and are implemented
by inheriting them in other classes.

The differences between them are:

1)Interfaces
a)All members are public by default.
b)They cannot contain fields.
c)No coding of the methods or the properties is allowed.
d)They do not provide implementation.
e)Interfaces support multiple inheritance
f)abstract keyword is not there before the interface or its members names.


Abstract classes
a)All members are private by default. We can put modifiers like
public, protected before the abstract class members.
b)They can contain fields.
c) coding of the methods or the properties is allowed.(nonabstract)
we can also declare abstract methods(methods with no coding) and only
the declaration
d)They can provide implementation. An abstract class can implement an
interface
e)Abstract classes support single inherritance
g)abstract keyword is required before their names and also before the
abstract methods or properties.






casting is the technique using which we convert data of one
type to data of another type.
It is like a main category of boxing.

boxing is a sub category of casting which deals with
converting a value type to a reference type.

example:
1) double d=245.66;
//casting: conversion between 2 value types
int;

a=(int)d;


2) int f=200;

object z=f; //casting as well as boxing: conversion of a value type to a reference type







You can load the assembly dynamically by using classes from the System.Reflection namespace.
Assembly x=Assembly.LoadForm( “custom.d11”);
You can create assembly by using classes from System.CodeDom.Compiler


Pinvoke (PlatForm Invoke) features of the .NET enables .NET Code to call functions from unmanaged libraries like user32.dll, kernel32.dll. Thse libraries contain Window API functions like FlashWindow, GetComputerName respectively.
FlashWindow can be used to blink the form's caption bar.
GetComputerName can be used to retreive the computer's name.


XSL stands for Extensible Style Language:

It is basically a formatting language using which we can convert an XML document
into an HTML document. XSL is similar to CSS but specific for XML documents.
XSL has its own set of namespaces and elements using which we can apply the formatting.



Differences between Window and Web Forms

Window Forms:

1)They do not need a web browser or web server to execute.

2)They execute through their respective exe files

3)They run on the same machine they are displayed on.

4)Their single instance exists until we close them or dispose them through coding

5)Used for developing games, inventory management, system utiltites etc.

6)They run under Code Access Security.


Web Forms:

1)They need a web browser as well as a web server(on the server machine only).

2)They execute through the dll of the web application which is then processed by IIS and the .net framework.

3)They run on a remote server and are displayed remotely on the clients.

4)Every time they are submitted, their new instance is created.

5)Used in web site development.

6)They use role based security



What is the difference between .NET 1.1,2.0,3.0,3.5 and 4.0 ?


The list of differences are huge. In interviews you normally need to short and sweet. So we will list down top 5 differences from each section.

So lets first start with the difference between 1.0 and 2.0.

Support for 64 bit application.
Generics
SQL cache dependency
Master pages
Membership and roles

Now the next difference .NET 2.0 and 3.0
WCF
WPF
WWF
WCS ( card space)

3.0 and 3.5
LINQ
Ajax inbuilt
ADO Entity framework
ADO data services
Multi targeting

Finally 3.5 and 4.0


MEF
Parallel computing
DLR dynamic
Code contract
language runtime
Lazy initialization


What is difference between out and ref in c#?


This is a great .NET Interview question and also very very confusing question. By default parameters are always passed by value to methods and functions.If you want to pass data byref then you can use either out or ref keyword.

There are two big difference between these keywords one is the way data is passed between the caller code and method and second who is responsible for initialization.

Way the data is passed(directional or bi-directional) 

When you use OUT data is passed only one way i.e from the method to the caller code.
When you use REF , Data can be passed from the called to the method and also vice versa.

Who initializes data
In OUT the variables value has to be intialized in the method. In REF the value is initialized outside the method by the caller

The most important thing the interviewer will like to hear from you When to use when
OUT will be used when you want data to be passed only from the method to the caller.
REF will be used when you want data to be passed from the called to the method and also vice versa.


What is .NET Framework?

.NET (.Network Enabled Technologies) is a collection of development tools
developed by the Microsoft Corporation that enables the developers to develop
and execute a large variety of applications

example: Console,Windows,Web,WPF,WCF, Web Services, Window Services,
Mobile Applications.

.NET Framework consists of:

1)CLR: (Common Language Runtime):

2)FCL: (Framework Class Llivraries)

3)Languages, Language Compilers

CLR is the set of components(also called as the execution engine) and provides
us with many runtime services.
example:
1)Managing code execution.
2)Menory management and Garbage Collection.
3)Exception handling management
4)Security and Code Verification
5)MultiThreading support
6)Cross Language interoperability using CTS and CLS.

FCL provides us with the predefined class libraries which have over thousands of

classes that can be used in development and execution.

example: System.Data.dl
System.Windows.Forms.dll
System.dll

mscorlib.dll

Languages :example: VB.NET, C#,VC++

Each language ahs its own set of compilers
ex: vbc for vb.net, csc for csharp.
Coompilers are used to compile the code and generate the executable files.(Assemblies)


What is CLS?


CLS:

Common Language Specification:

It is a set of the programming rules which every .NET language must follow.

CLS is used so that the code written in one language is interoperable with the code written in another language. The different .NET languages code is compiled into MSIL Code. CLS defines the infrastructure for the MSIL Code. The CLR processes the MSIL code and help in its execution. This ensures the language interoperability.


EXAMPLES OF


1)Common set of data types for all the languages( CTS)

Int32 datatype is implemented as int in C# and as integer in VB.NET

2)Interfaces cannot have static methods.It applies to all the .NET languages.

The Types which follow the CLS rules are also called as CLS Compliant types.

CLS compliant languages:

VB.NET,C#, VC++

Use of CLS:

A class written in VB.NET can be used in C# and vice-versa.


For the complete list of CLS features, please visit this link.


Differences between method overloading and method overriding


Method Overloading and Method Overriding are both the techniques used to implement FUNCTIONAL POLYMORPHISM
They enhance the methods functionality using their respective features.

overloading:
1) It involves having another method with the same name in a class or its derived class.

2)can be implemented with or without inheritance.

3)It is implemented by:

a)changing the number of parameters in different methods with same name.

b)changing the parameter data types (if the number of parameters are same)

c)changing parameter order.

4)applicable to static as well as non static methods:

5)no keywords needed before the method names in C#.

6)also called as COMPILE TIME Polymorphism

example: int add(int a, int b)
{
return a+b;
}
int add(int a)
{
return a*5;
}


1) It involves having another method with the same name in a base class and derived class.

2)always needs inheritance.

3)It is implemented by having two methods with same name, same signature, but different implementations (coding)in a base class and derived class

4)applicable to nonstatic, nonprivate methods only.access modifiers of the methods are not changed in the base and derived classes.

5)virtual and override keywords are needed before the method names in base and derived classes.
For overriding in firther classes, override keyword will be used,

6)RUN TIME Polymorphism
example:
class A
{
public virtual void demo()
{

}
}
class B:A
{
public override void demo()
{

}
static void Main()
{
B obj=new B();
obj.demo();
}
}



Collection classes are defined by 2 namespaces

1)System.Collections:

defines ArrayList, Stack, Queue

2)System.Collections.Generic

Defines the Generic Collections

example: List<>,Stack<>, Queue<>


Difference between an Assembly and DLL


An assembly is basically a file that contains the MSIL Code and Metadata.
It is the smallest unit of deployment of .NET applications.
An assembly in .NET has 2 extensions (.exe and .dll)

dll : dynamic link library.
So, we can say a dll is an assembly, but an assembly may not always be a dll

In other words, dll is one type of an assembly

OOP .NET Interview question :- What is Polymorphism?


This is a nice and simple OOP interview question.

As the name says POLY (Many) MORPHISM (Change). Polymorphism is the ability of the object to behave differently under different conditions. For instance a simple user object can behave as a admin user or as a simple user depending on conditions.

There are two ways of doing polymorphism dynamic and static. Static polymorphism is achieved by using method overloading and dynamic polymorphism is achieved by using method overriding. Please note do confuse with overloading and overriding while answering this question. Many .NET developers make a nice versa statement leading to lot of confusion.




What is MSIL?

MSIL : Microsoft Intermediate Language

Definition:
It is a set of CPU independent instructions that are generated by the language compiler when the project is compiled. MSIL code is not executable but further
processed by CLR/other runtime environments before it becomes executable.

MSIL is contained in the assembly of the .NET application.

Features:
MSIL instructions map to the code that is written in .NET Language and are used for loading, storing, initializing, and
calling methods on objects, as well as for
arithmetic and logical operations, control flow, direct
memory access, exception handling, and other operations.

CLS(Common language Specification) provides the infrastructure for MSIL

Benefits:

1)MSIL provides language interoperability as the code in any .NET language is compiled into MSIL.

2)Same performance for all the .NET Languages:

3)Support for different runtime environments:

CLR can understand MSIL.

Non .NET environments also support MSIL.
The JIT Compiler in CLR converts the MSIL code into native machine code which is then executed by the OS

Difference between Finalize and Dispose methods ?


Finalize and Dispose are both known as Finalizers.

They are the methods used to deallocate the memory of the objects
Differences:

FINALIZE

1)Finalize belongs to the Object class.

2)It is automatically called by the Garbage Collection mechanism when the object goes out of the scope(usually at the end of the program)
It is not called by the User Code.

In C#, suppose there is a class known as emp

class emp
{
//This is the destructor of emp class
~emp()
{
}
//This destructor is implicitly compiled to the Finalize method.
}

3)Not suitable for instant disposing of the objects.Sloer method

DISPOSE

1)Dispose belongs to the IDisposable interface

2)we have to manually write the code to implement it(User Code)
ex: if we have emp class we have to inherit it from the IDisposable interface
and write code. We may have to suppress the Finalize method using GC.SuppressFinalize() method.

3)Faster method for instant disposal of the objects

Example: user interface Controls. Forms, SqlConnection class have built in implementaion of Dispose method.
How many classes a dll can contain?


There is no limit.
However, it depends upon the hardware space available and the performance
related parameters.
What is Serialization?


Serialization:

It is the process through which we can convert an object into a format that can be persisted or transported.
During this process, the public and private fields of the object and the name of the class,including the assembly containing the class, are converted to a stream of bytes,
which is then written to a data stream.
Serialization allows us to save the state of objects from memory to files.
It is most commonly used in Web Services/Remoting applications.

Can abstract class have constructors?

Yes, an abstract class does have a constructor.
It will be called when it subclass is instantiated.

example:

abstract class bank

    {

        public bank()

        {

            Console.WriteLine("bank");

        }

       

    }

    class icici : bank

    {

        icici()

        {

            Console.WriteLine("icici");

        }

        static void Main()

        {

            bank b = new icici();



        }

    }


//Output:

when the object of icici class is created,
They will be displayed in the output.
bank
icici

Difference between a Class and Component?


Class is a datatype that encloses data and function members.
It can be used for implementing the various OOPS features.
Component is a particular class that must implement the IComponent interface .It is the base class for all components in the common language runtime that marshal by reference. Component is remotable and derives from the MarshalByRefObject class.
IComponent interface belongs to System.ComponentModel namespace.


What is an assembly manifest?

The assembly manifest is providing information to the .NET application at runtime. It provides the information like assembly's name, version, requested permissions, and other assemblies that the .NET application references.

It describes the assembly to the managed hosting environment.

It acts as a directory to the modules, types, and resources in the assembly.


What is an application manifest?


The application manifest which gives information to the operating system, such as in which way the assembly should be deployed and will check whether administrative elevation is required or not.

This is processed before the .NET-managed hosting environment loads to the assembly.





Difference between lock and Monitor.Enter()

lock keyword basically provides a shortcut to Enter method of Monitor class.
Monitor is used to provide thread synchronization.It means till the Thread in which the method is being used finishes its task, no other thread can access the object.

example:

lock (object)
{

}

It is compiled into

Monitor.Enter(object);
try
{
//code
}
finally
{
Monitor.Exit(object);
}  the MSIL of the assembly.




Can you install multiple assemblies together?


Yes, we can install multiple assemblies together

use installutil command

example: installutil Assembly1.exe Assembly2.exe.
It will install both the Assemblies in a transactional manner. if installation of one
of the assemblies fail, the installation of the other assembly will be rolled back.

Difference between Assembly.LoadFrom() and Assembly.LoadFile() methods?


Both methods are used to load the assemblies. we can then extract all the metatdata of the assembly using Reflection.

Difference:

1)LoadFrom can use either the name or the path of the assembly,
LoadFile will expect the path of the assembly(see the overloaded versions)

2)LoadFrom uses a probing algorithm to find the assembly.f if you have two assemblies that have the same identity but different locations, you can get some unexpected behavior.But using LoadFile, you can load the desired assembly as needed.

Is MSIL a high/low/middle level language?




MSIL

Microsoft Intermediate Language:
It is a set of CPU independent instructions which represent your code and used to provide language interoperability and compatibility of your code on different platforms.

It is not a high level language:
High Level language is C#:
High level language is more human readable,closer to a spoken language.
(Example: programming constructs like loops,if else conditions, keywords like using, class)
High level language defines modular programming,OOPS concepts and the source code.
MSIL is not low level language either:
low level language is in an executable or binary format(eg: machine language)
MSIL is not in an executable or binary format.

MSIL is not middle level language too:
Middle level language is C. It has modular programming and source code.
It is human readable.
C also supports low level programming (Assembly Language).


Can we use static constructors to initialize non static members?


Yes, it is possible. 
But we have to create an object of the class inside the static constructor and then initialize the non static member through the object

Code(example):

class Class2
{
int a;
static Class2()
{
Class2 p = new Class2();
p.a = 45;
System.Console.WriteLine(p.a);
}
static void Main()
{

}
}


No comments:

Post a Comment