Monday, August 5, 2013

.Net Interview Questions Advanced


.Net Interview Questions Advanced

 

Q1.Does JITting occur per-assembly or per-method? How does this affect the working set?

Per method. Methods that are not called are not compiled thus reducing impact on the working set.

In the context of a comparison, what is object identity versus object equivalence?

1)       Two objects are identical if they share same address in memory.Two objects are equivalent if they are instances of the same type and every field of the first object matches the fields of another object.

2)Object identical have only same instances. Object equivalent have fields are same but the different instances only type are same.

Generally speaking, two objects are identical if they share the same address in memory. This means that they are both referring to the same instance of a class. You can test if two objects are identical by using the ReferenceEquals static method of System.Object: Object.ReferenceEquals(myFirstObject, mySecondObject).

On the other hand, two objects are equivalent if they are instances of the same type and if every field of the first object matches the value of the same field of the second object. Being equivalent does not imply that the objects are identical: they can be independent instances, but their fields should have the same value. Because testing for equivalence can and probably will be different for most types, there is no global solution. For this purpose System.Object provides the virtual (overridable) method Equals to determine if two objects are equal.

The interesting thing is that if you don't override the virtual method Equals of System.Object when creating your own objects, the virtual method Equals looks like this:

[code=cs]

class Object {

public virtual Boolean Equals(Object obj) {

 

// If both references point to the same

// object, they must be equal.

if (this == obj) return (true);

 

// Assume that the objects are not equal.

return (false);

}

...

}

[/code]

So really, the virtual method Equals of System.Object only tests if the two objects are identical (share the same address in memory) not equivalent.  You will need to override this method if you want Equals to act any differently.

Did you ever think of System.String class. Being it is a reference type, instead of checking for same memory address (object identity), it checks for content (object equivalent). Right? But how? Microsoft did the same, they overrided the virtual method Equals of System.Object in the System.String class.

What is hiding in CSharp ?


Hiding is also called as Shadowing. This is the concept of Overriding the methods. It is a concept used in the Object Oriented Programming.

E.g.
public class ClassA {
public virtual void MethodA() {
Trace.WriteLine("ClassA Method");
}
}

Public class ClassB : ClassA {
public new void MethodA() {
Trace.WriteLine("SubClass ClassB Method");
}
}

public class TopLevel {
static void Main(string[] args) {
TextWriter tw = Console.Out;
Trace.Listeners.Add(new TextWriterTraceListener(tw));

ClassA obj = new ClassB();
obj.MethodA(); // Outputs “Class A Method"

ClassB obj1 = new ClassB();
obj.MethodA(); // Outputs “SubClass ClassB Method”
}
}

What is the difference between an XML "Fragment" and an XML "Document."
An XML fragment is an XML document with no single top-level root element. To put it simple it is a part (fragment) of a well-formed xml document. (node) Where as a well-formed xml document must have only one root element.

What does it meant to say “the canonical” form of XML?

"The purpose of Canonical XML is to define a standard format for an XML document. Canonical XML is a very strict XML syntax, which lets documents in canonical XML be compared directly.
Using this strict syntax makes it easier to see whether two XML documents are the same. For example, a section of text in one document might read Black & White, whereas the same section of text might read Black & White in another document, and even in another. If you compare those three documents byte by byte, they'll be different. But if you write them all in canonical XML, which specifies every aspect of the syntax you can use, these three documents would all have the same version of this text (which would be Black & White) and could be compared without problem.
This Comparison is especially critical when xml documents are digitally signed. The digital signal may be interpreted in different way and the document may be rejected.



Why is the XML InfoSet specification different from the Xml DOM? What does the InfoSet attempt to solve?

"The XML Information Set (Infoset) defines a data model for XML. The Infoset describes the abstract representation of an XML Document. Infoset is the generalized representation of the XML Document, which is primarily meant to act as a set of definitions used by XML technologies to formally describe what parts of an XML document they operate upon.
The Document Object Model (DOM) is one technology for representing an XML Document in memory and to programmatically read, modify and manipulate a xml document.
Infoset helps defining generalized standards on how to use XML that is not dependent or tied to a particular XML specification or API. The Infoset tells us what part of XML Document should be considered as significant information.

Contrast DTDs versus XSDs. What are their similarities and differences? Which is preferred and why?

Document Type Definition (DTD) describes a model or set of rules for an XML document. XML Schema Definition (XSD) also describes the structure of an XML document but XSDs are much more powerful.
The disadvantage with the Document Type Definition is it doesn’t support data types beyond the basic 10 primitive types. It cannot properly define the type of data contained by the tag.

An Xml Schema provides an Object Oriented approach to defining the format of an xml document. The Xml schema support most basic programming types like integer, byte, string, float etc., We can also define complex types of our own which can be used to define a xml document.
Xml Schemas are always preferred over DTDs as a document can be more precisely defined using the XML Schemas because of its rich support for data representation.

Speaking of Boolean data types, what's different between C# and C/C++?
There's no conversion between 0 and false, as well as any other number and true, like in C/C++.

How do you convert a string into an integer in .NET?

Int32.Parse(string)

Can you declare a C++ type destructor in C# like ~MyClass()?

Yes, but what's the point, since it will call Finalize(), and Finalize() has no guarantees when the memory will be cleaned up, plus, it introduces additional load on the garbage collector.

What's different about namespace declaration when comparing that to package declaration in Java?

No semicolon.

What's the difference between const and readonly?

The readonly keyword is different from the const keyword. A const field can only be initialized at the declaration of the field. A readonly field can be initialized either at the declaration or in a constructor. Therefore, readonly fields can have different values depending on the constructor used. Also, while a const field is a compile-time constant, the readonly field can be used for runtime constants as in the following example:
public static readonly uint l1 = (uint) DateTime.Now.Ticks;

What does \a character do?
On most systems, produces a rather annoying beep.

Can you create enumerated data types in C#?
Yes.

What's different about switch statements in C#?

No fall-throughs allowed.

What happens when you encounter a continue statement inside the for loop?

The code for the rest of the loop is ignored, the control is transferred back to the beginning of the loop.

How can you sort the elements of the array in descending order?

By calling Sort() and then Reverse() methods.

Will finally block get executed if the exception had not occurred?

Yes.

What's the C# equivalent of C++ catch (…), which was a catch-all statement for any possible exception?

A catch block that catches the exception of type System.Exception. You can also omit the parameter data type in this case and just write catch {}.

Can multiple catch blocks be executed?


No, once the proper catch code fires off,

the control is transferred to the finally block (if there are any), and then whatever follows the finally block.

Why is it a bad idea to throw your own exceptions?

Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project

1. Write a simple Windows Forms MessageBox statement.

2.System.Windows.Forms.MessageBox.Show


3.("Hello, Windows Forms");

4. Can you write a class without specifying namespace? Which namespace does it belong to by default??
    Yes, you can, then the class belongs to global namespace which has no name. For commercial products, naturally, you wouldn’t want global namespace.
5. You are designing a GUI application with a window and several widgets on it.

4. The user then resizes the app window and sees a lot of grey space, while the widgets stay in place. What’s the problem? One should use anchoring for correct resizing. Otherwise the default property of a widget on a form is top-left, so it stays at the same location when resized.
5. How can you save the desired properties of Windows Forms application?

.config files in .NET are supported through the API to allow storing and retrieving information. They are nothing more than simple XML files, sort of like what .ini files were before for Win32 apps.

4. So how do you retrieve the customized properties of a .NET application from XML .config file? Initialize an instance of AppSettingsReader class. Call the GetValue method of AppSettingsReader class, passing in the name of the property and the type expected. Assign the result to the appropriate variable.
5. Can you automate this process? In Visual Studio yes, use Dynamic Properties for automatic .config creation, storage and retrieval.


6. My progress bar freezes up and dialog window shows blank, when an intensive background process takes over. Yes, you should’ve multi-threaded your GUI, with taskbar and main form being one thread, and the background process being the other.
7. What’s the safest way to deploy a Windows Forms app? Web deployment: the user always downloads the latest version of the code; the program runs within security sandbox, properly written app will not require additional security privileges.
8. Why is it not a good idea to insert code into InitializeComponent method when working with Visual Studio? The designer will likely throw it away; most of the code inside InitializeComponent is auto-generated.


9. What’s the difference between WindowsDefaultLocation and WindowsDefaultBounds? WindowsDefaultLocation tells the form to start up at a location selected by OS, but with internally specified size. WindowsDefaultBounds delegates both size and starting position choices to the OS.
10. What’s the difference between Move and LocationChanged? Resize and SizeChanged? Both methods do the same, Move and Resize are the names adopted from VB to ease migration to C#.
11. How would you create a non-rectangular window, let’s say an ellipse? Create a rectangular form, set the TransparencyKey property to the same value as BackColor, which will effectively make the background of the form transparent. Then set the FormBorderStyle to FormBorderStyle.None, which will remove the contour and contents of the form.
12. How do you create a separator in the Menu Designer? A hyphen ‘-’ would do it. Also, an ampersand ‘&\’ would underline the next letter.
13. How’s anchoring different from docking? Anchoring treats the component as having the absolute size and adjusts its location relative to the

parent form. Docking treats the component location as absolute and disregards the component size. So if a status bar must always be at the bottom no matter what, use docking. If a button should be on the top right, but change its position with the form being resized, use anchoring

1. What is the difference between a Struct and a Class?
Ans.
Structs are value-type variables and are thus saved
on the stack -> additional overhead but faster retrieval. Another difference is that structs CANNOT inherit.  Classes are reference types and structs are value types. Since classes are reference type, a class variable can be assigned null.But we cannot assign null to a struct variable, since structs are value type.

struct AStruct
{  
  int aField;
}

class  AClass
{  
   int aField;
}

class MainClass
{
   public static void Main()
   { 
       AClass b = null;  // No error.
       AStruct s = null; // Error
/* [ Cannot convert null to 'AStruct' because  it is
a value type ].*/
   }
}

 When you instantiate a class, it will be allocated on the heap.When you instantiate a struct, it gets created on the stack. You will always be dealing with reference to an
object ( instance ) of a class. But you will not be dealing
with references to an instance of a struct ( but dealing directly with them ).

When passing a class to a method, it is passed by
reference. When passing a struct to a method, it's passed
by value instead of as a reference.

You cannot have instance Field initializers in structs.
But  classes can have initializers.

class MyClass
{
  int myVar =10;    //  no syntax error.   
  public void MyFun( )   
  { 
     //  statements   
  }
}

struct MyStruct
{   
  int myVar = 10;  //syntax error
  public void MyFun( )   
  {
        //  statements   
  }
}

Classes can have explicit parameterless constructors.
But structs cannot have explicit parameterless constructors.

class MyClass
{  
  int myVar = 10;  
  public MyClass( ) // no syntax error. 
  {
     // statements  
  }
}

struct MyStruct
{  
  int myVar;  
  public MyStruct( ) // syntax error.  
  {
       // statements  
  }
}

Classes must be instantiated using the new operator. But structs can be instantiated without using the new operator.

MyClass aClassObj;
/*  MyClass aClassObj=new MyClass(); is the correct
format.aClassObj.myVar=100;//NullReferenceException
(because aClassObj does not contain a reference to an object
of type myClass). */

MyStruct  aStructObj;aStructObj.myVar=100;// no exception.

Classes support inheritance.But there  is no inheritance for structs. ( structs don't support inheritance polymorphism )

(1)
struct MyStruct
{
 int aStructVar;
 internal void aStructMethod()
 {
   // statements
 }
}

class MyClass : MyStruct   // Syntax error.
{
  int aClassVar;
  int aClassMethod()
  {
     // statements
  }
}


(2)
class MyClass
{
  int aClassVar;
  int aClassMethod()
  {
     // statements
  }
}

struct MyStruct : MyClass   // Syntax error.
{
  int aStructVar;
  internal void aStructMethod()
  {
    // statements
  }
}

Since struct does not support inheritance, access modifier
of a member of a struct cannot be  protected or protected
internal. It is not mandatory to initialize all Fields inside
the constructor of a class. But all the Fields of a struct 
must be fully initialized inside the constructor.

class MyClass //No error( No matter whether the Field
                   //'MyClass.myString' is initialized or not ).
{  
  int  myInt;  
  string myString;
  public MyClass( int aInt )
  {
     myInt = aInt;  
  }
}

struct MyStruct // Error ( Field ' MyStruct.myString ' must
            //be fully assigned before it leaves the constructor ).
{
   int myInt;
   string myString;
   public MyStruct( int aInt )
   {      myInt = aInt;
   }
}
 

A class is permitted to declare a destructor.But a struct is not permitted to declare a destructor.

struct MyStruct
{   
  int myInt;
  public MyStruct( )  
  {    }    ~MyStruct( )   //Error.
  {
    Console.WriteLine("Destructor of MyStruct object");
  }
}

class MyClass
{
    int myInt;
    public MyClass( )    {    }    ~MyClass( ) // No Error.
    { 
       Console.WriteLine("Destructor of MyClass object");      }
}

Classes are used for complex and large set data. structs are
simple to use. structs are useful whenever you  need a type that will be used often and is mostly just a piece of data.

 

2. What does the term immutable mean?
Ans.
It means to create a view of data that is not
modifiable and is temporary of data that is
modifiable.

Immutable means you can't change the currrent data,
but if you perform some operation on that data, a
new copy is created. The operation doesn't change
the data itself. Like let's say you have a string
object having "hello" value. Now if you say

temp = temp + "new value"

a new object is created, and values is saved in that.
The temp object is immutable, and can't be changed.

An object qualifies as being called immutable if its value
cannot be modified once it has been created. For example,
methods that appear to modify a String actually return a new
String containing the modification.  Developers are
modifying strings all the time in their code.  This may
appear to the developer as mutable - but it is not.  What
actually happens is your string variable/object has been
changed to reference a new string value containing the
results of your new string value.  For this very reason
.NET has the System.Text.StringBuilder class.  If you find
it necessary to modify the actual contents of a string-like object heavily, such as in a for or foreach loop, use the System.Text.StringBuilder class.

3. Can we have private constructor? When can I
use them? When should we implement a private constructor?

Ans. Private constructors would be mainly used for singleton
patterns and for classes that are module-like
(only static/shared methods/attributes)

The idea of the singleton is that you don't have a public
constructor, specifically to prevent people from
instantiating more than one of them. You call a
non-constructor method to return the singleton instance.
If it doesn't exist, the method calls the private
constructor to create it. Then it returns a reference
to the singleton instance.

An example below...

// .NET Singleton
sealed class Singleton
{
 private Singleton() {}
 public static readonly Singleton Instance = new Singleton();
}

Obviously you'd need to add some properties and methods to get something useful, but you get the idea. Watch out for
thread safety issues.


4.Explain the differences between Server-side and
Client-side code?
Ans.
Server side code will execute at server end
all the business logic will execute at server end
where as client side code will execute at client side
at browser end. Usually, scripts like Javascript,
VBScript & JScript etc. take care of client side
funtions.

5. What type of code (server or client) is found in
a Code-Behind class?
Ans.
Server side.

6.Should validation (Did the user enter a real date?)
occur server-side or client-side? Why?
Ans.
Ideally it should occur client-side. It saves round-trip to server & thus saves time!!!  It also avoids SQL Injections from malicious users. SQL injection is a security vulnerability that occurs in the database layer of an application. The vulnerability
is present when user input is either incorrectly filtered
for string literal escape characters embedded in SQL
statements or user input is not strongly typed and thereby
unexpectedly executed. It is in fact an instance of a more
general class of vulnerabilities that can occur whenever
one programming or scripting language is embedded inside another.

Validation is usually done using client-side script like
javascript, jscript, vbscript (javascript being the most
popular due to browser compatibility).

.NET provides 5 + 1 controls for validation
1- RequiredFieldValidator
2- RangeValidator
3- RegularExpressionValidator
4- CompareValidator
5- CustomValidator
 and the ValidationSummary Control

7.What does the "EnableViewState" property do? Why
would I want it on or off?
Ans.
It keeps the data of the control during post backs.
if we turn off, the values should not populate during
server round trip. Basically its used to sustain value
of control's attributes betwen postbacks.

When a form is submitted in classic ASP, all form values
are cleared. Suppose you have submitted a form with a lot of information and the server comes back with an error. You will
have to go back to the form and correct the information. You click the back button, and what happens.......
ALL form values are CLEARED, and you will have to start all
over again! The site did not maintain your ViewState.

When a form is submitted in ASP .NET, the form reappears in
the browser window together with all form values. How come?
This is because ASP .NET maintains your ViewState. The ViewState indicates the status of the page when submitted to the server.

The status is defined through a hidden field placed on each page
with a <form runat="server"> control.

Maintaining the ViewState is the default setting for ASP.NET
Web Forms. If you want to NOT maintain the ViewState, include the directive <%@ Page EnableViewState="false" %> at the top of an .aspx page or add the attribute EnableViewState="false" to any control.

8. What is the difference between Server.Transfer and
Response.Redirect? Why would I choose one over the other?

Ans. Server.Transfer will prevent round trip. it will
redirect pages which or in the same directory. NO way to
pass the query strings . Thru http context we can able
to get the previous page control values.

Response.Redirect : There is a round trip to process the
request. We can redirect to any page external / internal
other than aspx. We can pass the query string thru which we
can manage sessions.

A common misconception is the difference between Server.Transfer and Response.Redirect in ASP.NET applications. Redirect and Transfer both cause a new page to be processed, but the interaction between the client (web browser) and server
(ASP.NET) is different in each situation.

Redirect: A redirect is just a suggestion – it’s like saying
to the client “Hey, you might want to look at this”. All you tell the client is the new URL to look at, and if they comply,
they do a second request for the new URL.

If you want to pass state from the source page to the new
page, you have to pass it either on the URL (such as a database key, or message string), or you can store it in the Session
object (caveat: there may be more than one browser window, and they’ll all use the same session object).

e.g. Redirect to the new.aspx page, passing an ID on the
query string. "true" stops processing the current page:

Response.Redirect("new.aspx?id=32", true);

Transfer: A transfer happens without the client knowing
– it’s the equivalent of a client requesting one page,
but being given another. As far as the client knows, they
are still visiting the original URL.

Sharing state between pages is much easier using
Server.Transfer – you can put values into the Context.Items
dictionary, which is similar to Session and Application,
except that it lasts only for the current request. (search
for HttpContext in MSDN). The page receiving postback can
process data, store values in the Context, and then Transfer
to a page that uses the values. e.g. Store a message in the context dictionary, and transfer to the default.aspx page (which can then display the message):

Context.Items["Message"] = "Your password was changed successfully";
Server.Transfer("default.aspx");

Response.Redirect is more user-friendly, as the site visitor can
bookmark the page that they are redirected to. Transferred pages appear to the client as a different url than they really are.
This means that things like relative links/image paths may not
work if you transfer to a page from a different directory.
Server.Transfer has an optional parameter to pass the form data
to the new page. Since the release version, this no longer works, because the Viewstate now has more security by default (The
EnableViewStateMac defaults to true), so the new page isn’t able to access the form data. You can still access the values of the original page in the new page, by requesting the original handler:

Page originalPage = (Page)Context.Handler;

TextBox textBox1 = (TextBox)originalPage.FindControl("textBox1");

 

9. Can you give an example of when it would be appropriate
to use a web service as opposed to a non-serviced .NET
component.
Ans.
Web service is one of main component in Service Oriented
Architecture. You could use web services when your clients and servers are running on different networks and also different platforms. This provides a loosely coupled system. And also if the client is behind the firewall it would be easy to use web service since it runs on port 80 (by default) instead of having some thing else in Service Oriented Architecture applications.
What is the standard you use to wrap up a call to a Web service?
Ans. SOAP.

Web services are best suite for Hetrogenious
environment. Remoting is best suite for Homogenious environment where the system is under CLR.

10. Let's say I have an existing application written using
Visual Studio 6 (VB 6, InterDev 6) and this application utilizes Windows 2000 COM+ transaction services. How would you approach migrating this application to .NET?

Ans. .NET has made excellent use of the existing COM+
Technology to provide component features like instance management, transactions, activity-based synchronization,
granular role-based security, disconnected asynchronous queued
components, and loosely coupled events. This integration is a
big leap forward, providing greater flexibility to developers
through code.

The .NET components, which make use of the COM+ Services, are termed as ServicedComponents. Must read this link to learn more : http://msdn2.microsoft.com/en-us/library/ms973809.aspx


11. Can you explain the difference between an ADO.NET
Dataset and ADO Recordset?
Ans.
In ADO, the in-memory representation of data is the
recordset. In ADO.NET, it is the dataset. There are important differences between them.

Number of Tables
A recordset looks like a single table. If a recordset is to contain data from multiple database tables, it must use a JOIN query, which assembles the data from the various database tables into a single result table. In contrast, a dataset is a collection of one or more tables. The tables within a dataset are called data tables; specifically, they are DataTable objects. If a dataset contains data from multiple database tables, it will typically contain multiple DataTable objects. That is, each DataTable object typically corresponds to a single database table or view. In this way, a dataset can mimic the structure of the underlying database.

A dataset usually also contains relationships. A relationship within a dataset is analogous to a foreign-key relationship in a database —that is, it associates rows of the tables with each other. For example, if a dataset contains a table about investors and another table about each investor's stock purchases, it could also contain a relationship connecting each row of the investor table with the corresponding rows of the purchase table. Because the dataset can hold multiple, separate tables and maintain information about relationships between them, it can hold much richer data structures than a recordset, including self-relating tables and tables with many-to-many relationships.


Data Navigation and Cursors
In ADO you scan sequentially through the rows of the recordset using the ADO MoveNext method. In ADO.NET, rows are represented as collections, so you can loop through a table as you would through any collection, or access particular rows via ordinal or primary key index. DataRelation objects maintain information about master and detail records and provide a method that allows you to get records related to the one you are working with. For example, starting from the row of the Investor table for "Nate Sun," you can navigate to the set of rows of the Purchase table describing his purchases.

A cursor is a database element that controls record navigation, the ability to update data, and the visibility of changes made to the database by other users. ADO.NET does not have an inherent cursor object, but instead includes data classes that provide the functionality of a traditional cursor. For example, the functionality of a forward-only, read-only cursor is available in the ADO.NET DataReader object. For more information about cursor unctionality, see Data Access Technologies.

Minimized Open Connections
In ADO.NET you open connections only long enough to perform a database operation, such as a Select or Update. You can read rows into a dataset and then work with them without staying connected to the data source. In ADO the recordset can provide disconnected access, but ADO is designed primarily for connected access.

There is one significant difference between disconnected processing in ADO and ADO.NET. In ADO you communicate with the database by making calls to an OLE DB provider. In ADO.NET you communicate with the database through a data adapter (an OleDbDataAdapter, SqlDataAdapter, OdbcDataAdapter, or OracleDataAdapter object), which makes calls to an OLE DB provider or the APIs provided by the underlying data source. The important difference is that in ADO.NET the data adapter allows you to control how the changes to the dataset are transmitted to the database — by optimizing for performance, performing data validation checks, or adding any other extra processing.

Note -   Data adapters, data connections, data commands, and data readers are the components that make up a .NET Framework data provider. Microsoft and third-party providers can make available other .NET Framework data providers that can be integrated into Visual Studio. For information on the different .NET Data providers, see .NET Data Providers.

Sharing Data Between Applications
Transmitting an ADO.NET dataset between applications is much easier than transmitting an ADO disconnected recordset. To transmit an ADO disconnected recordset from one component to another, you use COM marshalling. To transmit data in ADO.NET, you use a dataset, which can transmit an XML stream.

 

12.  Can you give an example of what might be best suited to place in the Application_Start and Session_Start subroutines? 

Ans. The Application_Start event is guaranteed to occur only once throughout the lifetime of the application. It’s a good place to initialize global variables. For example, you might want to retrieve a list of products from a database table and place the list in application state or the Cache object. SessionStateModule exposes both Session_Start and Session_End events.


13. If I'm developing an application that must accomodate
multiple security levels through secure login and my ASP.NET web appplication is spanned across three web-servers (using round-robbin load balancing)
what would be the best approach to maintain login-in state
for the users?
Ans.
Database Support OR through State Service

14. What are ASP.NET Web Forms? How is this technology
different than what is available though ASP (1.0-3.0)?
Ans.
There are plenty of differences.
ASP Interpreter.. use the script engine.
ASP.Net is compiled as managed code within the CLR. It also
supports code-behind (unlike in ASP, where code=behind was
invoked through VB components).

15. How does VB.NET/C# achieve polymorphism?
Ans. We achieve it using Function overloading & Operator overloading.

Polymorphism by definition means taking many forms. In C# it means the ability for classes to share the same methods (actions) but implement them differently. For instance, say we create a class called "Shape" and this class has a method called .draw() which draws the shape onto the user interface. Then we create two subclasses, using inheritance, of this Shape class. One called Square, the other called Circle. Now obviously a square and circle are two entirely different shapes, yet both classes have the .draw() method. When the Square.draw() method is called it will draw a square on the user interface. When the Circle.draw() method is called, it will draw a circle on the user interface. So both classes can use the same methods but implement them differently.

16. Can you explain what inheritance is and an example
of when you might use it?

Ans. Inheriting a trait from a parent class!
Use the existing functionality along with its own
properities.

17. How would you implement inheritance using VB.NET/C#?
Ans. Derived Class : Baseclass
VB.NEt : Derived Class Inherits Baseclass

18. Whats an assembly ?
Ans.
A Basic unit of executable code. 

  * It contains : Manifest - Meta data
  * versioning , Culture , IL, Reference

19. Describe the difference between inline and code behind.

Ans. Inline function bind at compile time can write in aspx page with in <% %> .

The code-behind is in a CS or a VB file.


20. Explain what a diffgram is, and a good use for one.
Ans.
A DiffGram is an XML format that is used to identify
current and original versions of data elements. The DataSet uses the DiffGram format to load and persist its contents, and to serialize its contents for transport across a network connection. When a DataSet is written as a DiffGram, it populates the DiffGram with all the necessary information to accurately recreate the contents, though not the schema, of the DataSet, including column values from both the Original and Current row versions, row error information, and row order. When sending and retrieving a DataSet from an XML Web service, the DiffGram format is implicitly used.
Additionally, when loading the contents of a DataSet from
XML using the ReadXml method, or when writing the
contents of a DataSet in XML using the WriteXml method,
you can select that the contents be read or written as a
DiffGram

DiffGram Format
The DiffGram format is divided into three sections: the
current data, the original (or "before") data, and an
errors section, as shown in the following example.

<?xml version="1.0"?>
<diffgr:diffgram
         xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
         xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
         xmlns:xsd="
http://www.w3.org/2001/XMLSchema">

   <DataInstance>
   </DataInstance>

  <diffgr:before>
  </diffgr:before>

  <diffgr:errors>
  </diffgr:errors>
</diffgr:diffgram>
The DiffGram format consists of the following blocks of data:

<DataInstance>
The name of this element, DataInstance, is used for
explanation purposes in this documentation. A DataInstance
element represents a DataSet or a row of a DataTable.
Instead of DataInstance, the element would contain the name
of the DataSet or DataTable. This block of the DiffGram format contains the current data, whether it has been modified or not.
An element, or row, that has been modified is identified with
the diffgr:hasChanges annotation.

<diffgr:before>
This block of the DiffGram format contains the original
version of a row. Elements in this block are matched to
elements in the DataInstance block using the diffgr:id
annotation.
<diffgr:errors>
This block of the DiffGram format contains error information
for a particular row in the DataInstance block. Elements in
this block are matched to elements in the DataInstance block
using the diffgr:id annotation.

21. Where would you use an iHTTPModule, and what are

the limitations of any approach you might take in

implementing one?

Ans. It provides module initialization and disposal events

to the implementing class.

 

 

22. Compare Session State Vs. ViewState.
Ans.
Session State is useful for storing values that must
be persisted across multiple pages by the same user. ViewState is useful for storing serializable data that must be
persisisted across PostBacks by a single page. If you use
Session State, the value you insert will remain in memory
until (1) The Session times out, or (2) Your code removes it.
If you use ViewState, the value you insert will remain in
ViewState until the user requests a different page.

ViewState stores data betwen PostBacks by putting it into a
hidden form field on the client HTML doc. when the doc is
Posted Back, the values are read from the hidden form field
and stored in memory until the page has finished processing.
 If ViewState is particularly large (and I'm talking KBs
here, not 6 bytes), it can negatively affect the speed at
which the HTML doc is downloaded by the browser.

 

24. Whats MSIL, and why should my developers need an appreciation of it if at all?
Ans. Microsoft Intermediate language. which is the out put
for all the .net supported languages after compilation will
produce. Appreciation is for cross language support.

Definition:Microsoft Intermediate Language (MSIL) is the
CPU-independent instruction set generated by .NET compilers
from .NET languages such as J#, C# or Visual Basic. MSIL is
compiled before or during execution of the program by a Virtual Execution System (VES), which is part of the Common Language Runtime module (CLR).

25. In what order do the events of an ASPX page execute. As a developer is it important to undertsand these events?
Ans.

Page request
 The page request occurs before the page life cycle begins.
When the page is requested by a user, ASP.NET determines
whether the page needs to be parsed and compiled (therefore beginning the life of a page), or whether a cached version
of the page can be sent in response without running the page.

Start
 In the start step, page properties such as Request and
Response are set. At this stage, the page also determines
whether the request is a postback or a new request and sets
the IsPostBack property. Additionally, during the start step,
the page's UICulture property is set.

Page initialization
 During page initialization, controls on the page are
available and each control's UniqueID property is set. Any
themes are also applied to the page. If the current request is
a postback, the postback data has not yet been loaded and
control property values have not been restored to the values
from view state.

Load
 During load, if the current request is a postback, control
properties are loaded with information recovered from view
state and control state.

Validation
 During validation, the Validate method of all validator
controls is called, which sets the IsValid property of
individual validator controls and of the page.

Postback event handling
 If the request is a postback, any event handlers are called.
Rendering  Before rendering, view state is saved for the page and all controls. During the rendering phase, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream of the page's Response property.

Unload
 Unload is called after the page has been fully rendered, sent
to the client, and is ready to be discarded. At this point,

page properties such as Response and Request are unloaded and any cleanup is performed.
 


26. Which method do you invoke on the DataAdapter
control to load your generated dataset with data?
Ans.
Fill()

 

27. Can you edit data in the Repeater control?
Ans. NO

 

28. Which template must you provide, in order to display
data in a Repeater control?
Ans. ITemtemplate

 

29. How can you provide an alternating color scheme in a Repeatercontrol?
Ans. AlternateItemTemplate

 

30. What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeatercontrol?

Ans. Datasource, DataBind

 

31. What base class do all Web Forms inherit from?
Ans.
System.Web.UI.Page

 

32. What method do you use to explicitly kill a user's
session?
Ans.
Abandon()

 

33. How do you turn off cookies for one page in your site?
Ans.
Disablecookies.

 

34. Which two properties are on every validation control?
Ans.
Control to validate, Error message

 

35. What tags do you need to add within the
asp:datagrid tags to bind columns manually?
Ans.
autogenerated columns is set to false

 

36. How do you create a permanent cookie?
Ans. 
Setting a permanent cookie is no harder than setting a
Session cookie. It’s very similar, except you give the cookie
an expiration date as well. It is very common that you don’t
specify any arbitrary expiration date, but instead expire the
cookie relative to the current date, using the DateAdd()
function, built into ASP. If you want to create a permanent
cookie called Name with a value of Nigel, which expires in one
month, you’d use the following code


Response.Cookies("Name") = "Nigel"
Response.Cookies("Name").Expires = DateAdd("m", 1, Now())

 

It’s that easy! Nothing more to it. You have now set a permanent cookie on your computer. Also, note that whenever the above code is called the expiration date of the cookie is renewed by one month from now.

There are a few more options which you can set, like for example the Path option. You can limit cookies to certain paths on your website, so you can set several cookies with the same name, as long as they belong to different paths. To do this, you would use the following code (extending the previous code):


Response.Cookies("Name").Path = "/foo/"

The above code would limit the cookie to the path foo. It is
also possible to assign multiple values to a particular cookie.
This is done using the so-called dictionary functionality of

a cookie. For example, if I’d want to store not only the first
name, but also the surname in my Name cookie, I’d be using
something like the following code:


Response.Cookies("Name")("First") = "Nigel"
Response.Cookies("Name")("Last") = "Pallett"
Response.Cookies("Name").Expires = DateAdd("m", 1, Now())

 

That’s all! Although there are a few more "advanced" options,
such as the Secure option and the Domain option, it is of no use now.


Retrieving Cookies

Retrieving the value of cookies is a very easy job, because
again everything is handled by the browser and your server.
All you have to use is ASP’s inbuilt functions.

There is no difference in retrieving a Session cookie or a
permanent cookie, and in both cases you use the following code:


Response.Write "Your Name: " & Request.Cookies("Name")

 

The above is for when you assigned only one value to a cookie. If you assigned multiple values you a cookie, you use the following code:


Response.Write "Your First Name: " & _
    Request.Cookies("Name")("First")
Response.Write "Your Surname: " & _
    Request.Cookies("Name")("Last")

 

That’s all there is to it. It’s that easy, because everything
is done by your server and the ASP engine. Make sure you check out this handy function as well, which shows your visitors all the cookies they have stored.


Checking if Cookies are enabled

Before using cookies, it is often useful to check whether your
visitor accepts cookies. Some may disable it in their browser;

others may be using browsers that don’t support cookies at all (although very few browsers do). You should always keep the fact that your cookies might not work in the back of your mind, meaning, do NOT rely on cookies to work. If your website does not work when cookies are disabled, you must fix this.

 

37. What tag do you use to add a hyperlink column to
the DataGrid?

Ans.<asp:HyperLink id="some_Id_uDefine" runat="server">

 

38. What is the standard you use to wrap up a call to a
Web service?

Ans. SOAP - SOAP is a simple XML-based protocol to let
applications exchange information over HTTP.

SOAP (originally Simple Object Access Protocol) is a
protocol for exchanging XML-based messages over computer
network, normally using HTTP. SOAP forms the foundation
layer of the Web services stack, providing a basic messaging
framework that more abstract layers can build on. The original acronym was dropped with Version 1.2 of the standard, which became a W3C Recommendation on June 24, 2003, as it was
considered to be misleading.

 

There are several different types of messaging patterns in
SOAP, but by far the most common is the Remote Procedure Call (RPC) pattern, in which one network node (the client) sends a request message to another node (the server), and the server immediately sends a response message to the client. SOAP is the successor of XML-RPC, though it borrows its transport and interaction neutrality and the envelope/header/body from elsewhere, probably from WDDX [citation needed]. Originally designed by Dave Winer, Don Box, Bob Atkinson, and Mohsen Al-Ghosein in 1998 with backing from Microsoft (where Atkinson and Al-Ghosein worked at the time) as an object-access protocol, the SOAP specification is currently maintained by the XML Protocol Working Group of the World Wide Web Consortium.

 

39. Which method do you use to redirect the user to
another page without performing a round trip to the client?

Ans. Server.transfer

 

40. What is the transport protocol you use to call a
Web service 
Ans.

SOAP. Transport Protocols: It is essential for the acceptance of Web Services that they are based on established Internet

infrastructure. This in fact imposes the usage of of the HTTP,
SMTP and FTP protocols based on the TCP/IP family of

transports. Messaging Protocol: The format of messages exchanged between Web Services clients and Web Services should be vendor neutral and should not carry details about the technology used to implement the service. Also, the message format should allow for extensions and different bindings to specific transport protocols. SOAP and ebXML Transport are specifications which fulfill these requirements. We expect that the W3C XML Protocol Working Group defines a successor standard.


41. True or False: A Web service can only be written
in .NET
Ans.
False

42. What does WSDL stand for?
Ans.
Webservice description language. WSDL is an XML format for describing network services as a set of endpoints
operating on messages containing either document-oriented or procedure-oriented information. The operations and messages are described abstractly, and then bound to a concrete network protocol and message format to define an endpoint. Related concrete endpoints are combined into abstract endpoints (services). WSDL is extensible to allow description of endpoints and their messages regardless of what message formats or network protocols are used to communicate, however, the only bindings described in this document describe how to use WSDL in conjunction with SOAP 1.1, HTTP GET/POST, and MIME.

 

43. What property do you have to set to tell the
grid which page to go to when using the Pager object?
Ans.
Page Index.

 

44. Where on the Internet would you look for Web services?
Ans.
UDDI

45. What tags do you need to add within the
asp:datagrid tags to bind columns manually.

Ans. Autogenerate columns

 

46. Which property on a Combo Box do you set with a column name, prior to setting the DataSource, to display data in the combo box?
Ans.
Datatext, Datavalue

47. How is a property designated as read-only?
Ans.

In VB.NET:

Public ReadOnly Property PropertyName As ReturnType
 Get   ‘Your Property Implementation goes in here
 End Get
End Property

In C#

public returntype PropertyName
{
 get{
  //property implementation goes here
 }
 // Do not write the set implementation
}

 

48. Which control would you use if you needed to make sure the values in two different controls matched?
Ans.
Ideally we would tend to use Comparefield validator.

 

49. True or False: To test a Web service you must create a windows application or Web application to consume this service?
Ans.
False

 

50. How many classes can a single .NET DLL contain?
Ans.
As many as u want!

 

51. Is ASP.NET a language?
Ans.
No! Its a technology.
ASP.NET is not a platform independent language. As was
ASP.NET is more of a technology that provides a framework for building web applications. ASP.NET provides the reources needed to dynamically deliver html content (pages) to the end user. ASP.NET can leverage languages such as C#, VB.NET, and javascript to help provide a reliable, high perfofmance, and secure web application

XML Documentation Questions
1.
Is XML case-sensitive?
Ans. Yes.
 
2.What’s the difference between // comments,
/* */ comments and /// comments?
Ans. Single-line comments, multi-line comments,
and XML documentation comments.
 
3.How do you generate documentation from the C#
file commented properly with a command-line compiler?
Ans. Compile it with the /doc switch.

Debugging and Testing Questions
1.
What debugging tools come with the .NET SDK?
Ans.
1. CorDBG – command-line debugger.  To use
CorDbg, you must compile the original C# file
using the /debug switch.

2. DbgCLR – graphic debugger.  Visual Studio
.NET uses the DbgCLR.
 
2.What does assert() method do?
Ans. In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false.  The program proceeds without any interruption if the condition is true.
 
3.What’s the difference between the Debug class and Trace class?
Ans. Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release
builds.
 
4.Why are there five tracing levels in System.Diagnostics.TraceSwitcher?
Ans. The tracing dumps can be quite verbose.  For applications that are constantly running you run the
risk of overloading the machine and the hard drive. 
Five levels range from None to Verbose, allowing you to
fine-tune the tracing activities.
 
5.Where is the output of TextWriterTraceListener
redirected?
Ans. To the Console or a text file depending on
the parameter passed to the constructor.
 
6.How do you debug an ASP.NET Web application?
Ans. Attach the aspnet_wp.exe process to the
DbgClr debugger.
 
7.What are three test cases you should go through
in unit testing?
Ans.
1.       Positive test cases (correct data, correct
output).
2.       Negative test cases (broken or missing data,
proper handling).
3.       Exception test cases (exceptions are thrown
and caught properly).
 
8.Can you change the value of a variable while debugging
a C# application?
Ans. Yes.  If you are debugging via Visual Studio.NET,
just go to Immediate window.
 
ADO.NET and Database Questions
1.
 What is the role of the DataReader class in
ADO.NET connections?
Ans. It returns a read-only, forward-only rowset from
the data source.  A DataReader provides fast access
when a forward-only sequential read is needed.
 
2.What are advantages and disadvantages of Microsoft
provided data provider classes in ADO.NET?
Ans. SQLServer.NET data provider is high-speed and
robust, but requires SQL Server license purchased from
Microsoft.

OLE-DB.NET is universal for accessing other sources,
like Oracle, DB2, Microsoft Access and Informix. 
OLE-DB.NET is a .NET layer on top of the OLE layer, so
it’s not as fastest and efficient as SqlServer.NET.
 
3.What is the wildcard character in SQL?
Ans. Let’s say you want to query database with LIKE for
all employees whose name starts with La. The wildcard
character is %, the proper query with LIKE would
involve ‘La%’.
 
4.Explain ACID rule of thumb for transactions.
Ans.
A transaction must be:
1.Atomic - it is one unit of work and does not dependent
on previous and following transactions.
2.Consistent - data is either committed or roll back, no
“in-between” case where something has been updated and
something hasn’t.
3.Isolated - no transaction sees the intermediate results
of the current transaction).
4.Durable - the values persist if the data had been
committed even if the system crashes right after.
 
5.What connections does Microsoft SQL Server support?
Ans. Windows Authentication (via Active Directory) and
SQL Server authentication (via Microsoft SQL Server
username and password).
 
6.Between Windows Authentication and SQL Server
Authentication, which one is trusted and which one is
untrusted?
Ans. Windows Authentication is trusted because the
username and password are checked with the Active
Directory, the SQL Server authentication is untrusted,
since SQL Server is the only verifier participating in the
transaction.
 
7.What does the Initial Catalog parameter define in the
connection string?
Ans. The database name to connect to.
  
8.What does the Dispose method do with the connection
object?
Ans. Deletes it from the memory.
To Do: answer better.  The current answer is not entirely
correct.
 
9.What is a pre-requisite for connection pooling?
Ans. Multiple processes must agree that they will share
the same connection, where every parameter is the same,
including the security settings.  The connection string
must be identical.

Assembly Questions
1.
How is the DLL Hell problem solved in .NET?
Ans. Assembly versioning allows the application to specify
not only the library it needs to run (which was available
under Win32), but also the version of the assembly.
 
2.What are the ways to deploy an assembly?
Ans. An MSI installer, a CAB archive, and XCOPY command.
 
3.What is a satellite assembly?
Ans. 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.
 
4.What namespaces are necessary to create a localized
application?
Ans.System.Globalization and System.Resources.
 
5.What is the smallest unit of execution in .NET?
Ans. an Assembly.
 
6.When should you call the garbage collector in .NET?
Ans. As a good rule, you should not call the garbage
collector.  However, you could call the garbage collector
when you are done using a large object (or set of objects)
to force the garbage collector to dispose of those very
large objects from memory.  However, this is usually not a
good practice.
 
7.How do you convert a value-type to a reference-type?
Ans. Use Boxing.
 
8.What happens in memory when you Box and Unbox a
value-type?
Ans. Boxing converts a value-type to a reference-type, thus storing the object on the heap.  Unboxing converts a
reference-type to a value-type, thus storing the value on the stack