LATEST DOT NET INTERVIEW QUESTIONS

What are Design Patterns?

A Design Pattern essentially consists of a problem in a software design and a solution to the same. In Design Patterns each pattern is described with its name, the motivation behind the pattern and its applicability.

According to MSDN, "A design pattern is a description of a set of interacting classes that provide a framework for a solution to a generalized problem in a specific context or environment. In other words, a pattern suggests a solution to a particular problem or issue in object-oriented software development.

Benefits of Design Patterns

The following are some of the major advantages of using Design Patterns in software development.

· Flexibility· Adaptability to change·Reusability

When to use Design Patterns

Design Patterns are particularly useful in one of the following scenarios.

·When the software application would change in due course of time.

·When the application contains source code that involves object creation and event notification.

When not to use Design Patterns

. Do not use design patterns in any of the following situations.

·When the software being designed would not change with time.

·When the requirements of the source code of the application are unique.

If any of the above applies in the current software design, there is no need to apply design patterns in the current design and increase unnecessary complexity in the design.

The Gang of Four (GOF) Patterns

The invention of the design patterns that we commonly use today can be attributed to the following four persons: Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides. These men invented 23 patterns in all that are commonly known as the Gang of Four patterns or the GOF patterns.

· Creational· Structural · Behavioral

Each of these groups in turn contains related sub patterns.

Creational Patterns

The Creational Patterns deals with the best possible way of creating an object or an instance of a class. They simplify object creation and provide a flexible approach towards object creation. The following are the sub-patterns that fall under this group.

·Abstract Factory ·Factory· Builder· Prototype · Singleton

Both the Abstract Factory and the Factory pattern have the same intent.

The Singleton Pattern indicates that there can be only one instance of a class throughout the Application’s life cycle. A singleton class is one that can be instantiated only once in the application domain and provides a global point of access to it.

Structural Patterns

Structural Patterns provides the flexibility to specify how objects and classes can interoperate. The following are the sub patterns that comprise the Structural Patterns group.

· Adapter·Façade · Bridge · Composite

· Decorator· Flyweight · Proxy · Adapter

· Bridge· Composite · Decorator · Flyweight

· Proxy

Behavioral Patterns

Behavioral patterns help you define a structure for inter-object communication between objects in your system. This design pattern is typically used to monitor the messages that are transmitted when the objects communicate in a system. The following are the sub patterns under Behavioral Patterns.

· Chain of Responsibility· Command · Interpreter · Iterator

· Mediator· Memento · Observer · State

· Strategy· Template Method · Visitor

ASP.NET MVC is a framework that allows developers to apply the MVC pattern in the development of an ASP.NET application, thus allowing a better separation of concerns, which results in better reusability and easier testing.

MVC consists of three kinds of objects

The Model is an application object.

The View is the screen presentation.

The controller defines the way the user interface reacts to user inputs

The request comes from the client and hits the Controller.

The Controller calls the Model in order to perform some "business" operations.

The Model returns the results of the operations back to the Controller.

The Controller decides which View needs to be rendered and sends it the data that must be rendered.

Finally the View renders the output and sends the response back to the client.

What is Cryptography?

Cryptography is used to protect data and has many valuable uses. It can protect data from being viewed, modified, or to ensure the integrity from the originator. Cryptography can be used as a mechanism to provide secure communication over an unsecured network, such as the Internet, by encrypting data, sending it across the network in the encrypted state, and then the decrypting the data on the receiving end. Encryption can also be used as an additional security mechanism to further protect data such as passwords stored in a database to prevent them from being human readable or understandable.

Encryption Components

Encryption involves the use of a cryptography algorithm combined with a key to encrypt and decrypt the data. The goal of every encryption algorithm is to make it as difficult as possible to decrypt the data without the proper key. Data is translated from its originating form into something that appears meaningless unless the proper algorithm and key are used to decrypt the data.

The Microsoft .NET Framework classes (System.Security.Cryptography) will manage the details of cryptography for you. The classes are implemented with the same interface; so working with the classes is the same across the cryptography namespace.

Public-Key Encryption

Public-key encryption, also known as asymmetric encryption, uses a public and private key pair to encrypt and decrypt data. The public key is made available to anyone and is used to encrypt data to be sent to the owner of the private key. The private key, as the name implies, is kept private. The private key is used to decrypt the data and will only work if the correct public key was used when encrypting the data. The private key is the only key that will allow data encrypted with the public key to be decrypted. The keys can be stored for use multiple times, or generated for a one-time use.

Asymmetric encryption algorithms are usually efficient for encrypting small amounts of data only. The following public-key algorithms are available for use in the .NET Framework.

Digital Signature Algorithm (DSA)

RSA

Private-Key Encryption

Private-key Encryption, also known as symmetric encryption, uses a single key to encrypt and decrypt information. The key must be kept secret from those not authorized to decrypt the data lest the data be compromised. Private-key algorithms are relatively fast and can be used to encrypt and decrypt large streams of data. Private-key algorithms are known as block ciphers because they encrypt data one block at a time. A block cipher will encrypt the same input block into the same output block based on the algorithm and key. If the anything were known about the structure of the data, patterns could be detected and the key could possibly be reverse engineered. To combat this, the classes in the .NET Framework use a process known as chaining where information from the previous block is used in encrypting the current block. This helps prevent the key from being discovered. It requires an initialization vector (IV) be given to encrypt the first block of data.

The following private-key algorithms are available in the .NET Framework. Each description contains some basic information about each algorithm, including the strengths and weaknesses.

Data Encryption Standard (DES) algorithm encrypts and decrypts data in 64-bit blocks, using a 64-bit key. Even though the key is 64-bit, the effective key strength is only 56-bits. There are hardware devices advanced enough that they can search all possible DES keys in a reasonable amount of time. This makes the DES algorithm breakable, and the algorithm is considered somewhat obsolete.

RC2 is a variable key-size block cipher. The key size can vary from 8-bit up to 64-bits for the key. It was specifically designed as a more secure replacement to DES. The processing speed is two to three times faster than DES. However, the RC2CryptoServiceProvider available in the .NET Framework is limited to 8 characters, or a 64-bit key. The 8-character limitation makes it susceptible to the same brute force attack as DES.

TripleDES algorithm uses three successive iterations of the DES algorithm. The algorithm uses either two or three keys. Just as the DES algorithm, the key size is 64-bit per key with an effective key strength of 56-bit per key. The TripleDES algorithm was designed to fix the shortcomings of the DES algorithm, but the three iterations result in a processing speed three times slower than DES alone.

Rijndael algorithm, one of the Advanced Encryption Standard (AES) algorithms, was designed as a replacement for the DES algorithms. The key strength is stronger than DES, and was designed to out perform DES. The key can vary in length from 128, 192, to 256 bits in length. This is the algorithm I personally trust the most and that I'll use for the examples contained in the column.

Hashing Algorithms

No, I'm not talking about some type of drug related activity or an extra special recipe for brownies. Hashing refers to mapping data of any length into a fixed-length byte sequence. Regardless of if the input is the contents of the library of Congress or the typing test "The quick brown fox jumps over the lazy dog" it will result in an output of the same size. Hashing also produces unique results. Just as no two snowflakes are identical, no two combinations of input will produce the same hash output. Even if the input varies by a single character it will produce different output. The .NET Framework provides support for the following hash algorithms of which I'll leave it up to you to discover which one is right for you based on the size of the data you require.

HMACSHA1 MACTripleDES MD5CryptoServiceProvider SHA1Managed

SHA256Managed SHA384Managed SHA512Managed

How to Generate a Key and IV for Private-key Encryption

Each algorithm has specific key sizes that it expects for use. Each key must fit a predetermined size typically ranging from 1 character (8-bit) up to 32 characters (256-bit). Some of the algorithms support varying key sizes, but they must be within the valid ranges of key size for the particular algorithm. For our purposes, we'll use Rijndael, which supports 128, 192, and 256 bit keys. The way to generate a 128-bit key for use is through one of the hashing algorithms. A phrase, or "secret" of any length can be hashed to generate a key of the required size for encrypting data. The following code outlines a class containing a method that takes an input phrase and generates a key and IV for use.

Using Encryption to Protect Sensitive Data Stored in a Database

This brings us to a possible and often overlooked use for encryption, which is encrypting data such as passwords that are stored in a database. There are several benefits to storing sensitive data such as passwords in encrypted format.

It keeps sensitive application data such as passwords secret from those authorized to view data that ideally should not be able to see application specific data such as passwords.

It keeps passwords protected from unauthorized access. If the database is somehow compromised, the intruder must now the correct algorithm and key to decrypt the sensitive data.

Passing direct input to a query is dangerous because you never know what the input may contain. Suppose a stored procedure including something like "WHERE vc_Login = @Login and Password = @Password" is used for authentication. A user name of "'m' or 1=1" with the same for the password could evaluate to a true statement and result in incorrectly allowing access. If the user id and or password were stored encrypted then the data would not evaluate to a valid SQL statement because an encrypted form of the statement would be used in the evaluation.

22 New Features of Visual Studio 2008 for .NET Professionals

1. LINQ Support

LINQ essentially is the composition of many standard query operators that allow you to work with data in a more intuitive way regardless.

The benefits of using LINQ are significant – Compile time checking C# language queries, and the ability to debug step by step through queries.

2. Expression Blend Support

Expression blend is XAML generator tool for silverlight applications. You can install Expression blend as an embedded plug-in to Visual Studio 2008. By this you can get extensive web designer and JavaScript tool.

3. Windows Presentation Foundation

WPF provides you an extensive graphic functionality you never seen these before. Visual Studio 2008 contains plenty of WPF Windows Presentation Foundation Library templates. By this a visual developer who is new to .NET, C# and VB.NET can easily develop the 2D and 3D graphic applications.

Visual Studio 2008 provides free game development library kits for games developers. currently this game development kits are available for C++ and also 2D/3D Dark Matter one image and sounds sets.

4. VS 2008 Multi-Targeting Support

Earlier you were not able to working with .NET 1.1 applications directly in visual studio 2005. Now in Visual studio 2008 you are able to create, run, debug the .NET 2.0, .NET 3.0 and .NET 3.5 applications. You can also deploy .NET 2.0 applications in the machines which contains only .NET 2.0 not .NET 3.x.

5. AJAX support for ASP.NET

Previously developer has to install AJAX control library separately that does not come from VS, but now if you install Visual Studio 2008, you can built-in AJAX control library. This Ajax Library contains plenty of rich AJAX controls like Menu, TreeView, webparts and also these components support JSON and VS 2008 contains in built ASP.NET AJAX Control Extenders.

6. JavaScript Debugging Support

Since starting of web development all the developers got frustration with solving javascript errors. Debugging the error in javascript is very difficult. Now Visual Studio 2008 makes it is simpler with javascript debugging. You can set break points and run the javaScript step by step and you can watch the local variables when you were debugging the javascript and solution explorer provides javascript document navigation support.

7. Nested Master Page Support

Already Visual Studio 2005 supports nested master pages concept with .NET 2.0, but the problem with this Visual Studio 2005 that pages based on nested masters can't be edited using WYSIWYG web designer. But now in VS 2008 you can even edit the nested master pages.

8. LINQ Intellisense and Javascript Intellisense support for silverlight applications

Most happy part for .NET developers is Visual Studio 2008 contains intellisense support for javascript. Javascript Intellisense makes developers life easy when writing client side validation, AJAX applications and also when writing Silverlight applications

Intellisense Support: When we are writing the LINQ Query VS provides LINQ query syntax as tool tips.

9. Organize Imports or Usings

We have Organize Imports feature already in Eclipse. SInce many days I have been waiting for this feature even in VS. Now VS contains Organize Imports feature which removes unnecessary namespaces which you have imported. You can select all the namespaces and right click on it, then you can get context menu with Organize imports options like "Remove Unused Usings", "Sort Usings", "Remove and Sort". Refactoring support for new .NET 3.x features like Anonymous types, Extension Methods, Lambda Expressions.

10. Intellisense Filtering

Earlier in VS 2005 when we were typing with intellisense box all the items were being displayed. For example If we type the letter 'K' then intellisense takes you to the items starts with 'K' but also all other items will be presented in intellisense box. Now in VS 2008 if you press 'K' only the items starts with 'K' will be filtered and displayed.

11. Intellisense Box display position

Earlier in some cases when you were typing the an object name and pressing . (period) then intellisense was being displayed in the position of the object which you have typed. Here the code which we type will go back to the dropdown, in this case sometimes programmer may disturb to what he was typing. Now in VS 2008 If you hold the Ctrl key while the intellisense is dropping down then intellisense box will become semi-transparent mode.

12. Visual Studio 2008 Split View

VS 205 has a feature show both design and source code in single window. but both the windows tiles horizontally. In VS 2008 we can configure this split view feature to vertically, this allows developers to use maximum screen on laptops and wide-screen monitors.

Here one of the good feature is if you select any HTML or ASP markup text in source window automatically corresponding item will be selected in design window.

13. HTML JavaScript warnings, not as errors:

VS 2005 mixes HTML errors and C# and VB.NET errors and shows in one window. Now VS 2008 separates this and shows javascript and HTML errors as warnings. But this is configurable feature.