Tuesday, 19 August 2014

C# & ASP.NET Interview Questions and Answers Part - 2

Ø  Friend/Internal - Method, Properties in that class can be accessed by all the classes within that particular assembly. 
Ø  Protected Friend/Protected Internal - Methods, Properties can be accessed by the child classes of that particular class in that particular assembly.
Ø  This property is used to check whether the page is being loaded and accessed for the first time or whether the page is loaded in response to the client postback. 
Ø  Example: Consider two combo boxes 
In one let’s have a list of countries 
In the other, the states. 
Ø  Upon selection of the first, the subsequent one should be populated in accordance. So this requires postback property in combo boxes to be true.
Ø  Use Server.GetLastError();
Ø  Use Server.ClearError();
Ø  MSIL is the Microsoft Intermediate Language.
Ø  All .NET compatible languages will get converted to MSIL. MSIL also allows the .NET Framework to JIT compile the assembly on the installed computer.

Ø  System.GC.Collect() forces garbage collector to run.
Ø  This is not recommended but can be used if situation arises.


There are three major ways to host a WCF service :- 

Ø  1. Self hosting the service in his own application domain. This we have already covered
in the first section. The service comes in to existence when you create the object of
Service Host class and the service closes when you call the Close of the Service Host
class. 
Ø  2. Host in application domain or process provided by IIS Server. 
Ø  3. Host in Application domain and process provided by WAS (Windows Activation
Service) Server.


Ø  No. in this case the finally block will not execute because when you say System.exit (0); the control immediately goes out of the program, and thus finally never executes.


60. How would you implement inheritance using VB.NET & C#?

Ø  C# : Derived Class : Baseclass 
Ø  VB.NEt : Derived Class Inherits Baseclass


 VB.NET :
-----------
1)no unsigned int
2)Loosely typed language
3)no operator overloading
4)no pointers
5)no auto XML documentation

C#.net :
-------------
1) supports unsigned int
2)strongly typed language
3)supports operator overloading
4)supports pointers
5)supports auto XML documentation

Ø  There is only one feature which is common to all languages and that is Garbage collection or GC.
Ø  This feature is automated which relieves developers of much work.
Ø  This garbage is disposed only when there is need of memory or stress for memory.
Ø  GC feature halts the application for few seconds before restarting it.

63. Explain the differences between Server-side and Client-side code? 

Ø  Server side code will execute at server (where the website is hosted) end, & all the business logic will execute at server.
Ø   Where as client side code will execute at client side (usually written in javascript, vbscript, jscript) at browser end. 

64. What type of code (server or client) is found in a Code-Behind class? 

Ø  Server side code. 

65.. How to make sure that value is entered in an asp:Textbox control? 

Ø  Use a RequiredFieldValidator control. 
66. Which property of validation control is used to associate with server control on that page? 

Ø  ControlToValidate property. 


68. Which method is invoked on the DataAdapter control to load the generated dataset with data? 

Ø  Fill() method. 


69. What method is used to explicitly kill a user's session? 

Ø  Session.Abandon() 


70. What property within the asp:gridview control is changed to bind columns manually?

Ø  Autogenerated columns is set to false 


71. Which method is used to redirect the user to another page without performing a round trip to the client? 

Ø  Server.Transfer method. 


72 . How do we use different versions of private assemblies in same application without re-build? 

Ø  Inside the Assemblyinfo.cs or Assemblyinfo.vb file, we need to specify assembly version.
assembly: AssemblyVersion

Advantages of Crystal Reports 

Some of the major advantages of using Crystal Reports are: 

Ø  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


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

Ø  Response.Output.Write() allows you to write formatted output.



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.

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.


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


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)

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.

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.

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. All C# (when not using the unsafe keyword), Visual Basic .NET, J#, and JScript .NET code is managed by default. Visual Studio .NET C++ code is not managed by default, but the compiler can produce managed code by specifying a Command-line switch (/CLR). Closely related to managed code is managed data—data that is allocated and reallocated by the common language runtime's garbage collector. C#, Visual Basic.NET, J# and JScript .NET data is managed by default. C# data can, however, be marked as unmanaged through the use of special keywords. Visual Studio .NET C++ data is unmanaged by default (even when using the /CLR switch), but when using Managed Extensions for C++, a class can be marked as managed by using the __gc keyword. As the name suggests, this means that the memory for instances of the class is managed by the garbage collector. In addition, the class becomes a full participating member of the .NET Framework community, with all of the benefits and restrictions that brings. An example of a benefit is proper interoperability with classes written in other languages (for example, a managed C++ class can inherit from a Visual Basic.NET class). An example of a restriction is that a managed class can only inherit from one base class. Any restrictions, such as this one, are designed to prevent common programming errors.


A name that consists of an assembly's identity—its simple text name, version number, and culture information (if provided)—strengthened by a public key and a digital signature generated over the assembly.

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. The specification for the PE/COFF file formats is available at 

Ø  system.object

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

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

When an exception occurs, the system searches for the nearest catch clause that can handle the exception, as determined by the run-time type of the exception. First, the current method is searched for a lexically enclosing try statement, and the associated catch clauses of the try statement are considered in order. If that fails, the method that called the current method is searched for a lexically enclosing try statement that encloses the point of the call to the current method. This search continues until a catch clause is found that can handle the current exception, by naming an exception class that is of the same class, or a base class, of the run-time type of the exception being thrown. A catch clause that doesn't name an exception class can handle any exception.
Once a matching catch clause is found, the system prepares to transfer control to the first statement of the catch clause. Before execution of the catch clause begins, the system first executes, in order, any finally clauses that were associated with try statements more nested that than the one that caught the exception.
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.

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.

Private, Public/Shared, Satellite

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

Reflection

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.

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.


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

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. The specification for the PE/COFF file formats is available at
http://www.microsoft.com/whdc/hwdev/hardware/pecoffdown.mspx


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.

system.object


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

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


When an exception occurs, the system searches for the nearest catch clause that can handle the exception, as determined by the run-time type of the exception. First, the current method is searched for a lexically enclosing try statement, and the associated catch clauses of the try statement are considered in order. If that fails, the method that called the current method is searched for a lexically enclosing try statement that encloses the point of the call to the current method. This search continues until a catch clause is found that can handle the current exception, by naming an exception class that is of the same class, or a base class, of the run-time type of the exception being thrown. A catch clause that doesn't name an exception class can handle any exception.
Once a matching catch clause is found, the system prepares to transfer control to the first statement of the catch clause. Before execution of the catch clause begins, the system first executes, in order, any finally clauses that were associated with try statements more nested that than the one that caught the exception.
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.




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.

Private, Public/Shared, Satellite
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
Reflection
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.
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.
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."

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


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.