Tuesday, February 23, 2010

Example: How to implement IEnumerable interface and use with LINQ

IEnumerable(T) Interface
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.

public class DataCollection<> : IEnumerable<>

{

         List _list<> = new List<>();



         public IEnumerator<> GetEnumerator()

         {

                  return _list.GetEnumerator();

         }

}
Note: Mention T in < > 
Understanding IEnumerable
The IEnumerable interface is a key part of LINQ to Objects and binds many of its different features together into a whole. This series of posts explainsIEnumerable and the role it plays in LINQ to Objects. If you hear people talking about IEnumerable, and sometimes wished you better understood its significance, then you should find this text helpful.
Collections and IEnumerable
Though LINQ to Objects can be used to query several C# types, it cannot be used against all your in-process data sources. Those that can be queried all support theIEnumerable interface. These include the generic collections found in the System.Collections.Generic namespace. The commonly used types found in this namespace include List, Stack, LinkedList, Queue, Dictionary and Hashset.
All of the collections in the System.Collections.Generic namespace support the IEnumerable interface. Here, for instance, is the declaration for List:
public class List : IList, ICollection, IEnumerable, IList, ICollection, IEnumerable
You will find IEnumerable listed for all the other generic collections. It is no coincidence that these collections support IEnumerable. Their implementation of this interface makes it possible to query them using LINQ to Objects.
LINQ to Objects and IEnumerable
Consider the following simple LINQ query:
List<int> list = new List<int> { 1, 3, 2 };
// The LINQ Query expression
var query = from num in list
            where num < 3
            select num;
foreach (var item in query)
{
    Console.WriteLine(item);
}
The type IEnumerable plays two key roles in this code.
  • The query expression has a data source called list which implements IEnumerable
  • The query expression returns an instance of IEnumberable.
Every LINQ to Objects query expression, including the one shown above, will begin with a line of this type:
from x in y
In each case, the data source represented by the variable y must support the IEnumerable interface. As you have already seen, the list of integers shown in this example supports that interface.
The same query shown here could also be written as follows:
IEnumerable<int> query = from num in list
                         where num < 3
                         select num;
This code makes explicit the type of the variable returned by this query. As you can see, it is of type IEnumerable. In practice, you will find that most LINQ to Objects queries return IEnumerable, for some type T. The only exceptions are those that call a LINQ query operator that return a simple type, such as Count():
int number = (from num in list
              where num < 3
              select num).Count();
In this case the query returns an integer specifying the number of items in the list created by this query. LINQ queries that return a simple type like this are an exception to the rule that LINQ to Objects queries operate on class that implement IEnumerable and return an instance that supports IEnumerable.
Composable
The fact that LINQ to Objects queries both take and return IEnumerable enables a key feature of LINQ called composability. Because LINQ queries are composable you can usually pass the result of one LINQ query to another LINQ query. This allows you to compose a series of queries that work together to achieve a single end:
List<int> list = new List<int> { 1, 3, 2 };

var query1 = from num in list
             where num < 3
             select num;

var query2 = from num in query1
             where num > 1
             select num;

var query3 = from num1 in query1
             from num2 in query2
             select num1 + num2;
Here the results of the first query are used as the data source for the second query, and the results of the first two queries are both used as data sources for the third query. If you print out the results of query3 with a foreach loop you get the numbers 3 and 4. Though it is not important to the current subject matter, you might have fun playing with the code to understand why these values are returned.
Summary
By now it should be clear to you that IEnumerable plays a central role in LINQ to Objects. A typical LINQ to Objects query expression not only takes a class that implements IEnumerable as its data source, but it also returns an instance of this same type. The fact that it takes and returns the same type enables a feature called composability.
The next logical question would be to ask why this type plays such a key role in LINQ to Objects. One simple answer would be that the creators of LINQ decided that it should be so, and hence it is so. But one can still ask why they picked this particular type. What is it about IEnumerable that makes it a useful data source and return type for LINQ to Objects queries? The answer to that question will be found in the second part of this series of articles.

Monday, February 22, 2010

SIMSOFT Logo

ASP.Net Page Life Cycle

Introduction
For ASP.NET developers, understanding the ASP.NET page lifecycle is important for many reasons, but primarily for knowing where to place particular methods, and when various page properties are set. However, it can often be difficult to remember and make sense out of all of the methods available in the page lifecycle. While there are scores of articles on the internet related to the internal mechanics of the page lifecycle, this article intends to begin by covering the basics and providing a simple and easy understanding of usage.
It can be difficult to remember exactly what happens and when during the ASP.NET page lifecycle. That in mind, often the easiest way to make sense out of a series of steps is to create an acronym. Microsoft shows us the basic steps of the ASP.NET page lifecycle below.
1. Page Request
2. Start
3. Page Initialization
4. Load
5. Validation
6. Postback event handling
7. Rendering
8. Unload
Putting together an acronym for these is easy enough. Since the Page Request technically isn't a part of the life cycle (it only indicates whether we actually will start the cycle or load a cached page) we won't include it in the acronym.
• S – Start
• I – Initialize
• L – Load
• V – Validate
• E – Event Handling
• R – Render
That gives us "SILVER", which is very easy to remember. However, it is important remember that the last part of the cycle is unload. You can remember it as "SILVER-U" or "SILVER-YOU" if that helps (but it just didn't quite fit into our acronym!). Now that it's easy to remember the order of steps for the page lifecycle, we'll summarize exactly what happens and what events are pertinent to each stage.
1. Start
This is where page properties such as Request, Response, IsPostBack and UICulture are set. As a developer, you most likely won't really need to do anything in this stage of the cycle. If you need to access or override behavior for this step, use the PreInit method to create or re-create dynamic controls, set a master page or theme or read or set profile property values. It is important to note that if the request is a postback, the values of the controls have not yet been restored from view state. If you set a control property at this stage, its value might be overwritten in the next event.
2. Initialize
This stage can be very important to developers. Here, themes are applied, and unique ids are generated and set for controls. Developers have access to the Init, InitComplete and PreLoad methods in this stage. Microsoft's recommended usage for these methods is as follows:
• Init – This event is raised after all controls have been initialized and any skin settings have been applied. Use this event to read or initialize control properties.
• InitComplete – This event is raised by the Page object. Use this event for processing tasks that require all initialization be complete.
• PreLoad - Use this event if you need to perform processing on your page or control before the Load event. After the Page raises this event, it loads view state for itself and all controls, and then processes any postback data included with the Request instance.
3. Load
This stage is perhaps the most utilized by developers. In this stage controls are loaded with information retrieved from view and control states. The OnLoad is the event method that fires during this stage. This is where you will want to set properties for all of the server controls on your page, request query strings, and establish database connections.
4. Validation
If you have controls that require validation, they are validated here and you can now check the IsValid property of the control. The event associated with this is Validate, which contains one overloaded method that accepts a validation group string. The overloaded method instructs the controls in the specified group to validate.
5. Event Handling
The event handling for server controls occurs during this stage. This means that events such as Click, SelectedIndexChanged, etc are applied to your server controls, and, in the case of a postback, these event handlers are fired by the control. The accessible events of note in this stage are as follows:
• LoadComplete – At this step, all of the controls for the page have been loaded.
• PreRender – A few things of import happen here. First, the page object will call EnsureChildControls for each control, and finally for the page. Additionally, any data bound control that has a DataSourceID set will call its DataBind method. It is important to note that the PreRender event occurs for each control on the page. At the conclusion of this event, ViewState will be saved for the page and all of the controls.
• SaveStateComplete – ViewState has been saved. If you have actions that do not require changes to controls but require ViewState to have been saved, you can handle the SaveStateComplete event.
6. Render
Render is not really an event. Rather, the page object calls this method on each control, which in turn writes out the HTML markup for the control to the browser. This stage is keenly important to developers who create custom controls, because the standard approach is to override the Render method for the control in order to output the custom markup. If your control inherits from a standard ASP.NET server control, you probably won't need to override the Render method unless you want to exhibit a different behavior than the control's default. This is outside the scope of this document, but for more reading, you can reference Microsoft's Developing Custom ASP.NET Server Controls. (http://msdn2.microsoft.com/en-us/library/zt27tfhy.aspx)
7. Unload
This final event occurs first for each control, then, finally, for the page. At this point, all controls have been rendered to the output stream and cannot be changed. During this event any attempt to access the response stream will result in an exception being thrown. This event is primarily for cleanup routines such as closing open database connections and open file streams, or, event logging and other tasks.
Methods
The following methods (which can all be overridden) occur in order during the lifecycle of an ASP.NET page. Please realize that some of these methods are called recursively, and multiple times depending on the content of the page. This list is the generalized order in which methods fire when a page loads. You can test this by creating a default ASP.NET application, overloading each of the below methods, and setting a breakpoint on each.
1. Construct
2. ProcessRequest
3. FrameworkInitialize
4. InitializeCulture
5. If child controls are present:
1. AddParsedSubObject
2. CreateControlCollection
3. AddedControl
4. ResolveAdapter
6. DeterminePostBackMode
7. OnPreInit
8. OnInit
9. TrackViewState
10. OnInitComplete
11. OnPreLoad
12. OnLoad
13. OnLoadComplete
14. EnsureChildControls
1. CreateChildControls
15. OnPreRender
16. OnPreRenderComplete
17. SaveViewState
18. OnSaveStateComplete
19. CreateHtmlTextWriter
20. RenderControl
21. Render
1. RenderChildren
2. VerifyRenderingInServerForm
22. OnUnload
23. Dispose
Conclusion
When developing ASP.NET applications, it's important to know what happens when. Understanding how events unfold inside of the page will save you several hours of headache and debugging. While the order of the methods may be hard to remember, I hope that applying the anagram will be of considerable use when determining what needs to happen where inside of your application.
I put this article together as much to help other people, as to help myself. Even experienced developers can sometimes forget the order in which things occur. This is not intended to be an all-encompassing article. Rather, it is my hope that beginning and intermediate developers can carry this "hip pocket" material around to help mitigate at least some of the more common mistakes.

Happy ASP.NET'ing!

Asim Riaz: 11 Little-Known Ways to Advance Your Career

Asim Riaz: 11 Little-Known Ways to Advance Your Career

Friday, February 19, 2010

11 Little-Known Ways to Advance Your Career

The employment situation today has workers feeling a little uneasy.

As the unemployment rate soared to 8.5 percent in March -- its highest rate since 1983 -- and the number of unemployed people increased to 13.2 million, according to the Bureau of Labor Statistics, the lucky people who are still employed are probably looking for a little job security.

Although nothing guarantees that your job is 100 percent secure, it doesn't hurt to implement "the little things" to increase your visibility and help you advance professionally.

Here are 11 simple, yet often overlooked, ways to advance your career in tough economic times:

1. Request the help of well-known professionals in your community
When she was starting out, Karen Fuqua, president of Fuqua Consulting Group, she wrote to the top 50 business women listed in Fortune magazine and asked if they would be willing to mentor a new professional; if not, did they have any advice?

"I had no idea what I would get back. The letters I received were fabulous," Fuqua recalls. "Top C-level women wrote back to me with encouragement, tips and advice as to what to do and not to do as a woman in business. It was easy to do and surprisingly effective."

2. Learn your work products
Try to get quality examples of the products your bosses are working on so that you know what quality output is, says Sean Ebner, regional vice president for Technisource, an IT recruiting and solutions company. When your boss gets sick or goes on vacation, volunteer to create the work product. This will help your boss and distinguish you above your peers.

3. Volunteer for the little things
Volunteer for a prominent role in community outreach activities, Ebner suggests. By doing so, you are more likely to get exposure to senior management.

Ebner gives the example of an old co-worker who had not done particularly well in college. His academics barred him from joining the firm as a consultant, so he joined the HR group in an administrative role.

"This gentleman gold plated everything that was asked of him and sought ways to help the office managing partner with personal items such as remembering birthdays and getting things for his wife," he says. "After about a year, this person was elevated to the consulting practice at a level higher than he would have entered directly from college. It was the relationships he had fostered and the focus on the little details of what he did that made the difference."

4. Stay on top of your industry
"Attend industry-related conferences or network with people in your industry online. Also, keep interacting with potential clients that aren't necessarily in your arena -- they may lead to a big sale in the future," says Kristen Fischer, author of "Ramen Noodles, Rent and Résumés." "You never know where a contact will take you."

5. Hone your public speaking and presentation skills
Most people hate any form of public speaking but it is one of the most potent publicity and marketing vehicles available to you, says Laurent Duperval, president of Duperval Consulting.

"Volunteer for any and every speaking opportunity that presents itself. You will be seen as a knowledgeable and competent individual," he says. "Since you are most likely the most visible person to boot, your name will be first on the list when promotion time comes around."

6. Be nice
It seems obvious, but in a marketplace where jobs are scarce and uncertainty is rampant, nerves get frayed easily, Duperval says.

"Step above the heap and be nice to people around you, especially when things go bad. In pressure situations, those who can keep their cool, their calm and still keep on smiling and laughing stand out," he says. "Those are the qualities you want in your leaders."

7. State your opinion even if it goes against the crowd
Be logical and strategic about stating your opinion. The idea is not to be against every idea or suggestion offered by other employees, Duperval says.

"If you feel strongly against an issue, learn to present and argue the facts compellingly. Doing so logically, while appealing to everyone's self-interest as well as the best interests of the company, is an uncommon skill, one that has tremendous value for any corporation."

8. Befriend your company's PR person
By getting quoted in articles or appearing on air as an "expert source," you are attracting attention to your firm and yourself, says Sammie Becker, CEO and founder of TigressPR.

"Volunteer to be speaker at a conference, an industry panel or even webinar," she says. "Something that your new best friend -- the public relations person -- can help you do or navigate."

9. Know the company
Study the company, the way it does business and its products, regardless of whether the information is relevant to your job or not, says Judi Perkins, a career coach.

"Know the trends in your industry and what your competitors are doing. For a VP, this is expected. For a customer service person, this sets you apart and marks you as someone to watch."

10. Notice other people's efforts
If your company has a newsletter, read it. Give kudos to people whether you know them or not, Perkins says. Don't forget to say thank you to those who offer their assistance to you in any way.


11. Get to know your boss, but don't curry favor
Know what the boss values in his staff. If he wants people to think through a problem before coming for help with a solution, don't go running to his office at the first hint of difficulty, Perkins says.

7 Signs That Your Job Could Be in Jeopardy

Recent economic news is enough to make even the most assured professional feel unsettled about his or her job. It's only natural to question your own career prospects when confronted with headlines about the rising unemployment rate and companies' plans to reduce staff levels in the coming year.

While it does no good to worry unnecessarily, there are ways to determine if your role is in real danger. Following are seven possible signs:

1. Your workload becomes much lighter. If you've noticed a considerable drop in the amount of work you've been assigned, or you just finished a large project and nothing else appears to be coming your way, there could be cause for concern. A dwindling workload may indicate reduced business and, consequently, less need for your services. Similarly, if you're not being included in key projects that you were in the past -- or tasks you typically handle are being assigned to others -- there's a chance your position may be eliminated.

2. Your work is cyclical in nature. Companies that are looking to trim personnel expenses often focus on departments or positions in which the work is cyclical, and the day-to-day workload could be supported with fewer people.

3. Your position isn't viewed as a revenue-generator. When budgets are reduced, priority is given to employees who are inextricably attached to profit-producing projects. How pivotal is your role in generating revenue or reducing expenses? If you contribute directly to these efforts, you may be in a fairly safe position. If, on the other hand, your role is viewed more as a "nice to have" than "need to have," you could be on shakier ground.

4. You're not being kept in the loop. This is one of the biggest signs that your job is in jeopardy. If you discover decisions about your immediate work activities or projects are being made without you, you have cause for concern.

5. Corporate belt-tightening. A sharp change in the company's attitude toward basic expenses could be a tip-off that personnel levels also are being considered. Implementing one or two cost-cutting measures might simply be good fiscal policy, but several can signal more widespread cutbacks. It's important to note, however, that many companies that are belt-tightening aren't necessarily looking to reduce head count. They may be taking these steps to avoid letting people go.

6. You're being asked to document everything. When management shows an increased interest in the status of your projects and the procedures for completing them, it could be because they want to get a better sense of how things are done and what still requires attention should your tasks need to be reassigned.

7. Your sector is struggling. If your company competes in an industry that is experiencing a down cycle, layoffs may be inevitable. If your firm is affected significantly, it may reduce the size of its work force to deal with the economic realities it faces.

Spotting one or two of these signs may not be cause for alarm. In fact, it could be a signal that you need to step up your game. If you enjoy your job and want to stay, continue to focus on producing high-quality work and demonstrating your value to the organization.

That said, it never hurts to have a backup plan just in case you find yourself suddenly in the job market. Make sure your résumé is up-to-date and reconnect with members of your professional network. Also consider enlisting the help of a recruiter who specializes in your industry. These professionals can provide you with valuable career advice and, because of their deep networks within the local business community, can alert you to promising employment opportunities. Layoffs can sometimes occur with little warning, and the more prepared you are for a job search, the more quickly you'll be back on your feet and working again.

C# Interview Questions

This is a list of questions I have gathered from other sources and created myself over a period of time from my experience, many of which I felt where incomplete or simply wrong. I have finally taken the time to go through each question and correct them to the best of my ability. However, please feel free to post feedback to challenge, improve, or suggest new questions. I want to thank those of you that have contributed quality questions and corrections thus far.
There are some question in this list that I do not consider to be good questions for an interview. However, they do exist on other lists available on the Internet so I felt compelled to keep them easy access.
General Questions
1. Does C# support multiple-inheritance?
No.

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

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

4. Describe the accessibility modifier “protected internal”.
It is available to classes that are within the same assembly and derived from the specified base class.

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

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

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

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

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

10. 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 identacle object.

11. How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.

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

13. What class is underneath the SortedList class?
A sorted HashTable.

14. Will the finally block get executed if an exception has not occurred?¬
Yes.

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

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

17. Explain the three services model commonly know as a three-tier application.
Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources).

Class Questions
1. What is the syntax to inherit from a class in C#?
Place a colon and then the name of the base class.
Example: class MyNewClass : MyBaseClass

2. Can you prevent your class from being inherited by another class?
Yes. The keyword “sealed” will prevent the class from being inherited.

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

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

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

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

7. Why can’t you specify the accessibility modifier for methods inside the interface?
They all must be public, and are therefore public by default.

8. Can you inherit multiple interfaces?
Yes. .NET does support multiple interfaces.

9. 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.
To Do: Investigate

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

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

Method and Property Questions
1. 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.

2. What does the keyword “virtual” declare for a method or property?
The method or property can be overridden.

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

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

5. What are the different ways a method can be overloaded?
Different parameter data types, different number of parameters, different order of parameters.

6. 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
1. What’s a delegate?
A delegate object encapsulates a reference to a method.

2. What’s a multicast delegate?
A delegate that has multiple handlers assigned to it. Each assigned handler (method) is called.

XML Documentation Questions
1. Is XML case-sensitive?
Yes.

2. What’s the difference between // comments, /* */ comments and /// comments?
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?
Compile it with the /doc switch.

Debugging and Testing Questions
1. 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.

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

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

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

5. Where is the output of TextWriterTraceListener redirected?
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?
Attach the aspnet_wp.exe process to the DbgClr debugger.

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

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

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

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

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

5. What connections does Microsoft SQL Server support?
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?
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?
The database name to connect to.

8. What does the Dispose method do with the connection object?
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?
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?
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?
An MSI installer, a CAB archive, and XCOPY command.

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

4. What namespaces are necessary to create a localized application?
System.Globalization and System.Resources.

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

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

7. How do you convert a value-type to a reference-type?
Use Boxing.

8. 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.
ASP.NET Interview Questions
This is a list of questions I have gathered and created over a period of time from my experience, many of which I felt where incomplete or simply wrong. I have finally taken the time to go through each question and correct them to the best of my ability. However, please feel free to post feedback to challenge, improve, or suggest new questions. I want to thank those of you that have contributed quality questions and corrections thus far.
There are some questions in this list that I do not consider to be good questions for an interview. However, they do exist on other lists available on the Internet so I felt compelled to keep them here for easy access.
1. 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.

2. What’s the difference between Response.Write() andResponse.Output.Write()?
Response.Output.Write() allows you to write formatted output.

3. What methods are fired during the page load?
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.

4. When during the page processing cycle is ViewState available?
After the Init() and before the Page_Load(), or OnLoad() for a control.

5. What namespace does the Web page belong in the .NET Framework class hierarchy?
System.Web.UI.Page

6. Where do you store the information about the user’s locale?
System.Web.UI.Page.Culture

7. What’s the difference between Codebehind="MyCode.aspx.cs" andSrc="MyCode.aspx.cs"?
CodeBehind is relevant to Visual Studio.NET only.

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

9. 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();");

10. What data types do the RangeValidator control support?
Integer, String, and Date.

11. Explain the differences between Server-side and Client-side code?
Server-side code executes on the server. Client-side code executes in the client's browser.

12. 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 clients browser. But just to be clear, code-behind executes on the server, thus making it server-side code.

13. Should user input data validation occur 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 feasable to provide a richer, more responsive experience for the user.

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

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

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

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

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

19. Whats an assembly?
Assemblies are the building blocks of the .NET framework. Overview of assemblies from MSDN

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

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

22. Whats MSIL, and why should my developers need an appreciation of it if at all?
MSIL is the Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL. MSIL also allows the .NET Framework to JIT compile the assembly on the installed computer.

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

24. Can you edit data in the Repeater control?
No, it just reads the information from its data source.

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

26. How can you provide an alternating color scheme in a Repeater control?
Use the AlternatingItemTemplate.

27. What property must you set, and what method must you call in your code, in order to bind the data from a data source to the Repeater control?
You must set the DataSource property and call the DataBind method.

28. What base class do all Web Forms inherit from?
The Page class.

29. Name two properties common in every validation control?
ControlToValidate property and Text property.

30. 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?
DataTextField property.

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

32. How many classes can a single .NET DLL contain?
It can contain many classes.

Web Service Questions
1. What is the transport protocol you use to call a Web service?
SOAP (Simple Object Access Protocol) is the preferred protocol.

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

3. What does WSDL stand for?
Web Services Description Language.

4. Where on the Internet would you look for Web services?
http://www.uddi.org

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

State Management Questions
1. 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 the retain the state of server-side objects between postabacks.

2. What is the lifespan for items stored in ViewState?
Item stored in ViewState exist for the life of the current page. This includes postbacks (to the same page).

3. 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 postbacks. 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 clients browser. When the page is posted back to the server the server control is recreated with the state stored in viewstate.

4. 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 a "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.
.NET Remoting Interview Questions
To Do: Comfirm these are correct answers. Many of these question I have obtained from other sources and have found they are not entirely correct, or simply wrong.
1. What’s a Windows process?
It’s an application that’s running and had been allocated memory.

2. What’s typical about a Windows process in regards to memory allocation?
Each process is allocated its own block of available RAM space, no process can access another process’ code or data. If the process crashes, it dies alone without taking the entire OS or a bunch of other applications down.

3. Explain what relationship is between a Process, Application Domain, and Application?
A process is an instance of a running application. An application is an executable on the hard drive or network. There can be numerous processes launched of the same application (5 copies of Word running), but 1 process can run just 1 application.

4. What are possible implementations of distributed applications in .NET?
.NET Remoting and ASP.NET Web Services. If we talk about the Framework Class Library, noteworthy classes are in System.Runtime.Remoting and System.Web.Services.

5. What are the consideration in deciding to use .NET Remoting or ASP.NET Web Services?
Remoting is a more efficient communication exchange when you can control both ends of the application involved in the communication process. Web Services provide an open-protocol-based exchange of informaion. Web Services are best when you need to communicate with an external organization or another (non-.NET) technology.

6. What’s a proxy of the server object in .NET Remoting?
It’s a fake copy of the server object that resides on the client side and behaves as if it was the server. It handles the communication between real server object and the client object. This process is also known as marshaling.

7. What are remotable objects in .NET Remoting?
Remotable objects are the objects that can be marshaled across the application domains. You can marshal by value, where a deep copy of the object is created and then passed to the receiver. You can also marshal by reference, where just a reference to an existing object is passed.

8. What are channels in .NET Remoting?
Channels represent the objects that transfer the other serialized objects from one application domain to another and from one computer to another, as well as one process to another on the same box. A channel must exist before an object can be transferred.

9. What security measures exist for .NET Remoting in System.Runtime.Remoting?
None. Security should be taken care of at the application level. Cryptography and other security techniques can be applied at application or server level.

10. What is a formatter?
A formatter is an object that is responsible for encoding and serializing data into messages on one end, and deserializing and decoding messages into data on the other end.

11. Choosing between HTTP and TCP for protocols and Binary and SOAP for formatters, what are the trade-offs?
Binary over TCP is the most effiecient, SOAP over HTTP is the most interoperable.

12. What’s SingleCall activation mode used for?
If the server object is instantiated for responding to just one single request, the request should be made in SingleCall mode.

13. What’s Singleton activation mode?
A single object is instantiated regardless of the number of clients accessing it. Lifetime of this object is determined by lifetime lease.

14. How do you define the lease of the object?
By implementing ILease interface when writing the class code.

15. Can you configure a .NET Remoting object via XML file?
Yes, via machine.config and application level .config file (or web.config in ASP.NET). Application-level XML settings take precedence over machine.config.

16. How can you automatically generate interface for the remotable object in .NET with Microsoft tools?
Use the Soapsuds tool.

Ten Tough Interview Questions and Ten Great Answers

Mental fear of the unknown is often what produces the physical symptoms of nervousness. In addition to preparing yourself physically, you need to prepare yourself mentally. The best way to prepare mentally is to know what may be coming. Fear of the unknown can only exist when there is an unknown. Take the time to understand some of the “standards” when it comes to interviewing questions.
The following are some of the most difficult questions you will face in the course of your job interviews. Some questions may seem rather simple on the surface—such as “Tell me about yourself”—but these questions can have a variety of answers. The more open ended the question, the wider the variation in the answers. Once you have become practiced in your interviewing skills, you will find that you can use almost any question as a launching pad for a particular topic or compelling story.
Others are classic interview questions, such as “What is your greatest weakness?” Questions most people answer improperly. In this case, the standard textbook answer for the “greatest weakness” question is to provide a veiled positive such as: “I work too much. I just work and work and work.” Wrong. Either you are lying or, worse yet, you are telling the truth, in which case you define working too much as a weakness and really do not want to work much at all.
The following answers are provided to give you a new perspective on how to answer tough interview questions. They are not there for you to lift from the page and insert into your next interview. They are provided for you to use as the basic structure for formulating your own answers. While the specifics of each reply may not apply to you, try to follow the basic structure of the answer from the perspective of the interviewer. Answer the questions behaviorally, with specific examples that show that clear evidence backs up what you are saying about yourself. Always provide information that shows you want to become the very best _____ for the company and that you have specifically prepared yourself to become exactly that. They want to be sold. They are waiting to be sold. Don’t disappoint them!
1. Tell me about yourself.
It seems like an easy interview question. It’s open ended. I can talk about whatever I want from the birth canal forward. Right?
Wrong. What the hiring manager really wants is a quick, two- to three-minute snapshot of who you are and why you’re the best candidate for this position.
So as you answer this question, talk about what you’ve done to prepare yourself to be the very best candidate for the position. Use an example or two to back it up. Then ask if they would like more details. If they do, keep giving them example after example of your background and experience. Always point back to an example when you have the opportunity.
“Tell me about yourself” does not mean tell me everything. Just tell me what makes you the best.
2. Why should I hire you?
The easy answer is that you are the best person for the job. And don’t be afraid to say so. But then back it up with what specifically differentiates you.
For example: “You should hire me because I’m the best person for the job. I realize that there are likely other candidates who also have the ability to do this job. Yet I bring an additional quality that makes me the best person for the job--my passion for excellence. I am passionately committed to producing truly world class results. For example . . .”
Are you the best person for the job? Show it by your passionate examples.
3. What is your long-range objective?
Make my job easy for me. Make me want to hire you.
The key is to focus on your achievable objectives and what you are doing to reach those objectives.
For example: “Within five years, I would like to become the very best accountant your company has on staff. I want to work toward becoming the expert that others rely upon. And in doing so, I feel I’ll be fully prepared to take on any greater responsibilities which might be presented in the long term. For example, here is what I’m presently doing to prepare myself . . .”
Then go on to show by your examples what you are doing to reach your goals and objectives.
4. How has your education prepared you for your career?
This is a broad question and you need to focus on the behavioral examples in your educational background which specifically align to the required competencies for the career.
An example: “My education has focused on not only the learning the fundamentals, but also on the practical application of the information learned within those classes. For example, I played a lead role in a class project where we gathered and analyzed best practice data from this industry. Let me tell you more about the results . . .”
Focus on behavioral examples supporting the key competencies for the career. Then ask if they would like to hear more examples.
5. Are you a team player?
Almost everyone says yes to this question. But it is not just a yes/no question. You need to provide behavioral examples to back up your answer.
A sample answer: “Yes, I’m very much a team player. In fact, I’ve had opportunities in my work, school and athletics to develop my skills as a team player. For example, on a recent project . . .”
Emphasize teamwork behavioral examples and focus on your openness to diversity of backgrounds. Talk about the strength of the team above the individual. And note that this question may be used as a lead in to questions around how you handle conflict within a team, so be prepared.
6. Have you ever had a conflict with a boss or professor? How was it resolved?
Note that if you say no, most interviewers will keep drilling deeper to find a conflict. The key is how you behaviorally reacted to conflict and what you did to resolve it.
For example: “Yes, I have had conflicts in the past. Never major ones, but there have been disagreements that needed to be resolved. I've found that when conflict occurs, it helps to fully understand the other person’s perspective, so I take time to listen to their point of view, then I seek to work out a collaborative solution. For example . . .”
Focus your answer on the behavioral process for resolving the conflict and working collaboratively.
7. What is your greatest weakness?
Most career books tell you to select a strength and present it as a weakness. Such as: “I work too much. I just work and work and work.” Wrong. First of all, using a strength and presenting it as a weakness is deceiving. Second, it misses the point of the question.
You should select a weakness that you have been actively working to overcome. For example: “I have had trouble in the past with planning and prioritization. However, I’m now taking steps to correct this. I just started using a pocket planner . . .” then show them your planner and how you are using it.
Talk about a true weakness and show what you are doing to overcome it.
8. If I were to ask your professors to describe you, what would they say?
This is a threat of reference check question. Do not wait for the interview to know the answer. Ask any prior bosses or professors in advance. And if they’re willing to provide a positive reference, ask them for a letter of recommendation.
Then you can answer the question like this:
“I believe she would say I'm a very energetic person, that I’m results oriented and one of the best people she has ever worked with. Actually, I know she would say that, because those are her very words. May I show you her letter of recommendation?”
So be prepared in advance with your letters of recommendation.
9. What qualities do you feel a successful manager should have?
Focus on two words: leadership and vision.
Here is a sample of how to respond: “The key quality in a successful manager should be leadership--the ability to be the visionary for the people who are working under them. The person who can set the course and direction for subordinates. The highest calling of a true leader is inspiring others to reach the highest of their abilities. I'd like to tell you about a person whom I consider to be a true leader . . .”
Then give an example of someone who has touched your life and how their impact has helped in your personal development.
10. If you had to live your life over again, what one thing would you change?
Focus on a key turning point in your life or missed opportunity. Yet also tie it forward to what you are doing to still seek to make that change.
For example: “Although I’m overall very happy with where I’m at in my life, the one aspect I likely would have changed would be focusing earlier on my chosen career. I had a great internship this past year and look forward to more experience in the field. I simply wish I would have focused here earlier. For example, I learned on my recent internship…” …then provide examples.
Stay focused on positive direction in your life and back it up with examples.
In reviewing these responses, please remember that they are only to be viewed samples. Please do not rehearse them verbatim or adopt them as your own. They are meant to stir your creative juices and get you thinking about how to properly answer the broader range of questions that you will face.
Fifty Standard Interview Questions

It is not enough to have solid answers for only the above questions. You need to be prepared for the full spectrum of questions that may be presented. For further practice, make sure you go through the required mock interview (see the Competitive Interview Prep chapter); and for further review, look at some of the following questions:
1. Tell me about yourself.
2. Tell me about your experience.
3. What is your most important accomplishment to date?
4. How would you describe your ideal job?
5. Why did you choose this career?
6. When did you decide on this career?
7. What goals do you have in your career?
8. How do you plan to achieve these goals?
9. How do you personally define success?
10. Describe a situation in which you were successful.
11. What do you think it takes to be successful in this career?
12. What accomplishments have given you the most satisfaction in your life?
13. If you had to live your life over again, what one thing would you change?
14. Would you rather work with information or with people?
15. Are you a team player?
16. What motivates you?
17. Why should I hire you?
18. Are you a goal-oriented person?
19. Tell me about some of your recent goals and what you did to achieve them.
20. What are your short-term goals?
21. What is your long-range objective?
22. What do you see yourself doing five years from now?
23. Where do you want to become ten years from now?
24. Do you handle conflict well?
25. Have you ever had a conflict with a boss or professor? How did you resolve it?
26. What major problem have you had to deal with recently?
27. Do you handle pressure well?
28. What is your greatest strength?
29. What is your greatest weakness?
30. If I were to ask one of your professors (or a boss) to describe you, what would he or she say?
31. Why did you choose to attend your college?
32. What changes would you make at your college?
33. How has your education prepared you for your career?
34. What were your favorite classes? Why?
35. Do you enjoy doing independent research?
36. Who were your favorite professors? Why?
37. Why is your GPA not higher?
38. Do you have any plans for further education?
39. How much training do you think you’ll need to become a productive employee?
40. What qualities do you feel a successful manager should have?
41. Why do you want to work in the _____ industry?
42. What do you know about our company?
43. Why are you interested in our company?
44. Do you have any location preferences?
45. How familiar are you with the community that we’re located in?
46. Are you willing to relocate? In the future?
47. Are you willing to travel? How much?
48. Is money important to you?
49. How much money do you need to make to be happy?
50. What kind of salary are you looking for?
Don’t just read these questions—practice and rehearse the answers. Don’t let the employer interview be the first time you actually formulate an answer in spoken words. It is not enough to think about them in your head—practice! Sit down with a friend, a significant other, or your roommate (an especially effective critic, given the amount of preparation to date) and go through all of the questions. If you have not yet completed a mock interview, do it now. Make the most of every single interview opportunity by being fully prepared!
Top Ten Critical Success Factors

With all the different questions being referenced, you may wonder what exactly the employer is seeking. And I will tell you.
Following is the list of the top ten critical success factors that nearly every employer is seeking:
1. Positive attitude toward work
2. Proficiency in field of study
3. Communication skills (oral and written)
4. Interpersonal skills
5. Confidence
6. Critical thinking and problem-solving skills
7. Flexibility
8. Self-motivation
9. Leadership
10. Teamwork
Show your competence in as many of these critical success factors as possible and you will rise above the competition.

Popular Posts