Monday, August 27, 2007

Frequently Asked Question in Dot Net Technologies


ASP.NET Questions


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

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.

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

Server side.

Should validation (did the user enter a real date) occur server-side or client-side? Why?

Client side. There is no need to go to validate user input. If it relates to data base validation we need to validate at server side.

What is ViewState?

ViewState allows the state of objects (serializable) to be stored in a hidden field on the page. ViewState is transported to the client and back to the server, and is not stored on the server or any other external source. ViewState is used to retain the state of server-side objects between post backs.

What does the "EnableViewState" property do? Why would I want it on or off?

It allows the page to save the users input on a form across post backs. It saves the server-side values for a given control into ViewState, which is stored as a hidden value on the page before sending the page to the client’s browser. When the page is posted back to the server the server control is recreated with the state stored in ViewState.



If we turn off the EnableViewState property of the control then the values is not populate during server round trip.

What is the lifespan for items stored in ViewState?

Item stored in ViewState exist for the life of the current page. This includes post backs (to the same page).

What is smart navigation?

The cursor position is maintained when the page gets refreshed due to the server side validation and the page gets refreshed

What are the different types of Session state management options available with ASP.NET?

ASP.NET provides In-Process and Out-of-Process state management.

In-Process stores the session in memory on the web server. This requires the "sticky-server" (or no load-balancing) so that the user is always reconnected to the same web server.

Out-of-Process Session state management stores data in an external data source. The external data source may be either a SQL Server or a State Server service. Out-of-Process state management requires that all objects stored in session are serializable.

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

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.

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

Application_Start need for global variable, which are available over the application.

Session_Start: login dependent (user dependent)

If I'm developing an application that must accommodate multiple security levels though secure login and my ASP.NET web application is spanned across three web-servers (using round-robin load balancing) what would be the best approach to maintain login-in state for the users?

Database Support or thru state service

What are ASP.NET Web Forms? How is this technology different than what is available though ASP (1.0-3.0)?

ASP Interpreter uses the script engine.

ASP.Net Compiled.

Describe the difference between inline and code behind - which is best in a loosely coupled solution Tightly coupled - INLINE

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

Explain what a diffgram is, and a good use for one

The DiffGram is one of the two XML formats that you can use to render DataSet object contents to XML. A good use is reading database data to an XML file to be sent to a Web Service.

Where would you use an iHTTPModule, and what are the limitations of any approach you might take in implementing one?

Preprocessing before going to IIS.

What are the disadvantages of viewstate?

It can be hacked. Page size is heavy.

Describe session handling in a web form, how does it work and what are the limits?

Following are Session mode:

In Proc

State sever/Out process

SQL



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

Init() - when the page is instantiated

Load() - when the page is loaded into server memory

PreRender() - the brief moment before the page is displayed to the user as HTML

Unload() - when page finishes loading.

Can you edit data in the Repeater control?

NO

Which template must you provide, in order to display data in a Repeater control?

Itemtemplate

How can you provide an alternating color scheme in a Repeatercontrol?

AlternateItemTemplate


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?

Datasource,

DataBind


What base class do all Web Forms inherit from?

System.Web.UI.Page

What method do you use to explicitly kill a user s session?

abandon()

How do you turn off cookies for one page in your site?

disablecookies.

Which two properties are on every validation control?

Controltovalidate, errormessage


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

AutoGenerated columns is set to false


How do you create a permanent cookie?

Cookie = new cookie().

cookie.adddate.

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

hyperlink column



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

server.transfer



What property do you have to set to tell the grid which page to go to when using the Pager object?

CurrentPageIndex.



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?

datatext

datavalue



How is a property designated as read-only?

Get


Which control would you use if you needed to make sure the values in two different controls matched?

Compare Validator

Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading process.

inetinfo.exe is theMicrosoft IIS server running, handling ASP.NET requests among other things.When an ASP.NET request is received (usually a file with .aspx extension), the ISAPI filter aspnet_isapi.dll takes care of it by passing the request tothe actual worker process aspnet_wp.exe.


What’s the difference between Response.Write() and Response.Output.Write()?

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



When during the page processing cycle is ViewState available?

After the Init() and before the Page_Load(), or OnLoad() for a control.


Where do you store the information about the user’s locale?

System.Web.UI.Page.Culture

What’s a bubbled event?

When you have a complex control, like DataGrid, writing an event processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its constituents.



Suppose you want a certain ASP.NET function executed on MouseOver for a certain button. Where do you add an event handler?

Add an OnMouseOver attribute to the button. Example: btnSubmit.Attributes.Add("onmouseover","someClientCodeHere();");

What data types do the RangeValidator control support?

Integer, String, and Date.


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

The answer is server-side code since code-behind is executed on the server. However, during the code-behind's execution on the server, it can render client-side code such as JavaScript to be processed in the client’s browser. But just to be clear, code-behind executes on the server, thus making it server-side code.


Should user input data validation occurs server-side or client-side? Why?

All user input data validation should occur on the server at a minimum. Additionally, client-side validation can be performed where deemed appropriate and feasible to provide a richer, more responsive experience for the user.

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

Server.Transfer transfers page processing from one page directly to the next page without making a round-trip back to the client's browser. This provides a faster response with a little less overhead on the server. Server.Transfer does not update the clients url history list or current url. Response.Redirect is used to redirect the user's browser to another page or site. This performs a trip back to the client where the client's browser is redirected to the new page. The user's browser history list is updated to reflect the new address.

Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?

Valid answers are:

· A DataSet can represent an entire relational database in memory, complete with tables, relations, and views.

· A DataSet is designed to work without any continuing connection to the original data source.

· Data in a DataSet is bulk-loaded, rather than being loaded on demand.

· There's no concept of cursor types in a DataSet.

· DataSets have no current record pointer You can use For Each loops to move through the data.

· You can store many edits in a DataSet, and write them to the original data source in a single operation.

· Though the DataSet is universal, other objects in ADO.NET come in different versions for different data sources.



What is the Global.asax used for?

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

What are the Application_Start and Session_Start subroutines used for?

This is where you can set the specific variables for the Application and Session objects.

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

When you want to inherit (use the functionality of) another class. Example: With a base class named Employee, a Manager class could be derived from the Employee base class.

Describe the difference between inline and code behind.

Inline code written along side the html in a page. Code-behind is code written in a separate file and referenced by the .aspx page.

WEB Service Questions

Can you give an example of when it would be appropriate to use a web service as opposed to a non-serviced .NET component

Web services are best suite for Hetrogenious environment.

Remoting is best suite for Homogenious environment. The systems that under CLR.


What is the transport protocol you use to call a Web service?

SOAP (Simple Object Access Protocol) is the preferred protocol.

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

false


What does WSDL stand for?

Web Service Description language. It is used to generate for proxy server object.


Where on the Internet would you look for Web services?

UDDI



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

False, the web service comes with a test page and it provides HTTP-GET method to test.



Where on the Internet would you look for Web services?

http://www.uddi.org


XML Documentation Questions

Is XML case-sensitive?

Yes.

What’s the difference between // comments, /* */ comments and /// comments?

Single-line comments

Multi-line comments

XML documentation comments

How do you generate documentation from the C# file commented properly with a command-line compiler?

Compile it with the /doc switch.

Debugging and Testing Questions

What debugging tools come with the .NET SDK?

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.

What does assert() method do?

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.

What’s the difference between the Debug class and Trace class?

Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.

Why are there five tracing levels in System.Diagnostics.TraceSwitcher?

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.

Where is the output of TextWriterTraceListener redirected?

To the Console or a text file depending on the parameter passed to the constructor.

How do you debug an ASP.NET Web application?

Attach the aspnet_wp.exe process to the DbgClr debugger.

What are three test cases you should go through in unit testing?

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

Can you change the value of a variable while debugging a C# application?

Yes. If you are debugging via Visual Studio.NET, just go to Immediate window.

ADO.NET and Database Questions

What is the role of the DataReader class in ADO.NET connections?

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.

What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?

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.


What is the wildcard character in SQL?

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

Explain ACID rule of thumb for transactions.

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.

What connections does Microsoft SQL Server support?

Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and password).

Between Windows Authentication and SQL Server Authentication, which one is trusted and which one is untrusted?

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.

What does the Initial Catalog parameter define in the connection string?

The database name to connect to.

What does the Dispose method do with the connection object?

Dispose places the connection back in the managed pool. So that other object/class can use that connection for further use.

What is a pre-requisite for connection pooling?

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.

Which method do you invoke on the DataAdapter control to load your generated dataset with data?

Fill()

Can you explain the difference between an ADO.NET Dataset and an ADO Record set?


Disconnected architecture.

Maintenance relation schemas

Multiple table grouping

Connected one


Assembly Questions

How is the DLL Hell problem solved in .NET?

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.

What are the ways to deploy an assembly?

An MSI installer, a CAB archive, and XCOPY command. What are the different types of assemblies available and their purpose?

Private Assemblies: Assembly used within an application is known as private assemblies

Public/shared Assemblies: Assembly, which can be shared across applications, is known as shared assemblies. Strong Name has to be created to create a shared assembly. This can be done using SN.EXE. The same has to be registered using GACUtil.exe (Global Assembly Cache).


Satellite Assemblies: These assemblies contain resource files pertaining to a locale (Culture + Language). These assemblies are used in deploying a Gloabl application for different languages.

What is a satellite assembly?

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.

What namespaces are necessary to create a localized application?

System.Globalization and System.Resources.

What is the smallest unit of execution in .NET?
An Assembly.

What is an assembly?
A Basic unit of executable code, which contains:

Manifest - Meta data

Versioning

Culture

IL

Reference

What’s a strong name?

A strong name includes the name of the assembly, version number, culture identity, and a public key token.



How can you create a strong name for a .NET assembly?

With the help of Strong Name tool (sn.exe).



Where are shared assemblies stored?

Global assembly cache.


Where’s global assembly cache located on the system?

Usually C:\winnt\assembly or C:\windows\assembly.

Can you have two files with the same file name in GAC?

Yes, remember that GAC is a very special folder, and while normally you would not be able to place two files with the same name into a Windows folder, GAC differentiates by version number as well, so it’s possible for MyApp.dll and MyApp.dll to co-exist in GAC if the first one is version 1.0.0.0 and the second one is 1.1.0.0.

So let’s say I have an application that uses MyApp.dll assembly, version 1.0.0.0. There is a security bug in that assembly, and I publish the patch, issuing it under name MyApp.dll 1.1.0.0. How do I tell the client applications that are already installed to start using this new MyApp.dll?

Use publisher policy. To configure a publisher policy, use the publisher policy configuration file, which uses a format similar app .config file. But unlike the app .config file, a publisher policy file needs to be compiled into an assembly and placed in the GAC.

What is delay signing?

Delay signing allows you to place a shared assembly in the GAC by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage, when the development process is complete and the component or assembly is ready to be deployed. This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at different stages of development.

When should you call the garbage collector in .NET?

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.

How do you convert a value-type to a reference-type?

Use Boxing.

What happens in memory when you Box and Unbox a value-type?

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.

How many classes can a single .NET DLL contain?

As many as u want

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

We need to have Wrapper to communicate COM components in .net. and vis versa

CCW : Com Callable wrapper.

RCW : RUN time callable wrapper.



What is MSIL, and why should my developers need an appreciation of it if at all?

Microsoft Intermediate language, which is the output for all the .net supported languages after compilation will produce. Appreciation for cross language support.



Class Questions

What is the syntax to inherit from a class in C#/VB.NET?

Place a colon and then the name of the base class.

Example C#: class MyNewClass : MyBaseClass

Example VB.Net: MyNewClass Inherits MyBaseclass



How does VB.NET/C# achieve polymorphism?

Function overloading.

Operator overloading.



Can you prevent your class from being inherited by another class?

Yes. The keyword “sealed” will prevent the class from being inherited.



Can you allow a class to be inherited, but prevent the method from being over-ridden?

Yes. Just leave the class public and make the method sealed.



What’s an abstract class?

A class that cannot be instantiated. An abstract class is a class that must be inherited and have the methods overridden. An abstract class is essentially a blueprint for a class without any implementation.



When do you absolutely have to declare a class as abstract?

1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.

2. When at least one of the methods in the class is abstract.



What is an interface class?

Interfaces, like classes, define a set of properties, methods, and events. But unlike classes, interfaces do not provide implementation. They are implemented by classes, and defined as separate entities from classes.



Why can’t you specify the accessibility modifier for methods inside the interface?

They all must be public, and are therefore public by default.



Can you inherit multiple interfaces?

Yes. .NET does support multiple interfaces.



What happens if you inherit multiple interfaces and they have conflicting method names?

It’s up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compiler cares you’re okay.



What’s the difference between an interface and abstract class?

In an interface class, all methods are abstract - there is no implementation. In an abstract class some methods can be concrete. In an interface class, no accessibility modifiers are allowed. An abstract class may have accessibility modifiers.



What is the difference between a Struct and a Class?

Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval. Another difference is that structs cannot inherit.



Can we have private constructor? When can I use them?

Private constructors can be used when you do not want the class's object to be created. Since the constructor cannot be accessed, an object of the class cannot be created. A possible scenario would be, a class with static methods, which don’t need object instance to be called.





Method and Property Questions



What’s the implicit name of the parameter that gets passed into the set method/property of a class?

Value. The data type of the value parameter is defined by whatever data type the property is declared as.



What does the keyword “virtual” declare for a method or property?

The method or property can be overridden.



How is method overriding different from method overloading?

When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same name within the class.



Can you declare an override method to be static if the original method is not static?

No. The signature of the virtual method must remain the same. (Note: Only the keyword virtual is changed to keyword override)



What are the different ways a method can be overloaded?

Different parameter data types

Different number of parameters

Different order of parameters



If a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?

Yes, just place a colon, and then keyword base (parameter list to invoke the appropriate constructor) in the overloaded constructor definition inside the inherited class.



Events and Delegates


What’s a delegate?

A delegate object encapsulates a reference to a method.



What’s a multicast delegate?

A delegate that has multiple handlers assigned to it. Each assigned handler (method) is called.



Frequently Asked Question in Dot Net Technologies

After so many interviews given by or taken by me for my selection or selection for my company, usually i am short of questions to ask or answer to be given in perfect way. When today one of my collegue asked me about some questions which normally asked in Dot Net Technology, i have searched some internet sites and learning from my past experience, I have prepared below Question Bank with answers from persons who published in different forums or personal sites and clubbed together as single point for reference instead of referring to different locations:



Dot Net Technology Frequently Asked Questions



General Questions

What is CLS (Common Language Specificaiton)?

It provides the set of specificaiton which has to be adhered by any new language writer / Compiler writer for .NET Framework. This ensures Interoperability. For example: Within a ASP.NET application written in C#.NET language, we can refer to any DLL written in any other language supported by .NET Framework. As of now .NET Supports around 32 languages.

What is CTS (Common Type System)?

It defines about how Objects should be declard, defined and used within .NET. CLS is the subset of CTS.

What is Boxing and UnBoxing?

Boxing is implicit conversion of ValueTypes to Reference Types (Object).

UnBoxing is explicit conversion of Reference Types (Object) to its equivalent ValueTypes. It requires type-casting.

What is the difference between Value Types and Reference Types?

Value Types uses Stack to store the data where as the later uses the Heap to store the data.

Is String is Value Type or Reference Type in C#?

String is an object (Reference Type).

Does C# support multiple-inheritance?
No.

Who is a protected class-level variable available to?
It is available to any sub-class (a class inheriting this class).

When you inherit a protected class-level variable, who is it available to?

Protected members can be accessible by all the derived class irrespective of the Namespaces only protected Friend or protected internal will be accessed inside the namespace...

Are private class-level variables inherited?
Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.

Describe the accessibility modifier “protected internal”.

It is available to classes that are within the same assembly and derived from the specified base class.

What’s the top .NET class that everything is derived from?
System.Object.

What does the term immutable mean?
The data value may not be changed. Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.

Immutable means you can't change the current 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.

What’s the difference between System.String and System.Text.StringBuilder classes?

System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.

What is the difference between const and static readonly?
The difference is that the value of a static readonly field is set at run time, and can thus be modified by the containing class, whereas the value of a const field is set to a compile time constant.

In the static readonly case, the containing class is allowed to modify it only in the variable declaration (through a variable initializer)

In the static constructor (instance constructors, if it's not static) static readonly is typically used if the type of the field is not allowed in a const declaration, or when the value is not known at compile time.

Instance readonly fields are also allowed.

Remember that for reference types, in both cases (static and instance) the readonly modifier only prevents you from assigning a new reference to the field. It specifically does not make immutable the object pointed to by the reference.

class Program

{

public static readonly Test test = new Test();



static void Main(string[] args)

{

test.Name = "Program";



test = new Test(); // Error: A static readonly field cannot be assigned to (except in a static constructor or a variable initializer)


}

}



class Test

{

public string Name;

}



On the other hand, if Test were a value type, then assignment to test.Name would be an error.

How do I create a constant that is an array?
Strictly speaking you can't, since const can only be applied to a field or local whose value is known at compile time.

In both the lines below, the right-hand is not a constant expression (not in C#).

const int [] constIntArray = newint [] {2, 3, 4}; //error CS0133: The expression being assigned to 'constIntArray' must be constant

const int [] constIntArrayAnother = {2, 3, 4}; //error CS0623: Array initializers can only be used in a variable or field initializer. Try using a new expression instead.

However, there are some workarounds, depending on what it is you want to achieve.

If want a proper .NET array (System.Array) that cannot be reassigned, then static readonly will do for you.

static readonly int [] constIntArray = new int[] {1, 2, 3};


The constIntArray field will be initialized before it its first use.

If, on the other hand, you really need a const set of values (say as an argument to an attribute constructor), then - if you can limit yourself to integral types - an enum would serve you well.

For example

[Flags]

public enum Role

{

Administrator = 1,

BackupOperator = 2,

// etc.

}

public class RoleAttribute : Attribute

{

public RoleAttribute()

{

CreateRole = DefaultRole;

}

public RoleAttribute(Role role)

{

CreateRole = role;

}

public Role CreateRole

{

get { return this.createRole; }

set { this.createRole = value; }

}

private Role createRole = 0;

public const Role DefaultRole = Role.Administrator | Role.BackupOperator;

}

[RoleAttribute(RoleAttribute.DefaultRole)]

public class DatabaseAccount

{

//..............

}

Avoiding Type Name-Clashes using 'using'
You are already aware that the C# using keyword allows you to supply hints to the compiler regarding the fully qualified name of the types within a given *.cs file.

However, what you may not know is that the using keyword also allows you to build aliases (very helpful for prevent name clashes). Assume you have the following two-namespace definitions:

namespace My2DShapes

{

public class Hexagon{}

}

namespace My3DShapes

{

public class Hexagon{}

}

Now assume you wish to create an instance of the 3D Hexagon from the following application:

using My2DShapes;

using My3DShapes;

public class MyApp

{

public static void Main()

{

// Error! Which Hexagon?

Hexagon h = new Hexagon();

}

}

This name clash can be resolved quite simply by building the following alias:

using My2DShapes;

using The3DHex = My3DShapes.Hexagon;

public class MyApp

{

public static void Main()

{

// This really creates a new My3DShapes.Hexagon.

The3DHex h = new The3DHex();

}

}

Can you store multiple data types in System.Array?
No.

What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?

The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identical object.

Array. CopyTo does not make a deep copy. This can be easily verified by running the following code.

public class MyClass

{

public static void Main()

{

Container[] containerArray = new Container[10];

for( int i=0; i < containerArray.Length; i++ ){

containerArray[i] = new Container( i );

}

Container[] containerArrayCopy = new Container[10];

containerArray.CopyTo( containerArrayCopy, 0 );

containerArrayCopy[2].V = 3;

for( int i=0; i < containerArray.Length; i++ ){

Console.Write( "{0}, ", containerArray[i].V );

}

Console.WriteLine();

}



}



public class Container{

public int V;

public Container(int i ){

V = i;

}

}

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

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

What’s the .NET collection class that allows an element to be accessed using a unique key?

HashTable.

What class is underneath the SortedList class?

A sorted HashTable.

Will the finally block get executed if an exception has not occurred?

Yes.

What’s the C# syntax to catch 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 {}.


There are two primary exception throwing scenarios:

- Throwing a new exception (creating and throwing it)

- Re-Throwing an exception (an exception that has been caught within a try/catch block)


THROWING (a new exception):

However, when it comes to "throwing" exceptions I have one rule that is the most important of all.


Rule: Throw an exception only when the current request/process simply can not progress due to incorrect, insufficient data, or otherwise. If this code is in the UI an exception should rarely be thrown since a user can usually be notified of the error - such as an incorrect password. However, for middle tier or non-UI code, throwing an exception is most likely the correct response.

RE-THROWING (an existing exception):

The primary rule I have when "Re-Throwing" an exception is:

Rule: Re-Throw an exception ONLY when you are adding value to the exception process such as adding data to the exception for debugging purposes. Otherwise, the try/catch should not even be used since the exception will naturally propagate up the call stack.

Can multiple catch blocks be executed for a single try statement?

No. Once the proper catch block processed, control is transferred to the finally block (if there are any).

Explain the three services model commonly know as a three-tier application.

Presentation (UI)

Business (logic and underlying code)

Data (from storage or other sources)

0 comments;Click here for request info on this topic:

Post a Comment