Saturday, 9 August 2014

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

1. What is Cross-Page Posting?

Ø  Whenever you send a request to the server it sends request to the same page.
Ø  In Cross page posting it will send request to another page.
Ø  We can achieve his through postback url property

2. What are Web services?

 

Ø  Web services are functions exposed by server-side applications.
Ø  They are programmable units that other applications (and Web services) can access over the Internet.
Ø  Web services are hosted in some website.
Ø  Web services holds business logic which can be used by any application.


There are three different techniques of managing session in ASP.NET 
Ø  1.InProc : Session state is stored locally in memory of ASP.NET worker process. 


Ø  2. 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. 

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

4. What is boxing and unboxing?

Ø  Converting a value type to reference type is called Boxing.

Ø  Converting reference type of value type is Unboxing. 
     int i = 1; 
object o = i; // boxing 
int j = (int) o; // unboxing

  

5. What is Property?

Ø  A property is a member that provides a flexible mechanism to read, write, or compute the value of a private field. Properties can be used as if they are public data members, but they are actually special methods called accessors. This enables data to be accessed easily and still helps promote the safety and flexibility of methods.


Ø  This is an execution engine for .NET Framework application.
Ø  CLR is responsible for take care of entire execution process.
Ø  It will convert MSIL code into Native Code.
Ø  CLR provides the following services
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.)

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

8. String is a value type or reference type?

Ø  String is a reference type variable.
   

9. List few ValueType variables.

System.SByte, 
System.Byte 
System.Int16 
System.Int32 
System.Int64 
System.Single 
System.Double 
System.Decimal 
System.Char 
System.Boolean 
System.DateTime



Ø  All reference type variables are stored in heap memory (Random).
Ø  All value types variables are stored in stack memory (Sequential).

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

12. What does aspx stand for?

Ø  Active Server Pages Extension

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


14. What is CLS?

Ø  CLS (Common Language Specification) is a set of constructs 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.

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

Ø  System.Threading.Thread.Abort

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

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

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


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# %>


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

Ø  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


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

Ø  C:\$WINDOWS\assembly

Ø  Just-in-time compiler is a compiler used to convert the Common 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.


Ø  Abstract class cannot be instantiated instead it has to be inherited.
Ø  The methods in abstract class can be overriden in the child class
Ø  Abstract class can holds both abstract methods and concrete methods.
Ø  Abstract class is desined to act as base class.
Ø  Concrete methods are common to all classes but abstract classes have new implementation in derived classes.


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


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



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


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


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.




Ø  The difference between ApplicationException and SystemException is that SystemExceptions are thrown by the CLR, and ApplicationExceptions are thrown by Applications.


Ø  Function 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). 
Ø  Function 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.


Ø  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).


Ø  An application can have multiple web.config  files but in different directories .
Ø  Mean each and every directory can have a web.config file.

Ø  Database connection string can be stored in the web config file.

Ø  The .NET Framework provides specialized classes for data storage and retrieval.


Ø  Inheritance 
Ø  Abstraction 
Ø  Polymorphism 
Ø  Encapsulation


Ø  If  interface inheritance all the methods in the interface needs to be implemented. 
Ø  Class inheritance no need such thing.


Ø  Web.config is an xml configuration file.
Ø  It is never directly called unless we need to retrieve a configurations setting.


Ø  Server name, user id, password, database name.

Ø  The runtime host is the environment in which the CLR is started and managed.

Ø  The application level variable hold value at the application level and their instances are destroyed when the no more client access that application
Ø  whereas session correspond to a individual user accessing the application.

Ø  Virtual directory is the physical location of the application on the machine. 
Ø  By default it’s - inetpub/wwwroot

Ø  No, maintaining value in cookie won’t be possible. In that case you have to make use of other ways to maintain state of the data on page. 
Ø  you can check whether client support cookies or not by using  Request.Browser.Cookies property.

Process - Instance of the application.
Ø  Session - Instance of the user accessing the application.
Ø  Cookie  - Used for storing small amount of data on client machine.

      Serialization is a process of converting an object into a stream of bytes. 
Ø  .Net has 2 serializers namely XMLSerializer and SOAP/BINARY Serializer.
Ø  Serialization is mainly used in the concept of .Net Remoting.

Ø  Overriding - Method has the same signature as the parent class method. 

Ø  Overloading - Method having diff parameters list or type or the return type may be different.