Sie sind auf Seite 1von 11

Basic .NET, ASP.NET, OOPS and SQL Server Interview questions and answers: 1.

What is IL code, CLR, CTS, GAC & GC? IL: (Common Intermediate Language). All .NET source code is compiled to IL. This IL is then converted to machine code at the point where the software is installed, or at run-time by a JustIn- Time (JIT) compiler. The IL contains all the information about your application, including methods, properties, events, types, exceptions, security objects, and so on, and it also includes metadata about what types in your code can or cannot be exposed to other applications. This was called a type library in Visual Basic 6 or an IDL (interface definition language) file in C++. In .NET, it's simply the metadata that the IL contains about your assembly. The file format for the IL is known as PE (portable executable) format, which is a standard format for processor-specific execution. CLR: CLR is .NET equivalent of Java Virtual Machine (JVM). It is the runtime that converts a MSIL code into the host machine language code, which is then executed appropriately. The CLR is the execution engine for .NET Framework applications. It provides a number of services, including: - Code management (loading and execution) - Application memory isolation - Verification of type safety - Conversion of IL to native code. - Access to metadata (enhanced type information) - Managing memory for managed objects - Enforcement of code access security - Exception handling, including cross-language exceptions - Interoperation between managed code, COM objects, and pre-existing DLL's (unmanaged code and data) - Automation of object layout - Support for developer services (profiling, debugging, and so on). CTS defines all of the basic types that can be used in the .NET Framework and the operations performed on those type. All this time we have been talking about language interoperability, and .NET Class Framework. None of this is possible without all the language sharing the same data types. What this means is that an int should mean the same in VB, VC++, C# and all other .NET compliant languages. This is achieved through introduction of Common Type System (CTS). GAC (Global Assembly Cache) is used where shared .NET assembly reside. GAC is used in the following situations: - If the application has to be shared among several application. If the assembly has some special security requirements like only administrators can remove the assembly. If the assembly is private then a simple delete of assembly the assembly file will remove the assembly.

Garbage collection is a CLR feature which automatically manages memory. Programmers forget to release the objects while coding ..... Laziness (Remember in VB6 where one of the good practices is to set object to nothing). CLR automatically releases objects when they are no longer in use and refernced. CLR runs on non-deterministic to see the unused objects and cleans them. One side effect of this non-deterministic feature is that we cannot assume an object is destroyed when it goes out of the scope of a function. Therefore, we should not put code into a class destructor to release resources. 2. How can we do Assembly versioning? Each assembly has a version number as part of its identity. As such, two assemblies that differ by version number are considered by the runtime to be completely different assemblies. This version number is physically represented as a four-part string with the following format: <major version>.<minor version>.<build number>.<revision> For example, version 1.5.1254.0 indicates 1 as the major version, 5 as the minor version, 1254 as the build number, and 0 as the revision number. The version number is stored in the assembly manifest along with other identity information, including the assembly name and public key, as well as information on relationships and identities of other assemblies connected with the application. When an assembly is built, the development tool records dependency information for each assembly that is referenced in the assembly manifest. The runtime uses these version numbers, in conjunction with configuration information set by an administrator, an application, or a publisher, to load the proper version of a referenced assembly. The runtime distinguishes between regular and strong-named assemblies for the purposes of versioning. Version checking only occurs with strong-named assemblies. 3. Can you explain how ASP.NET application life cycle and page life cycle events fire? Life cycle of an ASP .NET page: Stage Events/Method Page Initialization Page_Init View State Loading LoadViewState Postback data processin LoadPostData Page Loading Page_Load PostBack Change Notification RaisePostDataChangedEvent PostBack Event Handling RaisePostBackEvent Page Pre Rendering Phase Page_PreRender View State Saving SaveViewState Page Rendering Page_Render Page Unloading Page_UnLoad

4. What is the problem with Functional Programming? Most people find functional programming to be difficult to understand. This means it will probably be harder for you to write functional code, and it will almost certainly be harder for someone else to pick it up. Functional programming languages are usually slower than a language like c would be. This is becoming less of an issue over time (because computers are getting faster, and compilers are getting smarter) Not being as wide spread as their imperative counterparts, it can be difficult to find libraries and examples for common programming problems. (For example its almost always easier to find something for Python, then it is for Haskell) There's a lack of tools, particularly for debugging. Its definitely not as easy as opening up Visual Studio for C#, or eclipse for Java. 5. Can you define OOP and the 4 principles of OOP? It is a problem solving technique to develop software systems. It is a technique to think real world in terms of objects. Object maps the software model to real world concept. These objects have responsibilities and provide services to application or other objects. Following are characteristics of Object Oriented Systems :1) Encapsulation : Hiding internal implementation of the objects and provide global interface access to object. 2) Inheritance : The ability of a class to reuse the members and member functions of its base class. 3) Polymorphism : The ability of the objects to be represented in multiple forms. This is possible with overriding and overloading. 4) Abstraction : Describing an object with its unique and relevant characteristics according to specific need. 6. What are Classes and Objects? Class: A class describes all the attributes of objects, as well as the methods that implement the behaviour of member objects. Its a comprehensive data type which represents a blue print of objects. Its a template of object. Object: It is a basic unit of a system. An object is an entity that has attributes, behavior, and identity. Objects are members of a class. Attributes and behavior of an object are defined by the class definition. 7. What is Inheritance? Inheritance: Hierarchy is used to define more specialized classes based on a preexisting generalized class. Example we have VEHICLE class and we can inherit this class make more specialized class like CAR, which will add new attributes and use some existing qualities of the parent class. Its shows more of a parent-child relationship. This kind of hierarchy is called inheritance. 8. What is Polymorphism, overloading, overriding and virtual?

Overloading: Method name remains the same with different signatures. Overriding: Method name and Signatures must be the same. 9. What is an abstract class? Following are features of a abstract class:You cannot create a object of abstract class. Abstract class is designed to act as a base class (to be inherited by other classes). Abstract class is a design concept in program development and provides a base upon which other classes are built. Abstract classes are similar to interfaces. After declaring an abstract class, it cannot be instantiated on its own, it must be inherited. In VB.NET abstract classes are created using MustInherit keyword. In C# we have Abstract keyword. Abstract classes can have implementation or pure abstract methods which should be implemented in the child class. 10. Define Interface & what is the diff. between abstract & interface? Interface is a contract that defines the signature of the functionality. So if a class is implementing an interface it says to the outer world, that it provides specific behaviour. Example if a class is implementing Idisposable interface that means it has a functionality to release unmanaged resources. Now external objects using this class know that it has contract by which it can dispose unused unmanaged objects. Single Class can implement multiple interfaces. If a class implements a interface then it has to provide implementation to all its methods. Following are the differences between abstract and interfaces: Abstract classes can have concrete methods while interfaces have no methods implemented. Interfaces do not come in inheriting chain, while abstract classes come in inheritance. 11. What problem does Delegate Solve? Delegate is a class that can hold a reference to a method or a function. Delegate class has a signature and it can only reference those methods whose signature is compliant with the class. Delegates are type-safe functions pointers or call backs. 12. What is a Multicast delegate? It is a delegate that points to and eventually fires off several methods. 13. What are events and what's the difference between delegates and events? Actually events use delegates in bottom. But they add an extra layer on the delegates, thus forming the publisher and subscriber model. As delegates are function to pointers they can move across any clients. So any of the clients can add or remove events, which can be pretty confusing. But events give the extra protection by adding the layer and making it a publisher and subscriber model. Just imagine one of your clients doing this

c.XyzCallback = null This will reset all your delegates to nothing and you have to keep searching where the error is. 14. How can we make Asynchronous method calls using delegates ? A delegate is a special method that encapsulates a method and represents a method signature. From the main thread, when a method is invoked using a delegate, the Main thread has to wait until the method, that was invoked, has completed. This could prove expensive if your code is performing a slow operation like downloading a large file from your server. As you can see, the Main method has to wait until the method SquareMethod completes. This is because SquareMethod was executed on the same thread, as that of the Main method. you can use delegates to call any method asynchronously This is done using the BeginInvoke and EndInvoke methods of the Delegate class. BeginInvoke, EndInvoke and IAsyncResult The BeginInvoke method initiates the asynchronous call on a separate thread taken from the ThreadPool. It consists the same parameters required by the method (that you want to execute asynchronously) and consists two additional optional parameters called the callback parameter and the state parameter. The advantage of using BeginInvoke is that it returns immediately and does not wait for the asynchronous call to complete. BeginInvoke returns a reference to an object implementing the IAsyncResult interface, which can be used to monitor the progress of the asynchronous call. The EndInvoke method retrieves the results of the asynchronous call and releases the resource used by the thread. The parameters of EndInvoke include the out and ref parameters of the method that you want to execute asynchronously, plus a reference to the IAsyncResult returned by the BeginInvoke. If the BeginInvoke() and EndInvoke() are not clear yet, worry not, as we will see an example shortly. Call a Method Asynchronously using Delegate Now that you know how the BeginInvoke and EndInvoke methods of the Delegate class work, let us see the different ways/patterns available to use BeginInvoke() and EndInvoke() to make asynchronous calls EndInvoke Pattern - In this pattern, we use BeginInvoke from the Main thread to call the method, then do some processing on the main thread and then call EndInvoke(). This is useful when you want to have the calling thread to continue processing at the same time the asynchronous call is executing. Here the EndInvoke() does not return until the asynchronous call has completed. In other words, the main thread waits till the asynchronous operation is complete.

WaitHandle Using this technique, the main method calls the method asynchronously and waits for a WaitHandle before it calls EndInvoke(). Polling Pattern - In this pattern, the calling thread polls the other thread (doing async operation) periodically using the IAsyncResult object and checks whether the thread has completed. If not, it continues processing and checks the thread later. The application does not call EndInvoke() until it knows that the operation is complete. This pattern can be useful when you want your UI to be responsive, till the async operation completes. Callback Pattern - In this pattern, the initial thread initiates the async call but does not wait or check to see if the thread that was called, has completed. This pattern can be useful if you not want to process the results of the async call in the main thread. Let us see an example of calling a method asynchronously using the EndInvoke Pattern

As you can see, BeginInvoke() is used to initiate the asynchronous call, which returns immediately after the call is made, so the Main method can continue processing while the async operation executes. The BeginInvoke() returns an IAsyncResult object to the calling thread. IAsyncResult asyncRes = sd.BeginInvoke(10, null, null); We then use the EndInvoke() function to retrieve the results of the asynchronous call. The EndInvoke() has a parameter that is a reference to the IAsyncResult, returned by the BeginInvoke. int res = sd.EndInvoke(asyncRes);

EndInvoke() uses this parameter to find the thread it refers to, which can be used to monitor the progress of the asynchronous call.

15. What is a stack, Heap, Value types and Reference types ? Value types: Value types directly contain their data which are either allocated on the stack or allocated in-line in a structure. Reference types store a reference to the value's memory address, and are allocated on the heap. Reference types: Reference types can be self-describing types, pointer types, or interface types. Variables that are value types each have their own copy of the data, and therefore operations on one variable do not affect other variables. Variables that are reference types can refer to the same object; therefore, operations on one variable can affect the same object referred to by another variable. All types derive from the System.Object base type. 16. What is boxing and unboxing ? Boxing permits any value type to be implicitly converted to type object or to any interface type implemented by value type. Boxing is a process in which object instances are created and copy values in to that instance. Unboxing is vice versa of boxing operation where the value is copied from the instance in to appropriate storage location. Below is sample code of boxing and unboxing where integer data type is converted in to object and then vice versa. Dim x As Integer Dim y As Object x = 10 boxing process 17. Can you explain ASP.NET application and Page life cycle ? PreInit This event is the beginning of the page life cycle. All page controls are initialized and the properties are set according to the aspx source code.

Possible to change or set Master page, themes Creates or re-creates dynamic controls Reads or sets Profile property values

Init First, the Init event for the Page object occurs, then Init event occurs for each control on the Page. Viewstate information is not available at this stage.

Controls have been initialized Theme skins applied if any

Initialize control properties

InitComplete This event is used for processing tasks that require all initialization to be complete. PreLoad This event is used before performing any processing that should occur before Load. Use this event if you need to perform processing on your page or control before the Load event. Before the Page instance raises this event, it loads view state for itself and all controls, and then processes any postback data included with the Requestinstance. Load Set properties in controls and establish database connections. Control Events These are control specific events such as Button Click, DropDownIndexChanged, etc. Load Complete This event is used for performing those tasks which require load has been completed. PreRender In this event, Page ensures that all child controls are created. Page calls EnsureChildControls for all controls, including itself. Every control whose datasource/databind property is set calls for its databind method. SaveStateComplete This event occurs after viewstate is encoded and saved for the page and for all controls. Render Every ASP.NET control has render method and the page instance calls this method to output the controls markup, after this event any changes to the page or controls are ignored. Unload Unload event is used to do cleanup tasks like closing the database connections, closing of the open files, completing logging or other requested tasks. Unload events occurs for each control on page control tree first and after that page.

18. What is Authentication, Authorization, Principal & Identity objects? Authentication is the process by which the identity of the user is verified and authorization is the process by which access to an application/feature is granted based on the identity. Identity: This object stores information about the user. This object encapsulates the name of the user being authenticated. We can relate this object to a data store which stores information (User Name) about a user. Identity objects are of two types.

WindowsIdentity: This object encapsulates the Windows login user name and the type of protocol adopted for authentication by Windows. Anytime we need to know the Windows login username, WindowsIdentity objects have the information. GenericIdentity: also stores information about a user, but is used when an application needs to implement custom logon. This object can be created by specifying the User name (usually accepted via custom logon screens) and can be propagated across various application tiers for authorization purposes.

We shall be discussing more in detail about this at a later stage in this article. Principal: This object represents the security context for the running process or the AppDomain. Each thread has a context and it holds the principal object. Principal objects encapsulate Identity and the Role/Group membership of a user. Role based security can best be implemented with the help of Principal objects. A Principal object can be created with the help of identity and role of a user. Principal objects are very handy while implementing role based authorization for an application. Principal objects are of two types:

GenericPrincipal: This object encapsulates the identity object and the role. While implementing custom logon with role based authorization, GenericPrincipal objects are to be created. WindowsPrincipal: also stores identity and the Windows group membership of the user. This would very much qualify to implement role based security for an application.

19. How can we do Inproc and outProc session management ? The OutProc is of two types: State Server and SQL Server. For State Server <sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:55455" sqlConnectionString="data source=127.0.0.1;user id=sa;password='' cookieless="false" timeout="20"/> The attributes are self explanatory but I will go over them.

mode: This can be StateServer or SqlServer. Since we are using StateServer we set the mode to StateServer. stateConnectionString: connectionString that is used to locate the State Service. sqlConnectionString: The connection String of the sql server database. cookieless: Cookieless equal to false means that we will be using cookies to store the session on the client side. For SQL Server <sessionState mode = "SqlServer" stateConnectionString="tcpip=127.0.0.1:45565" sqlConnectionString="data source="SERVERNAME;user id=sa;password='' cookiesless="false" timeout="20"/>

20. How can we windows , forms and passport authentication and authorization in ASP.NET ? The authentication option for the ASP.NET application is specified by using the tag in the Web.config file, as shown below: other authentication options: 1. WINDOWS AUTHENTICATION Schemes I. Integrated Windows authentication II. Basic and basic with SSL authentication III. Digest authentication IV. Client Certificate authentication 2. FORMS AUTHENTICATION You, as a Web application developer, are supposed to develop the Web page and authenticate the user by checking the provided user ID and password against some user database 3. PASSPORT AUTHENTICATION A centralized service provided by Microsoft, offers a single logon point for clients. Unauthenticated users are redirected to the Passport site 4. NONE/CUSTOM AUTHENTICATION: If we dont want ASP.NET to perform any authentication, we can set the authentication mode to none. The reason behind this decision could be: We dont want to authenticate our users, and our Web site is open for all to use. We want to provide our own custom authentication

21. In a parent child relationship which constructor fires first?

Parent constructor is executes first. It's because of the hierarchy of objects. Parent is being processed first, child later. It's very logical, because child do have all properties of parent so it's obvious that parent must be created first. If base class has different constructor than child, you can call it explicit like this: Public Class Class1 Public Sub New() End Sub End Class

Public Class Class2 Inherits Class1 Public Sub New(param As Integer) MyBase.New() End Sub End Class

Das könnte Ihnen auch gefallen