<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4777054191702843272</id><updated>2011-07-08T01:16:35.640-07:00</updated><category term='web/IIS configuration'/><category term='Double'/><category term='Mouse Move'/><category term='MS Access'/><category term='System.String'/><category term='Database Concepts'/><category term='VS.NET'/><category term='.Dotnet basics'/><category term='Classes and Object model in .NET'/><category term='ADO.NET programming'/><category term='DivideByZeroException'/><category term='Delete'/><category term='DataTable'/><category term='Mouse Click'/><category term='sqlserver'/><category term='using System'/><category term='Event driven programming'/><category term='connectionString'/><category term='System.IO.StreamReader'/><category term='Visual Studio .NET 2005'/><category term='float'/><category term='WinForms'/><category term='C# Language Syntax'/><category term='web.config'/><category term='while'/><category term='dotnet pdf'/><category term='.net   interview questions and answers'/><category term='foreach'/><category term='webservices'/><category term='C# Coding'/><category term='object'/><category term='c# object oriented programming'/><category term='ConfigurationSettings.'/><category term='XML'/><category term='.net interview questions'/><category term='System.IO.File.Exists()'/><category term='int'/><category term='visual studio .net'/><category term='MessageBox buttons'/><category term='Read'/><category term='private.constructor'/><category term='try'/><category term='ADO.NET sampleExecuteNonQuery()'/><category term='HttpException.System.ArithmeticException'/><category term='.net projects'/><category term='.NET framework'/><category term='Introducing the .NET Framework'/><category term='Visual Studio .NET 3.5'/><category term='System.IO.Path.GetExtension'/><category term='Accessing database using ADO.NET in C# or VB.NET'/><category term='Exceptions'/><category term='byte'/><category term='ado.net tutorial'/><category term='uint'/><category term='myAdapter.Fill'/><category term='.NET'/><category term='MessageBox icons'/><category term='Namespaces'/><category term='OpenFileDialog'/><category term='public'/><category term='Button Click'/><category term='MessageBox'/><category term='DataTypes in C#'/><category term='Int32'/><category term='WriteXml'/><category term='Oracle'/><category term='doubl'/><category term='visual studio .net tutorial'/><category term='Connection.Open()'/><category term='string'/><category term='Dotnet online course'/><category term='.net basics'/><category term='Toolbox'/><category term='Visual C# Projects'/><category term='System.Data.SqlClient System.Data.OleDb'/><category term='DataSet'/><category term='C# sample for retrieving html content from any websites'/><category term='Int16'/><category term='System.Xml'/><category term='.net architecture diagram'/><category term='.net   tutorial'/><category term='System.Net.WebRequest()'/><category term='Configuration Files'/><category term='DataAdapter'/><category term='asp.net code free download'/><category term='.net architecture'/><category term='Visual Studio .NET 2008'/><category term='How to create a DataTable'/><category term='ystem.Net.WebRequest.GetResponse()'/><category term='C# sample for basic file operations'/><category term='long'/><category term='catch'/><category term='c sharp'/><category term='c# namespace'/><category term='&quot;Hello World&quot; using c#'/><category term='Property in C# class'/><category term='char'/><category term='Create'/><category term='Custom Exceptions'/><category term='.net interview questions and answers'/><category term='DialogResult'/><category term='Exception classes in .NET'/><category term='System.Net.WebRequest.Create(url)'/><category term='System.Exception'/><category term='DataRow'/><category term='Namespaces in.net'/><category term='sbyte'/><category term='Dotnet projects'/><category term='Displaying Simple MessageBox'/><category term='Key Press'/><category term='Database'/><category term='&quot;Hello World&quot; Application in .net'/><category term='DataReader'/><category term='Define .NET framework ?'/><category term='Application Configuration Files'/><category term='visual studio .net free download'/><category term='GetXml()'/><category term='Update'/><category term='Debugging in VS.NET'/><category term='Visual Studio .NET 2010'/><category term='System.Windows.Forms.Form'/><category term='Exception Handling in .NET'/><category term='using System.Configuration'/><category term='What Is .NET ?'/><category term='bool'/><title type='text'>.NET TUTOR</title><subtitle type='html'>ALL TYPES OF DOTNET MATERIALS AND DOTNET PROJECTS WILL BE AVAILABLE IN THIS BLOG</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>24</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-3468921956316758291</id><published>2010-05-03T11:17:00.001-07:00</published><updated>2010-05-07T22:47:53.352-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='C# Coding'/><category scheme='http://www.blogger.com/atom/ns#' term='ado.net tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='.net interview questions and answers'/><category scheme='http://www.blogger.com/atom/ns#' term='c sharp'/><category scheme='http://www.blogger.com/atom/ns#' term='asp.net code free download'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET framework'/><category scheme='http://www.blogger.com/atom/ns#' term='.net architecture diagram'/><category scheme='http://www.blogger.com/atom/ns#' term='.Dotnet basics'/><category scheme='http://www.blogger.com/atom/ns#' term='.net interview questions'/><title type='text'>C# Coding Standards and Best Programming Practices</title><content type='html'>1. &amp;nbsp; &amp;nbsp;Introduction&lt;br /&gt;&lt;br /&gt;Anybody can write code. With a few months of programming experience, you can write 'working applications'. Making it work is easy, but doing it the right way requires more work, than just making it work.&lt;br /&gt;&lt;br /&gt;Believe it, majority of the programmers write 'working code', but not ‘good code'. Writing 'good code' is an art and you must learn and practice it.&lt;br /&gt;&lt;br /&gt;Everyone may have different definitions for the term ‘good code’. In my definition, the following are the characteristics of good code.&lt;br /&gt;&lt;br /&gt;· &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Reliable&lt;br /&gt;· &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Maintainable&lt;br /&gt;· &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Efficient&lt;br /&gt;&lt;br /&gt;Most of the developers are inclined towards writing code for higher performance, compromising reliability and maintainability. But considering the long term ROI (Return On Investment), efficiency and performance comes below reliability and maintainability. If your code is not reliable and maintainable, you (and your company) will be spending lot of time to identify issues, trying to understand code etc throughout the life of your application.&lt;br /&gt;&lt;br /&gt;2. &amp;nbsp; &amp;nbsp;Purpose of coding standards and best practices&lt;br /&gt;&lt;br /&gt;To develop reliable and maintainable applications, you must follow coding standards and best practices.&lt;br /&gt;&lt;br /&gt;The naming conventions, coding standards and best practices described in this document are compiled from our own experience and by referring to various Microsoft and non Microsoft guidelines.&lt;br /&gt;&lt;br /&gt;There are several standards exists in the programming industry. None of them are wrong or bad and you may follow any of them. What is more important is, selecting one standard approach and ensuring that everyone is following it.&lt;br /&gt;&lt;br /&gt;3. &amp;nbsp; &amp;nbsp;How to follow the standards across the team&lt;br /&gt;&lt;br /&gt;If you have a team of different skills and tastes, you are going to have a tough time convincing everyone to follow the same standards. The best approach is to have a team meeting and developing your own standards document. You may use this document as a template to prepare your own document.&lt;br /&gt;&lt;br /&gt;Distribute a copy of this document (or your own coding standard document) well ahead of the coding standards meeting. All members should come to the meeting prepared to discuss pros and cons of the various points in the document. Make sure you have a manager present in the meeting to resolve conflicts.&lt;br /&gt;&lt;br /&gt;Discuss all points in the document. Everyone may have a different opinion about each point, but at the end of the discussion, all members must agree upon the standard you are going to follow. Prepare a new standards document with appropriate changes based on the suggestions from all of the team members. Print copies of it and post it in all workstations.&lt;br /&gt;&lt;br /&gt;After you start the development, you must schedule code review meetings to ensure that everyone is following the rules. 3 types of code reviews are recommended:&lt;br /&gt;&lt;br /&gt;Peer review – another team member review the code to ensure that the code follows the coding standards and meets requirements. This level of review can include some unit testing also. Every file in the project must go through this process.&lt;br /&gt;Architect review – the architect of the team must review the core modules of the project to ensure that they adhere to the design and there is no “big” mistakes that can affect the project in the long run.&lt;br /&gt;Group review – randomly select one or more files and conduct a group review once in a week. Distribute a printed copy of the files to all team members 30 minutes before the meeting. Let them read and come up with points for discussion. In the group review meeting, use a projector to display the file content in the screen. Go through every sections of the code and let every member give their suggestions on how could that piece of code can be written in a better way. (Don’t forget to appreciate the developer for the good work and also make sure he does not get offended by the “group attack”!)&lt;br /&gt;&lt;br /&gt;4. &amp;nbsp; &amp;nbsp;Naming Conventions and Standards&lt;br /&gt;&lt;br /&gt;Note :&lt;br /&gt;The terms Pascal Casing and Camel Casing are used throughout this document.&lt;br /&gt;Pascal Casing - First character of all words are Upper Case and other characters are lower case.&lt;br /&gt;Example: BackColor&lt;br /&gt;Camel Casing - First character of all words, except the first word are Upper Case and other characters are lower case.&lt;br /&gt;Example: backColor&lt;br /&gt;&lt;br /&gt;1. &amp;nbsp; &amp;nbsp; Use Pascal casing for Class names&lt;br /&gt;&lt;br /&gt;public class HelloWorld&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;2. &amp;nbsp; &amp;nbsp; Use Pascal casing for Method names&lt;br /&gt;&lt;br /&gt;void SayHello(string name)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3. &amp;nbsp; &amp;nbsp; Use Camel casing for variables and method parameters&lt;br /&gt;&lt;br /&gt;int totalCount = 0;&lt;br /&gt;void SayHello(string name)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; string fullMessage = "Hello " + name;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;4. &amp;nbsp; &amp;nbsp; Use the prefix “I” with Camel Casing for interfaces ( Example: IEntity )&lt;br /&gt;&lt;br /&gt;5. &amp;nbsp; &amp;nbsp; Do not use Hungarian notation to name variables.&lt;br /&gt;&lt;br /&gt;In earlier days most of the programmers liked it - having the data type as a prefix for the variable name and using m_ as prefix for member variables. Eg:&lt;br /&gt;&lt;br /&gt;string m_sName;&lt;br /&gt;int nAge;&lt;br /&gt;&lt;br /&gt;However, in .NET coding standards, this is not recommended. Usage of data type and m_ to represent member variables should not be used. All variables should use camel casing.&lt;br /&gt;&lt;br /&gt;Some programmers still prefer to use the prefix m_ to represent member variables, since there is no other easy way to identify a member variable.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;6. &amp;nbsp; &amp;nbsp; Use Meaningful, descriptive words to name variables. Do not use abbreviations.&lt;br /&gt;&lt;br /&gt;Good:&lt;br /&gt;&lt;br /&gt;string address&lt;br /&gt;int salary&lt;br /&gt;&lt;br /&gt;Not Good:&lt;br /&gt;&lt;br /&gt;string nam&lt;br /&gt;string addr&lt;br /&gt;int sal&lt;br /&gt;&lt;br /&gt;7. &amp;nbsp; &amp;nbsp; Do not use single character variable names like i, n, s etc. Use names like index, temp&lt;br /&gt;&lt;br /&gt;One exception in this case would be variables used for iterations in loops:&lt;br /&gt;&lt;br /&gt;for ( int i = 0; i &amp;lt; count; i++ )&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; ...&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;If the variable is used only as a counter for iteration and is not used anywhere else in the loop, many people still like to use a single char variable (i) instead of inventing a different suitable name.&lt;br /&gt;&lt;br /&gt;8. &amp;nbsp; &amp;nbsp; Do not use underscores (_) for local variable names.&lt;br /&gt;&lt;br /&gt;9. &amp;nbsp; &amp;nbsp; All member variables must be prefixed with underscore (_) so that they can be identified from other local variables.&lt;br /&gt;&lt;br /&gt;10. &amp;nbsp;Do not use variable names that resemble keywords.&lt;br /&gt;&lt;br /&gt;11. &amp;nbsp;Prefix boolean variables, properties and methods with “is” or similar prefixes.&lt;br /&gt;&lt;br /&gt;Ex: private bool _isFinished&lt;br /&gt;&lt;br /&gt;12. &amp;nbsp;Namespace names should follow the standard pattern&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;13. &amp;nbsp; Use appropriate prefix for the UI elements so that you can identify them from the rest of the variables.&lt;br /&gt;&lt;br /&gt;There are 2 different approaches recommended here.&lt;br /&gt;&lt;br /&gt;a. &amp;nbsp; &amp;nbsp; Use a common prefix ( ui_ ) for all UI elements. This will help you group all of the UI elements together and easy to access all of them from the intellisense.&lt;br /&gt;&lt;br /&gt;b. &amp;nbsp; &amp;nbsp; Use appropriate prefix for each of the ui element. A brief list is given below. Since .NET has given several controls, you may have to arrive at a complete list of standard prefixes for each of the controls (including third party controls) you are using.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Control&lt;br /&gt;Prefix&lt;br /&gt;Label&lt;br /&gt;lbl&lt;br /&gt;TextBox&lt;br /&gt;txt&lt;br /&gt;DataGrid&lt;br /&gt;dtg&lt;br /&gt;Button&lt;br /&gt;btn&lt;br /&gt;ImageButton&lt;br /&gt;imb&lt;br /&gt;Hyperlink&lt;br /&gt;hlk&lt;br /&gt;DropDownList&lt;br /&gt;ddl&lt;br /&gt;ListBox&lt;br /&gt;lst&lt;br /&gt;DataList&lt;br /&gt;dtl&lt;br /&gt;Repeater&lt;br /&gt;rep&lt;br /&gt;Checkbox&lt;br /&gt;chk&lt;br /&gt;CheckBoxList&lt;br /&gt;cbl&lt;br /&gt;RadioButton&lt;br /&gt;rdo&lt;br /&gt;RadioButtonList&lt;br /&gt;rbl&lt;br /&gt;Image&lt;br /&gt;img&lt;br /&gt;Panel&lt;br /&gt;pnl&lt;br /&gt;PlaceHolder&lt;br /&gt;phd&lt;br /&gt;Table&lt;br /&gt;tbl&lt;br /&gt;Validators&lt;br /&gt;val&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;14. &amp;nbsp;File name should match with class name.&lt;br /&gt;&lt;br /&gt;For example, for the class HelloWorld, the file name should be helloworld.cs (or, helloworld.vb)&lt;br /&gt;&lt;br /&gt;15. &amp;nbsp;Use Pascal Case for file names.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;5. &amp;nbsp; &amp;nbsp;Indentation and Spacing&lt;br /&gt;&lt;br /&gt;1. &amp;nbsp; &amp;nbsp; Use TAB for indentation. Do not use SPACES. &amp;nbsp;Define the Tab size as 4.&lt;br /&gt;&lt;br /&gt;2. &amp;nbsp; &amp;nbsp; Comments should be in the same level as the code (use the same level of indentation).&lt;br /&gt;&lt;br /&gt;Good:&lt;br /&gt;&lt;br /&gt;// Format a message and display&lt;br /&gt;&lt;br /&gt;string fullMessage = "Hello " + name;&lt;br /&gt;DateTime currentTime = DateTime.Now;&lt;br /&gt;string message = fullMessage + ", the time is : " + currentTime.ToShortTimeString();&lt;br /&gt;MessageBox.Show ( message );&lt;br /&gt;&lt;br /&gt;Not Good:&lt;br /&gt;&lt;br /&gt;// Format a message and display&lt;br /&gt;string fullMessage = "Hello " + name;&lt;br /&gt;DateTime currentTime = DateTime.Now;&lt;br /&gt;string message = fullMessage + ", the time is : " + currentTime.ToShortTimeString();&lt;br /&gt;MessageBox.Show ( message );&lt;br /&gt;&lt;br /&gt;3. &amp;nbsp; &amp;nbsp; Curly braces ( {} ) should be in the same level as the code outside the braces.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;4. &amp;nbsp; &amp;nbsp; Use one blank line to separate logical groups of code.&lt;br /&gt;&lt;br /&gt;Good:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; bool SayHello ( string name )&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string fullMessage = "Hello " + name;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DateTime currentTime = DateTime.Now;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string message = fullMessage + ", the time is : " + currentTime.ToShortTimeString();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MessageBox.Show ( message );&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if ( ... )&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Do something&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // ...&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return true;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;Not Good:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; bool SayHello (string name)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string fullMessage = "Hello " + name;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DateTime currentTime = DateTime.Now;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string message = fullMessage + ", the time is : " + currentTime.ToShortTimeString();&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;MessageBox.Show ( message );&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if ( ... )&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Do something&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // ...&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return true;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;5. &amp;nbsp; &amp;nbsp; There should be one and only one single blank line between each method inside the class.&lt;br /&gt;&lt;br /&gt;6. &amp;nbsp; &amp;nbsp; The curly braces should be on a separate line and not in the same line as if, for etc.&lt;br /&gt;&lt;br /&gt;Good:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if ( ... ) &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Do something&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;br /&gt;Not Good:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if ( ... ) &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Do something&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;br /&gt;7. &amp;nbsp; &amp;nbsp; Use a single space before and after each operator and brackets.&lt;br /&gt;&lt;br /&gt;Good:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if ( showResult == true )&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for ( int i = 0; i &amp;lt; 10; i++ )&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;br /&gt;Not Good:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(showResult==true)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(int &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;i= 0;i&amp;lt;10;i++)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;8. &amp;nbsp; &amp;nbsp; Use #region to group related pieces of code together. If you use proper grouping using #region, the page should like this when all definitions are collapsed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;9. &amp;nbsp; &amp;nbsp; Keep private member variables, properties and methods in the top of the file and public members in the bottom.&lt;br /&gt;&lt;br /&gt;6. &amp;nbsp; &amp;nbsp;Good Programming practices&lt;br /&gt;&lt;br /&gt;1. &amp;nbsp; &amp;nbsp; Avoid writing very long methods. A method should typically have 1~25 lines of code. If a method has more than 25 lines of code, you must consider re factoring into separate methods.&lt;br /&gt;&lt;br /&gt;2. &amp;nbsp; &amp;nbsp; Method name should tell what it does. Do not use mis-leading names. If the method name is obvious, there is no need of documentation explaining what the method does.&lt;br /&gt;&lt;br /&gt;Good:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; void SavePhoneNumber ( string phoneNumber )&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Save the phone number.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;Not Good:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; // This method will save the phone number.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; void SaveDetails ( string phoneNumber )&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Save the phone number.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;3. &amp;nbsp; &amp;nbsp; A method should do only 'one job'. Do not combine more than one job in a single method, even if those jobs are very small.&lt;br /&gt;&lt;br /&gt;Good:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; // Save the address.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SaveAddress ( &amp;nbsp;address );&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; // Send an email to the supervisor to inform that the address is updated.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SendEmail ( address, email ); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; void SaveAddress ( string address )&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Save the address.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// ...&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; void SendEmail ( string address, string email )&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Send an email to inform the supervisor that the address is changed.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// ...&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;Not Good:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; // Save address and send an email to the supervisor to inform that&lt;br /&gt;// the address is updated.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; SaveAddress ( address, email );&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; void SaveAddress ( string address, string email )&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Job 1.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Save the address.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// ...&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Job 2.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Send an email to inform the supervisor that the address is changed.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// ...&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;4. &amp;nbsp; &amp;nbsp; Use the c# or VB.NET specific types (aliases), rather than the types defined in System namespace.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; int age; &amp;nbsp; (not Int16)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; string name; &amp;nbsp;(not String)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; object contactInfo; (not Object)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;Some developers prefer to use types in Common Type System than language specific aliases.&lt;br /&gt;&lt;br /&gt;5. &amp;nbsp; &amp;nbsp; Always watch for unexpected values. For example, if you are using a parameter with 2 possible values, never assume that if one is not matching then the only possibility is the other value.&lt;br /&gt;&lt;br /&gt;Good:&lt;br /&gt;&lt;br /&gt;If ( memberType == eMemberTypes.Registered )&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; // Registered user… do something…&lt;br /&gt;}&lt;br /&gt;else if ( memberType == eMemberTypes.Guest )&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; // Guest user... do something…&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Un expected user type. Throw an exception&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;throw new Exception (“Un expected value “ + memberType.ToString() + “’.”)&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// If we introduce a new user type in future, we can easily find&lt;br /&gt;// the problem here.&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Not Good:&lt;br /&gt;&lt;br /&gt;If ( memberType == eMemberTypes.Registered )&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Registered user… do something…&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;// Guest user... do something…&lt;br /&gt;&lt;br /&gt;// If we introduce another user type in future, this code will&lt;br /&gt;// fail and will not be noticed.&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;6. &amp;nbsp; &amp;nbsp; Do not hardcode numbers. Use constants instead. Declare constant in the top of the file and use it in your code.&lt;br /&gt;&lt;br /&gt;However, using constants are also not recommended. You should use the constants in the config file or database so that you can change it later. Declare them as constants only if you are sure this value will never need to be changed.&lt;br /&gt;&lt;br /&gt;7. &amp;nbsp; &amp;nbsp; Do not hardcode strings. Use resource files.&lt;br /&gt;&lt;br /&gt;8. &amp;nbsp; &amp;nbsp; Convert strings to lowercase or upper case before comparing. This will ensure the string will match even if the string being compared has a different case.&lt;br /&gt;&lt;br /&gt;if ( name.ToLower() == “john” )&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //…&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;9. &amp;nbsp; &amp;nbsp; Use String.Empty instead of “”&lt;br /&gt;&lt;br /&gt;Good:&lt;br /&gt;&lt;br /&gt;If ( name == String.Empty )&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; // do something&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Not Good:&lt;br /&gt;&lt;br /&gt;If ( name == “” )&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; // do something&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;10. &amp;nbsp;Avoid using member variables. Declare local variables wherever necessary and pass it to other methods instead of sharing a member variable between methods. If you share a member variable between methods, it will be difficult to track which method changed the value and when.&lt;br /&gt;&lt;br /&gt;11. &amp;nbsp;Use enum wherever required. Do not use numbers or strings to indicate discrete values.&lt;br /&gt;&lt;br /&gt;Good:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; enum MailType&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Html,&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PlainText,&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Attachment&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; void SendMail (string message, MailType mailType)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;switch ( mailType )&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case MailType.Html:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Do something&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case MailType.PlainText:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Do something&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case MailType.Attachment:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Do something&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; default:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Do something&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Not Good:&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; void SendMail (string message, string mailType)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;switch ( mailType )&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case "Html":&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Do something&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case "PlainText":&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Do something&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; case "Attachment":&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Do something&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; default:&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Do something&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; break;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;12. &amp;nbsp;Do not make the member variables public or protected. Keep them private and expose public/protected Properties.&lt;br /&gt;&lt;br /&gt;13. &amp;nbsp;The event handler should not contain the code to perform the required action. Rather call another method from the event handler.&lt;br /&gt;&lt;br /&gt;14. &amp;nbsp;Do not programmatically click a button to execute the same action you have written in the button click event. Rather, call the same method which is called by the button click event handler.&lt;br /&gt;&lt;br /&gt;15. &amp;nbsp;Never hardcode a path or drive name in code. Get the application path programmatically and use relative path.&lt;br /&gt;&lt;br /&gt;16. &amp;nbsp;Never assume that your code will run from drive "C:". You may never know, some users may run it from network or from a "Z:".&lt;br /&gt;&lt;br /&gt;17. &amp;nbsp;In the application start up, do some kind of "self check" and ensure all required files and dependancies are available in the expected locations. Check for database connection in start up, if required. Give a friendly message to the user in case of any problems.&lt;br /&gt;&lt;br /&gt;18. &amp;nbsp;If the required configuration file is not found, application should be able to create one with default values.&lt;br /&gt;&lt;br /&gt;19. &amp;nbsp;If a wrong value found in the configuration file, application should throw an error or give a message and also should tell the user what are the correct values.&lt;br /&gt;&lt;br /&gt;20. &amp;nbsp;Error messages should help the user to solve the problem. Never give error messages like "Error in Application", "There is an error" etc. Instead give specific messages like "Failed to update database. Please make sure the login id and password are correct."&lt;br /&gt;&lt;br /&gt;21. &amp;nbsp;When displaying error messages, in addition to telling what is wrong, the message should also tell what should the user do to solve the problem. Instead of message like "Failed to update database.", suggest what should the user do: "Failed to update database. Please make sure the login id and password are correct."&lt;br /&gt;&lt;br /&gt;22. &amp;nbsp;Show short and friendly message to the user. But log the actual error with all possible information. This will help a lot in diagnosing problems.&lt;br /&gt;&lt;br /&gt;23. &amp;nbsp;Do not have more than one class in a single file.&lt;br /&gt;&lt;br /&gt;24. &amp;nbsp;Have your own templates for each of the file types in Visual Studio. You can include your company name, copy right information etc in the template. You can view or edit the Visual Studio file templates in the folder C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplatesCache\CSharp\1033. (This folder has the templates for C#, but you can easily find the corresponding folders or any other language)&lt;br /&gt;&lt;br /&gt;25. &amp;nbsp;Avoid having very large files. If a single file has more than 1000 lines of code, it is a good candidate for refactoring. Split them logically into two or more classes.&lt;br /&gt;&lt;br /&gt;26. &amp;nbsp; Avoid public methods and properties, unless they really need to be accessed from outside the class. Use “internal” if they are accessed only within the same assembly.&lt;br /&gt;&lt;br /&gt;27. &amp;nbsp; Avoid passing too many parameters to a method. If you have more than 4~5 parameters, it is a good candidate to define a class or structure.&lt;br /&gt;&lt;br /&gt;28. &amp;nbsp; If you have a method returning a collection, return an empty collection instead of null, if you have no data to return. For example, if you have a method returning an ArrayList, always return a valid ArrayList. If you have no items to return, then return a valid ArrayList with 0 items. This will make it easy for the calling application to just check for the “count” rather than doing an additional check for “null”.&lt;br /&gt;&lt;br /&gt;29. &amp;nbsp; Use the AssemblyInfo file to fill information like version number, description, company name, copyright notice etc.&lt;br /&gt;&lt;br /&gt;30. &amp;nbsp; Logically organize all your files within appropriate folders. Use 2 level folder hierarchies. You can have up to 10 folders in the root folder and each folder can have up to 5 sub folders. If you have too many folders than cannot be accommodated with the above mentioned 2 level hierarchy, you may need re factoring into multiple assemblies.&lt;br /&gt;&lt;br /&gt;16. &amp;nbsp;Make sure you have a good logging class which can be configured to log errors, warning or traces. If you configure to log errors, it should only log errors. But if you configure to log traces, it should record all (errors, warnings and trace). Your log class should be written such a way that in future you can change it easily to log to Windows Event Log, SQL Server, or Email to administrator or to a File etc without any change in any other part of the application. Use the log class extensively throughout the code to record errors, warning and even trace messages that can help you trouble shoot a problem.&lt;br /&gt;&lt;br /&gt;17. &amp;nbsp;If you are opening database connections, sockets, file stream etc, always close them in the finally block. This will ensure that even if an exception occurs after opening the connection, it will be safely closed in the finally block.&lt;br /&gt;&lt;br /&gt;18. &amp;nbsp;Declare variables as close as possible to where it is first used. Use one variable declaration per line.&lt;br /&gt;&lt;br /&gt;19. &amp;nbsp;Use StringBuilder class instead of String when you have to manipulate string objects in a loop. The String object works in weird way in .NET. Each time you append a string, it is actually discarding the old string object and recreating a new object, which is a relatively expensive operations.&lt;br /&gt;&lt;br /&gt;Consider the following example:&lt;br /&gt;&lt;br /&gt;public string ComposeMessage (string[] lines)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; string message = String.Empty;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; for (int i = 0; i &amp;lt; lines.Length; i++)&lt;br /&gt;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;message += lines [i];&lt;br /&gt;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; return message;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;In the above example, it may look like we are just appending to the string object ‘message’. But what is happening in reality is, the string object is discarded in each iteration and recreated and appending the line to it.&lt;br /&gt;&lt;br /&gt;If your loop has several iterations, then it is a good idea to use StringBuilder class instead of String object.&lt;br /&gt;&lt;br /&gt;See the example where the String object is replaced with StringBuilder.&lt;br /&gt;&lt;br /&gt;public string ComposeMessage (string[] lines)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;StringBuilder message = new StringBuilder();&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;for (int i = 0; i &amp;lt; lines.Length; i++)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; message.Append( lines[i] );&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;return message.ToString();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;7. &amp;nbsp; &amp;nbsp;Architecture&lt;br /&gt;&lt;br /&gt;1. &amp;nbsp; &amp;nbsp; Always use multi layer (N-Tier) architecture.&lt;br /&gt;&lt;br /&gt;2. &amp;nbsp; &amp;nbsp;Never access database from the UI pages. Always have a data layer class which performs all the database related tasks. This will help you support or migrate to another database back end easily.&lt;br /&gt;&lt;br /&gt;3. &amp;nbsp; &amp;nbsp;Use try-catch in your data layer to catch all database exceptions. This exception handler should record all exceptions from the database. The details recorded should include the name of the command being executed, stored proc name, parameters, connection string used etc. After recording the exception, it could be re thrown so that another layer in the application can catch it and take appropriate action.&lt;br /&gt;&lt;br /&gt;4. &amp;nbsp; &amp;nbsp;Separate your application into multiple assemblies. Group all independent utility classes into a separate class library. All your database related files can be in another class library.&lt;br /&gt;&lt;br /&gt;8. &amp;nbsp; &amp;nbsp;ASP.NET&lt;br /&gt;&lt;br /&gt;1. &amp;nbsp; &amp;nbsp; Do not use session variables throughout the code. Use session variables only within the classes and expose methods to access the value stored in the session variables. A class can access the session using System.Web.HttpCOntext.Current.Session&lt;br /&gt;&lt;br /&gt;2. &amp;nbsp; &amp;nbsp; Do not store large objects in session. Storing large objects in session may consume lot of server memory depending on the number of users.&lt;br /&gt;&lt;br /&gt;3. &amp;nbsp; &amp;nbsp; Always use style sheet to control the look and feel of the pages. Never specify font name and font size in any of the pages. Use appropriate style class. This will help you to change the UI of your application easily in future. Also, if you like to support customizing the UI for each customer, it is just a matter of developing another style sheet for them&lt;br /&gt;&lt;br /&gt;9. &amp;nbsp; &amp;nbsp;Comments&lt;br /&gt;&lt;br /&gt;Good and meaningful comments make code more maintainable. However,&lt;br /&gt;&lt;br /&gt;1. &amp;nbsp; &amp;nbsp; Do not write comments for every line of code and every variable declared.&lt;br /&gt;&lt;br /&gt;2. &amp;nbsp; &amp;nbsp; Use // or /// for comments. Avoid using /* … */&lt;br /&gt;&lt;br /&gt;3. &amp;nbsp; &amp;nbsp; Write comments wherever required. But good readable code will require very less comments. If all variables and method names are meaningful, that would make the code very readable and will not need many comments.&lt;br /&gt;&lt;br /&gt;4. &amp;nbsp; &amp;nbsp; Do not write comments if the code is easily understandable without comment. The drawback of having lot of comments is, if you change the code and forget to change the comment, it will lead to more confusion.&lt;br /&gt;&lt;br /&gt;5. &amp;nbsp; &amp;nbsp; Fewer lines of comments will make the code more elegant. But if the code is not clean/readable and there are less comments, that is worse.&lt;br /&gt;&lt;br /&gt;6. &amp;nbsp; &amp;nbsp; If you have to use some complex or weird logic for any reason, document it very well with sufficient comments.&lt;br /&gt;&lt;br /&gt;7. &amp;nbsp; &amp;nbsp; If you initialize a numeric variable to a special number other than 0, -1 etc, document the reason for choosing that value.&lt;br /&gt;&lt;br /&gt;8. &amp;nbsp; &amp;nbsp; The bottom line is, write clean, readable code such a way that it doesn't need any comments to understand.&lt;br /&gt;&lt;br /&gt;9. &amp;nbsp; &amp;nbsp; Perform spelling check on comments and also make sure proper grammar and punctuation is used.&lt;br /&gt;&lt;br /&gt;10. Exception Handling&lt;br /&gt;&lt;br /&gt;1. &amp;nbsp; &amp;nbsp; Never do a 'catch exception and do nothing'. If you hide an exception, you will never know if the exception happened or not. Lot of developers uses this handy method to ignore non significant errors. You should always try to avoid exceptions by checking all the error conditions programmatically. In any case, catching an exception and doing nothing is not allowed. In the worst case, you should log the exception and proceed.&lt;br /&gt;&lt;br /&gt;2. &amp;nbsp; &amp;nbsp; In case of exceptions, give a friendly message to the user, but log the actual error with all possible details about the error, including the time it occurred, method and class name etc.&lt;br /&gt;&lt;br /&gt;3. &amp;nbsp; &amp;nbsp; Always catch only the specific exception, not generic exception.&lt;br /&gt;&lt;br /&gt;Good:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; void ReadFromFile ( string fileName )&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;try&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // read from file.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;catch (FileIOException ex)&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // log error.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // &amp;nbsp;re-throw exception depending on your case.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throw;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;Not Good:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;void ReadFromFile ( string fileName )&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;// read from file.&lt;br /&gt;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp; catch (Exception ex) &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;// Catching general exception is bad... we will never know whether&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;// it was a file error or some other error. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;// Here you are hiding an exception.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;// In this case no one will ever know that an exception happened.&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;return ""; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&lt;br /&gt;4. &amp;nbsp; &amp;nbsp; No need to catch the general exception in all your methods. Leave it open and let the application crash. This will help you find most of the errors during development cycle. You can have an application level (thread level) error handler where you can handle all general exceptions. In case of an 'unexpected general error', this error handler should catch the exception and should log the error in addition to giving a friendly message to the user before closing the application, or allowing the user to 'ignore and proceed'.&lt;br /&gt;&lt;br /&gt;5. &amp;nbsp; &amp;nbsp; When you re throw an exception, use the throw statement without specifying the original exception. This way, the original call stack is preserved.&lt;br /&gt;&lt;br /&gt;Good:&lt;br /&gt;&lt;br /&gt;catch&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; // do whatever you want to handle the exception&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Not Good:&lt;br /&gt;&lt;br /&gt;catch (Exception ex)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; // do whatever you want to handle the exception&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw ex;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;6. &amp;nbsp; &amp;nbsp; Do not write try-catch in all your methods. Use it only if there is a possibility that a specific exception may occur and it cannot be prevented by any other means. For example, if you want to insert a record if it does not already exists in database, you should try to select record using the key. Some developers try to insert a record without checking if it already exists. If an exception occurs, they will assume that the record already exists. This is strictly not allowed. You should always explicitly check for errors rather than waiting for exceptions to occur. On the other hand, you should always use exception handlers while you communicate with external systems like network, hardware devices etc. Such systems are subject to failure anytime and error checking is not usually reliable. In those cases, you should use exception handlers and try to recover from error.&lt;br /&gt;&lt;br /&gt;7. &amp;nbsp; &amp;nbsp; Do not write very large try-catch blocks. If required, write separate try-catch for each task you perform and enclose only the specific piece of code inside the try-catch. This will help you find which piece of code generated the exception and you can give specific error message to the user.&lt;br /&gt;&lt;br /&gt;8. &amp;nbsp; &amp;nbsp; &amp;nbsp;Write your own custom exception classes if required in your application. Do not derive your custom exceptions from the base class SystemException. Instead, inherit from ApplicationException.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-3468921956316758291?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/3468921956316758291/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/c-coding-standards-and-best-programming_03.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/3468921956316758291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/3468921956316758291'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/c-coding-standards-and-best-programming_03.html' title='C# Coding Standards and Best Programming Practices'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-4893550146975643533</id><published>2010-05-03T09:29:00.002-07:00</published><updated>2010-05-03T11:39:02.278-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='visual studio .net tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='.net projects'/><category scheme='http://www.blogger.com/atom/ns#' term='.net   tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='.net architecture diagram'/><category scheme='http://www.blogger.com/atom/ns#' term='.Dotnet basics'/><category scheme='http://www.blogger.com/atom/ns#' term='.net interview questions'/><category scheme='http://www.blogger.com/atom/ns#' term='.net architecture'/><category scheme='http://www.blogger.com/atom/ns#' term='webservices'/><category scheme='http://www.blogger.com/atom/ns#' term='.net   interview questions and answers'/><title type='text'>Web Services</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;Webservices are services exposed over the internet. Typically, webservice is just like any other class library, written in any language. What make it a&amp;nbsp;&lt;b&gt;'web service'&lt;/b&gt;&amp;nbsp;is, it can be accessed across internet.&lt;br /&gt;&lt;br /&gt;Eventhough webservice is a new technology with a wide range of usage, it is a pretty simple concept. It doesn't require much additional knowledge to create web services if you are already familiar with C# or VB.NET. (Web services are not specific to .NET. Even Java has web service applications, but here we are discussing only the .NET web services.)&lt;br /&gt;&lt;br /&gt;As we mentioned, web services are exposed over internet. To make this happen, it has to be hosted with a web site. Othen than hosted as part of a web site to make this visible across internet, web services have no web pages or UI. It is just a set of classes with public/private methods and properties.&lt;br /&gt;&lt;br /&gt;Web services are a group of [web] methods. Consumer applications can treat this as just another class library. Regular class libraries are located along with the same application and we can call any methods in the class libraries (assemblies). But in case of web services, the assembly is located in the internet server. The consumer application will not have direct access to the assembly. Consumer applications have to add a reference to the webservice URL and then call methods in it. The method call goes across the internet using&amp;nbsp;&lt;span class="v12b"&gt;SOAP protocal&lt;/span&gt;&amp;nbsp;and results are returned across internet in the form of XML. The communication across internet happens transparently and the application need not know anything about this communication.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Creating a simple web service&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you are using VS.NET, it won't take more than 2-3 minutes to create your first webservice. Follow the steps below to create a web service:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Choose&amp;nbsp;&lt;b&gt;New Project&lt;/b&gt;from VS.NET and create a C# project of type 'ASP.NET Web Service' and give the name 'MyWebService'&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;The new project will have a default page 'Service1.asmx'. This is your first web service page. Web service pages have the extension&amp;nbsp;&lt;b&gt;.asmx&lt;/b&gt;&amp;nbsp;(like ASP.NET pages have the extension&lt;b&gt;.aspx&lt;/b&gt;)&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;The code behind file 'Service1.asmx.cs' have a class 'Service1'. This is like other regular classes with the only difference that it inherits the system class&lt;b&gt;System.Web.Services.WebService&lt;/b&gt;. This is required for web service classes.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;VS.NET creates a sample method for you. All you have to do is, uncomment the following method in Service1.asmx.cs&amp;nbsp;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;//[WebMethod]&lt;br /&gt;//public string HelloWorld()&lt;br /&gt;//{&lt;br /&gt;//return "Hello World";&lt;br /&gt;//}&lt;/pre&gt;&lt;/span&gt;Note that this method is pretty much same as any other regular method.&lt;br /&gt;The only difference is, it has an attribute [WebMethod]. This attribute make&lt;br /&gt;the method visible across internet. If you remove this attribute, your&lt;br /&gt;application will still compile, but the consumer applications cannot call this&lt;br /&gt;method across internet.&lt;br /&gt;&lt;br /&gt;Ok, thats all you have to do to create a simple webservice. Build your solution and your web service is ready to be called by other applications.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Create a consumer application&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A wide range of applications can consume the web services, including web page, other web services, windows applications etc. let us create a sample windows application and call our web service.&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Create a new C# Windows Application.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Right click on the 'References' in the Solution Explorer, under your project name. Choose 'Web References'.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Another window will open and will allow you to specify the URL of the web service to be referenced.&lt;br /&gt;&lt;br /&gt;Type the URL of your web service in the space provided for 'URL'. If you have created the web service in the local machine's default web site, the URL might be like this :&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;http://localhost/MyWebService/Service1.asmx&lt;/pre&gt;&lt;/span&gt;If you have given a different name fro the project or if you have changed the default service name, then your URL may differ. Type the URL and press enter. It will attempt to connect with the web service and if succeeded it will retrieve the public web methods and display. Once you get this success screen, press the 'Add Reference' button on the screen to add the web reference to your application. There is a space to specify the 'web reference name', which will have the default value 'localhost'. Leave it as it is.&lt;br /&gt;&lt;br /&gt;Now you are ready to make calls to the webservice. Just use the following code in your application:&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;localhost.Service1 service = new localhost.Service1();&lt;br /&gt;string result = service.HelloWorld();&lt;br /&gt;&lt;br /&gt;MessageBox.Show( result );&lt;/pre&gt;&lt;/span&gt;Let us analyze our code. The first line creates an instance of the Service1 class, just like any regular class. Only thing is it uses the namespace 'localhost'. This is same as the 'web reference name' we specified while adding the web reference. We can use any web reference name when we add the reference and have to use the same name as namespace while making calls to the web service class.&lt;br /&gt;&lt;br /&gt;In the second line, we are actually calling the web method 'HelloWorld()' and it returns the result as a string. Note this is just like any other method call. So, your application makes the call to web service as if it is calling any local class library calls!! The communication with web service, wrapping your calls in SOAP/XML, retrieve results from web service, unwrap the SOAP/XML to get the actual result etc are done behind the scene by the framework and you need not do any additional work to make all this work.&lt;br /&gt;&lt;br /&gt;Now you can go back to your web service, add more methods with different parameters and play around with that. You will be able to call methods in the web service just like you use any local class. Note that when you make any changes to the method name or parameters, or if you add new methods, you will need to refresh your web reference to get access to the updated web service methods. To do this, go to the Server Explorer, right click on the web reference name 'localhost' under the 'Web References'. Then choose 'Refresh'. This will communicate with the web service again and retrieve the latest web service data.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;How does all this work?&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;To make calls to any classes, your application need to know the details of the class. To successfully compile your code, it has to have information about the class, what are the public methods and properties etc. But in your sample code which calls the web service, the actual&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;Service1&lt;/span&gt;class resides in the web (in your case, in your local web server). So how does the application compile without having the '&lt;span style="color: blue; font-family: Courier;"&gt;Service1&lt;/span&gt;' class in your application?&lt;br /&gt;&lt;br /&gt;This is where the framework help you. When you add a 'web reference' to the web service URL, VS.NET actually creates&amp;nbsp;&lt;b&gt;local proxy&lt;/b&gt;&amp;nbsp;in your application. A local proxy is a minimal version of the actual class. The proxy has just the sufficient information about the 'real class', which is required for your application to successfully compile. The proxy class has the list of all public web methods in the real web service class and it knows the parameters and their data types of each method.&lt;br /&gt;&lt;br /&gt;The most important thing is, your application is actually using this proxy class and not the real web service class.&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;localhost.Service1 service = new localhost.Service1();&lt;br /&gt;string result = service.HelloWorld();&lt;br /&gt;&lt;br /&gt;MessageBox.Show( result );&lt;/pre&gt;&lt;/span&gt;In the above code,&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;localhost.Service1&lt;/span&gt;is actually the proxy class (a representative of a real class), which is created automatically by VS.NET when you added the web reference. You are creating an instance of the proxy class and calling the '&lt;span style="color: blue; font-family: Courier;"&gt;HelloWorld()&lt;/span&gt;' method of this proxy. Since the proxy class knows that it is 'only a proxy of the real class', it redirects all calls to the 'real web service class'. The method '&lt;span style="color: blue; font-family: Courier;"&gt;HelloWorld()&lt;/span&gt;' in the proxy class takes care of converting the call to a web request using SOAP/XML. After retrieving the result of the web request to the real web service class, this proxy class takes the responsibility of parsing the SOAP/XML response and returning only the result string to the calling applicationn. So the proxy class does all the dirty job for you.&lt;br /&gt;&lt;br /&gt;The proxy class has no implementation of the functionality. It just redirects the call to the web service. So, if you make any changes to the implementation in the web service, still you will get the 'updated result' when you make calls to web service. But, if you change the method name, or change the parameter types in the web service and do not 'refresh the web reference', then your application will compile with the old proxy. But when the proxy redirect the call to the web service, it will find that the parameters or method names do not match and it will fail. So, if there is any change in the method names or parameters, you must refresh your web reference.&lt;br /&gt;&lt;br /&gt;We will explore more features of web services in another chapter. Please complete the following feedback, if this article is incomplete or misleading. Please let us know if there is anyway we can improve this article.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You can download web service samples from&amp;nbsp;&lt;a href="http://www.dotnetspider.com/projects/Alerts.aspx" style="color: #0080ff; text-decoration: none;"&gt;our projects section.&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-4893550146975643533?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/4893550146975643533/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/web-services.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/4893550146975643533'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/4893550146975643533'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/web-services.html' title='Web Services'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-1580921226800403853</id><published>2010-05-03T09:29:00.000-07:00</published><updated>2010-05-07T22:48:29.756-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ado.net tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='.net interview questions and answers'/><category scheme='http://www.blogger.com/atom/ns#' term='c sharp'/><category scheme='http://www.blogger.com/atom/ns#' term='asp.net code free download'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET framework'/><category scheme='http://www.blogger.com/atom/ns#' term='XML'/><category scheme='http://www.blogger.com/atom/ns#' term='.net architecture diagram'/><category scheme='http://www.blogger.com/atom/ns#' term='.Dotnet basics'/><category scheme='http://www.blogger.com/atom/ns#' term='.net interview questions'/><title type='text'>Introduction to XML</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;XML stands for e&lt;u&gt;X&lt;/u&gt;tended&amp;nbsp;&lt;u&gt;M&lt;/u&gt;arkup&amp;nbsp;&lt;u&gt;L&lt;/u&gt;anguage. XML has some similarities to HTML, which is also another Markup Language (HyperText Markup Language).&lt;br /&gt;&lt;br /&gt;An important difference between XML and HTML is, XML is used to define data, while HTML is basically used to display/format text. Main use of HTML is to make web pages. But XML is used in a wide variety of applications now and is becoming a standard for data exchange between different paltforms.&lt;br /&gt;Unlike HTML, XML has no pre-defined set of tags. You can define your own tags to structure and organize your data. Let us see some sample XML :&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;&lt;company&gt;&lt;br /&gt; &lt;employees&gt;&lt;br /&gt;  &lt;employee id="101" name="John"&gt;&lt;/employee&gt;&lt;br /&gt;  &lt;employee id="102" name="Lisa"&gt;&lt;/employee&gt;&lt;br /&gt;  &lt;employee id="103" name="Bill"&gt;&lt;/employee&gt;&lt;br /&gt; &lt;/employees&gt;&lt;br /&gt; &lt;br /&gt; &lt;departments&gt;&lt;br /&gt;  &lt;department name="Sales"&gt;&lt;/department&gt;&lt;br /&gt;  &lt;department name="Software"&gt;&lt;/department&gt;&lt;br /&gt;  &lt;department name="HR"&gt;&lt;/department&gt;&lt;br /&gt; &lt;/departments&gt;&lt;/company&gt;&lt;/pre&gt;&lt;/span&gt;The above piece of XML is quite self explanatory. It is used to represent the data related to a company. One thing to note here is, the tags like &lt;company&gt;, &lt;employees&gt; etc are not predefined. Any XML document can have it's own set of tags. Only thing is, a valid XML document should follow some rules (like each tag should have a matching closing tag. There more such rules...)&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Need for XML&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;XML is a platform neutral standard. Since it is represented in plain text, any platform can understand it. You can use XML to exchange data between Unix and Windows, Mainframes and windows applications and virtually any other platforms. It is a simple, easy to use *language* to exchange/store data.&lt;br /&gt;&lt;br /&gt;In real world, if you have to store data, you have several choices. One of the most common mechanism is databases. Databases are the best choice if you have lot of data to be stored/manipulated. But if you have to send data to another application or platform, databases will not be much helpful. Suppose you have your data stored in an SQL Server database. What if your manager ask you to give the list of Employees in the Sales department ? How will you give the data to him? You cannot give your SQL Server database to him. He may not have a SQL Server software or he may not have the technical expertise to view data from SQL Server. XML is very helpful in such scenarios. You just need to generate an XML from the SQL Server database with the required records and hand over the XML as a print out or email. XML is so simple so that any one can simply read it using any text editor.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #006699;"&gt;There are several XML viewers and editors available, which will help you read XML in the form of a tree view. Internet Explorer is a good XML viewer. Simply copy the above XML and save into a file called 'sample.xml'. Then open the xml file in internet explorer and see how it works!&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can define your own XML tags based on your needs. You can have nested tags too, which help you organize the data any way you want it. See a slightly different version of the above XML:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/employees&gt;&lt;/company&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;&lt;company&gt;&lt;br /&gt; &lt;employees&gt;&lt;br /&gt;  &lt;employee id="101" name="John"&gt;&lt;/employee&gt;&lt;br /&gt;  &lt;employee id="102" name="Lisa"&gt;&lt;/employee&gt;&lt;br /&gt;  &lt;employee id="103" name="Bill"&gt;&lt;/employee&gt;&lt;br /&gt; &lt;/employees&gt;&lt;br /&gt; &lt;br /&gt; &lt;departments&gt;&lt;br /&gt;  &lt;department name="Sales"&gt;&lt;br /&gt;   &lt;manager&gt;&lt;br /&gt;    &lt;name&gt;Fred&lt;/name&gt;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;&lt;address&gt;3000 Briarcliif Way&lt;/address&gt;&lt;email&gt;Fred@spiderkerala.com&lt;/email&gt;&lt;br /&gt;    &lt;phone&gt;&lt;br /&gt;     &lt;residencephone&gt;616 304 1093&lt;/residencephone&gt;&lt;br /&gt;     &lt;officephone&gt;616 304 1093&lt;/officephone&gt;&lt;br /&gt;    &lt;/phone&gt;&lt;br /&gt;      &lt;br /&gt;  &lt;br /&gt;  &lt;br /&gt;  &lt;department name="Software"&gt;&lt;br /&gt;   &lt;manager&gt;&lt;br /&gt;    &lt;name&gt;Joe&lt;/name&gt;&lt;br /&gt;    &lt;/manager&gt;&lt;/department&gt;&lt;br /&gt;&lt;br /&gt;&lt;address&gt;3960 Whispering Way&lt;/address&gt;&lt;email&gt;Joe@spiderkerala.com&lt;/email&gt;&lt;br /&gt;    &lt;phone&gt;&lt;br /&gt;     &lt;residencephone&gt;616 304 1093&lt;/residencephone&gt;&lt;br /&gt;     &lt;officephone&gt;616 304 1093&lt;/officephone&gt;&lt;br /&gt;    &lt;/phone&gt;&lt;br /&gt;      &lt;br /&gt;  &lt;br /&gt; &lt;/manager&gt;&lt;/department&gt;&lt;/departments&gt;&lt;/company&gt;&lt;/pre&gt;&lt;/span&gt;The XML data altogether is called an '&lt;b&gt;XML Document&lt;/b&gt;'. .NET gives several classes to read and manipulate XML Documents. We will explore some of them in upcoming chapters.&lt;br /&gt;&lt;br /&gt;You might have seen our&amp;nbsp;&lt;a href="http://www.dotnetspider.com/tutorials/" style="color: #3399bb; text-decoration: none;"&gt;Tutorial Index&lt;/a&gt;, which lists all chapters. You can click on any chapter title and navigate to the corresponding page. This index is populated from an XML file.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;a href="http://www.dotnetspider.com/tutorials/Tutorials.xml" style="color: #0080ff; text-decoration: none;" target="_blank"&gt;Click here&lt;/a&gt;&amp;nbsp;to view the XML file, from which we load our tutorial chapters.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The reason we load it from an XML file is, our chapters are continuously changing and we add new chapters frequently. All our chapters have a link to&amp;nbsp;&lt;b&gt;Next Chapter&lt;/b&gt;. If we hard-code these links in all chapters, we have to make changes in several places when we change the order of some chapters or when we add new chapters. There is all possibility that we might make some mistakes and some of the chapters may lead to 'wrong next chapter'. In our current implementation, we programmatically read the XML file and display the&amp;nbsp;&lt;b&gt;Tutorial Index&lt;/b&gt;. Also, each page has a piece of code which read the current page URL and find the&amp;nbsp;&lt;b&gt;Next Page Url&lt;/b&gt;&amp;nbsp;from the XML file based on the current page URL. This mechanism helps us add new chapters without making any changes to existing pages. All we have to do is, just insert one line of entry in the XML file and the changes will be automatically reflected in all other relevant pages. Even if we want to re-order some of the chapters, we just need to re-arrange the entries in the XML file.&lt;br /&gt;&lt;br /&gt;We use the following code to load our Chapter Index from the XML file:&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;public string GetChapters( string filePath )&lt;br /&gt;{&lt;br /&gt; // Create an xml document.&lt;br /&gt; XmlDocument doc = new XmlDocument();   &lt;br /&gt;&lt;br /&gt; // Load the XML from the file.&lt;br /&gt; doc.Load(filePath);&lt;br /&gt;&lt;br /&gt; // Retrieve all categories from the xml.&lt;br /&gt; XmlNodeList categories  = doc.SelectNodes("DotNetSpider/tutorials/Category");&lt;br /&gt;&lt;br /&gt; string chapterString = "";&lt;br /&gt; int chapter = 0;&lt;br /&gt;&lt;br /&gt; // Iterate through all the categories&lt;br /&gt; foreach ( XmlNode categoryNode in categories )&lt;br /&gt; {&lt;br /&gt;  // Add category name to the string.&lt;br /&gt;  chapterString += "&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: medium;"&gt;" + categoryNode.Attributes["Name"].Value + "&lt;/span&gt;&lt;br /&gt;";&lt;br /&gt;&lt;br /&gt;  // Get all chapters in the current category.&lt;br /&gt;  XmlNodeList chapters = categoryNode.SelectNodes("Chapter");&lt;br /&gt;&lt;br /&gt;  // Loop through all chapters in the current category and add to the string.&lt;br /&gt;  foreach ( XmlNode chapterNode in chapters )&lt;br /&gt;  {&lt;br /&gt;   ++chapter;&lt;br /&gt;&lt;br /&gt;   chapterString += "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;li&gt;Chapter " + chapter +       " : &lt;a href="http://www.blogger.com/+%20chapterNode.Attributes[%22Url%22].Value%20+"&gt;" +       chapterNode.Attributes["Name"].Value + "&lt;/a&gt;";   }  }   // Return the string, which contains the list of chapters.  return chapterString; }&lt;/li&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;We explored some areas where XML can be used. But XML can be used in a very wide range of ways. We will explore more advanced uses of XML in another chapter.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;XML Specification&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;We gave a very brief introduction to XML in this chapter. This chapter is meant to give a very brief introduction and we haven't covered many important aspects of XML here. We will explain most of them in some other chapters.&lt;br /&gt;&lt;br /&gt;XML has become a standard now and you can read the rules and specification for this standard here :&amp;nbsp;&lt;a href="http://www.w3.org/TR/2004/REC-xml-20040204" style="color: #0080ff; text-decoration: none;"&gt;http://www.w3.org/TR/2004/REC-xml-20040204&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-1580921226800403853?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/1580921226800403853/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/introduction-to-xml.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/1580921226800403853'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/1580921226800403853'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/introduction-to-xml.html' title='Introduction to XML'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-7075386480704884082</id><published>2010-05-03T09:28:00.002-07:00</published><updated>2010-05-07T22:50:06.418-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Custom Exceptions'/><category scheme='http://www.blogger.com/atom/ns#' term='.net basics'/><category scheme='http://www.blogger.com/atom/ns#' term='Exceptions'/><category scheme='http://www.blogger.com/atom/ns#' term='ado.net tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='.net interview questions and answers'/><category scheme='http://www.blogger.com/atom/ns#' term='c sharp'/><category scheme='http://www.blogger.com/atom/ns#' term='asp.net code free download'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET framework'/><category scheme='http://www.blogger.com/atom/ns#' term='.net interview questions'/><title type='text'>Custom Exceptions</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;The Microsoft .NET team has done a good job by providing us a rich set of Exception classes. Most of the time, these exception classes are sufficient enough to handle any common error situation. However, it may be required that our application would need some additional exception classes, that are not available in .NET Framework.&lt;br /&gt;&lt;br /&gt;The .NET Framework exception handling mechanism allows us to create our own custom exception classes and use it in our applications.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Custom Exceptions&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;All exceptions in .NET are derived from the root exception class - System.Exception. There are two other&lt;br /&gt;exception classes immediately derived from the System.Exception :&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.SystemException&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.ApplicationException&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;All exceptions thrown by the .NET Framework is derived from the SystemException class. If we raise any exception from our application, it should be derived from the System.ApplicationException. This will differentiate our exceptions from the system generated exceptions.&lt;br /&gt;&lt;br /&gt;It is easy to create a custom exception class. Just create a new class and mark it as derived from System.ApplicationException&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;public class UserNotExistsException : System.ApplicationException &lt;br /&gt; {&lt;br /&gt; }   &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now we have derived a custom exception class and we can use it in ourr application. See the sample code, showing how we&lt;br /&gt;can throw ourr custom exception.&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;public void UpdateUser( User userObj )&lt;br /&gt; {&lt;br /&gt;  if ( some error condition )&lt;br /&gt;  {&lt;br /&gt;   throw new UserNotExistsException();&lt;br /&gt;  }&lt;br /&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The 'throw' statement allows us to raise an exception programmatically. Here we are creating a new object of type 'UserNotExistsException' and throwing it. Another class or method which calls our method should handle this exception.&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;try&lt;br /&gt; {&lt;br /&gt;  UpdateUser( userObj );&lt;br /&gt; }&lt;br /&gt; catch ( UserNotExistsException ex )&lt;br /&gt; {&lt;br /&gt;  MessageBox.Show ( ex.Message );&lt;br /&gt; }&lt;br /&gt;   &lt;/pre&gt;&lt;br /&gt;In this sample, we are calling the method UpdateUser(...), which might throw an exception of type UserNotExistsException. If this exception is raised, it will go to our catch block and we are showing a message to the user.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Enhancing our custom exception&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the custom exception we defined above, we haven't specified any constructor. But since we derive it from the ApplicationException, it will use the public constructors available in AppicationException. It is a good idea to provide at least one constructor, which takes an error message as a parameter.&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;public class UserNotExistsException : System.ApplicationException &lt;br /&gt; {&lt;br /&gt;  public UserNotExistsException ( string message ) : base ( message )&lt;br /&gt;  {&lt;br /&gt;  }&lt;br /&gt; }   &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now, when we throw this exception, we have to pass an error message to the constructor. The error handlers will be able to retrieve this message from the Exception object and show a better message to the user.&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;public void UpdateUser( User userObj )&lt;br /&gt; {&lt;br /&gt;  if ( some error condition )&lt;br /&gt;  {&lt;br /&gt;   throw new UserNotExistsException( "The user you are trying to update does not exists." );&lt;br /&gt;  }&lt;br /&gt; }&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;See the exception handler code :&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;try&lt;br /&gt; {&lt;br /&gt;  UpdateUser( userObj );&lt;br /&gt; }&lt;br /&gt; catch ( UserNotExistsException ex )&lt;br /&gt; {&lt;br /&gt;  MessageBox.Show ( ex.Message );&lt;br /&gt; }&lt;/pre&gt;&lt;br /&gt;Now the user will see the more friendly error message which we passed as part of the exception, while throwing it.&lt;br /&gt;&lt;br /&gt;You can customize the custom exception classes such a way that it passes any information you want including the date and time the exception occurred, the method name in which the exception was first raised, user name of the current user etc. You may also provide a Save() method for your custom exception class so that when a caller catch our custom exception, he can call the Save() method, which will record the error information to the disk.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-7075386480704884082?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/7075386480704884082/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/custom-exceptions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/7075386480704884082'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/7075386480704884082'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/custom-exceptions.html' title='Custom Exceptions'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-5844759347694980989</id><published>2010-05-03T09:28:00.000-07:00</published><updated>2010-05-07T22:51:47.266-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='catch'/><category scheme='http://www.blogger.com/atom/ns#' term='Exception classes in .NET'/><category scheme='http://www.blogger.com/atom/ns#' term='DivideByZeroException'/><category scheme='http://www.blogger.com/atom/ns#' term='System.Exception'/><category scheme='http://www.blogger.com/atom/ns#' term='try'/><category scheme='http://www.blogger.com/atom/ns#' term='HttpException.System.ArithmeticException'/><title type='text'>Exception classes in .NET</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;NET Framework provides several classes to work with exceptions. When there is an exception, the .NET framework creates an object of type 'Exception' and 'throws' it. This Exception object contains all information about the 'error'.&lt;br /&gt;&lt;br /&gt;If you enclose your code within the try-catch block, you will receive the exception object in the 'catch' block when the exception occurs. You can use this object to retrieve the information regarding the error and take appropriate action.&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;try&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: darkgreen;"&gt;// Code which can cause an exception.&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: darkgreen;"&gt;// Code to handle exception&lt;/span&gt;&lt;br /&gt;MessageBox.Show ( ex.Message );&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;Within the catch block, you can use the Exception object to get more information about the error. The exception object exposes a property called 'Message', which gives a description about the error. This may not be a very friendly message for the end user. But you can use it to log the error and show another friendly message to the user.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;The System.Exception class&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In .NET, all exceptions are derived from the Exception class. The Exception class is defined inside the System namespace.Other derived exception classes are spread across many other namespaces.&lt;br /&gt;&lt;br /&gt;Since all other exceptions are derived from the System.Exception class, if you catch System.Exception, that would cover all exceptions derived from System.Exception also. So, the statement&amp;nbsp;&lt;b&gt;catch (Exception)&lt;/b&gt;&amp;nbsp;would catch all exceptions of type System.Exception and all derived exceptions. In .NET, all exceptions are derived from System.Exception. So,&lt;b&gt;catch (Exception)&lt;/b&gt;&amp;nbsp;will catch all posibble exceptions in your .NET application.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Specify what exception type you want to catch&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;See the catch block in the above sample code.&amp;nbsp;&lt;b&gt;catch ( Exception ex )&lt;/b&gt;&amp;nbsp;- specifies that we want to catch all exceptions of Type&amp;nbsp;&lt;b&gt;Exception&lt;/b&gt;. So, if there is an exception of Type&amp;nbsp;&lt;b&gt;Exception&lt;/b&gt;, it will be caught by the catch block.&lt;br /&gt;&lt;br /&gt;If you specify an exception Type in the catch statement, it will catch all exceptions of the specified type and all types derived from it.&lt;br /&gt;&lt;br /&gt;See the following sample :&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;try&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: darkgreen;"&gt;// Code which can cause an exception.&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;catch(System.Web.HttpException ex)&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: darkgreen;"&gt;// Code to handle exception&lt;/span&gt;&lt;br /&gt;MessageBox.Show ( ex.Message );&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;The above example will only catch the exception of type&amp;nbsp;&lt;b&gt;System.Web.HttpException&lt;/b&gt;&amp;nbsp;and any other exception derived from it. So, if there is any exception of type&lt;b&gt;System.ArithmeticException&lt;/b&gt;, it will not be handled and it may lead to program termination.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Handling specific Exception types&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In my previous article, I mentioned few examples from real life - "When you ride a bike, you may wear a helmet. When you go for boating, you might use a life jacket. A car driver might use seat belts while driving at high speed in a high way. What is the purpose ? To handle exceptions (accidents), right ? We do not know when it might happen, so we are prepared to 'handle' such situations any time. "&lt;br /&gt;&lt;br /&gt;Yes, a helmet helps a bike rider when he meet with an accident. A life jacket may be helpful in water and a seat belt would help a car driver. But what if some one ride a bike with a helpmet, life jacket and a seat belt ? That may not look good, right ?&lt;br /&gt;&lt;br /&gt;Similarly, in Exception handling, you do not need to catch all exceptions. You need to catch only the 'expected' exceptions. Which means,if you are doing an arithmetic calculation, you must handle&amp;nbsp;&lt;b&gt;ArithmeticException&lt;/b&gt;&amp;nbsp;and&amp;nbsp;&lt;b&gt;DivideByZeroException&lt;/b&gt;. When you are accessing the web from your code, you must handle&amp;nbsp;&lt;b&gt;HttpException&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;The bottom line is, depending on the nature of the code, you must handle the appropriate, specific exceptions, instead of catching the father of all exceptions (System.Exception).&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Multiple catch blocks&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can have any number of catch blocks for each try block. For example, if you are doing some operation which involve web access and also some arithmetic operations, you can handle both&amp;nbsp;&lt;b&gt;System.Web.HttpException&lt;/b&gt;&amp;nbsp;and&amp;nbsp;&lt;b&gt;System.ArithmeticException&lt;/b&gt;. See the sample below:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;try&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: darkgreen;"&gt;// Code which can cause a web exception or arithmetic exception.&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;catch(System.Web.HttpException ex)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show ( "A web exception occurred." );&lt;br /&gt;}&lt;br /&gt;catch(System.ArithmeticException ex)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show ( "An arithmetic exception occurred." );&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Program Flow&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When an exception occurs within a try block, the program control will jump to the first catch block and compare if the exception type is same the as the type specified in the catch block. If the type matches, it will execute the catch block. If the types do not match, it will jump to the next catch block and compare. Like this, it will compare against all catch blocks until a match is found. If there is no catch block found which matches the exception type, it will become an unhandled exception and will lead to program termination&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Catch derived exceptions first and base exception last&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A base exception type will match the derived exceptions also. If there is a catch block with the type 'Exception', it will catch all types of exceptions. So, you have multiple catch blocks, you must specify the derived exception types first and the base types last. See the following code:&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;try&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: darkgreen;"&gt;// Code which can cause a web exception or arithmetic exception.&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;catch (System.Exception ex)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show ( "An exception occurred." );&lt;br /&gt;}&lt;br /&gt;catch (System.Web.HttpException ex)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show ( "A web exception occurred." );&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;In the above code, assume there is a web exception occurred. The exception type will be compared against the first catch block. Since the WebException is derived from System.Exception or oneof it's derived classes, the types will match and the first catch block will be executed. So, you might be expecting that the&amp;nbsp;&lt;b&gt;catch (System.Web.HttpException)&lt;/b&gt;block will be executed, but it would never get called because of the&amp;nbsp;&lt;b&gt;catch(System.Exception ex)&lt;/b&gt;&amp;nbsp;before that.&lt;br /&gt;&lt;br /&gt;You must change the above code as shown below :&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;try&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: darkgreen;"&gt;// Code which can cause a web exception or arithmetic exception.&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;catch (System.Web.HttpException ex)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show ( "A web exception occurred." );&lt;br /&gt;}&lt;br /&gt;catch(System.Exception ex)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show ( "An exception occurred." );&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;Now, if there is a web exception, it will go to the&amp;nbsp;&lt;b&gt;catch (System.Web.HttpException ex)&lt;/b&gt;&amp;nbsp;block. All other exceptions will go to&amp;nbsp;&lt;b&gt;catch (System.Exception ex)&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Some commonly used .NET Exception classes&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;System.ArithmeticException - This is the base class for exceptions that occur during arithmetic operations, such as System.DivideByZeroException and System.OverflowException.&lt;br /&gt;&lt;br /&gt;System.ArrayTypeMismatchException - ArrayTypeMismatchException is thrown when a an incompatible object is attpemted to store into an Array.&lt;br /&gt;&lt;br /&gt;System.DivideByZeroException - This exception is thrown when an attempt to divide a number by zero.&lt;br /&gt;&lt;br /&gt;System.IndexOutOfRangeException - IndexOutOfRangeException is thrown when attempted to access an array using an index that is less than zero or outside the bounds of the array.&lt;br /&gt;&lt;br /&gt;System.InvalidCastException - Thrown when an explicit type conversion from a base type or interface to a derived type fails at run time.&lt;br /&gt;&lt;br /&gt;System.NullReferenceException - This exception is thrown when an object is accessed but it is null.&lt;br /&gt;&lt;br /&gt;System.OutOfMemoryException - OutOfMemoryException is thrown if the 'new' operation (creating new object) fails due to in sufficient memory.&lt;br /&gt;&lt;br /&gt;System.OverflowException - OverflowException is thrown when an arithmetic operation overflows.&lt;br /&gt;&lt;br /&gt;System.StackOverflowException - StackOverflowException is thrown when the execution stack is exhausted by having too many pending method calls, most probably due to infinite loop.&lt;br /&gt;&lt;br /&gt;ArgumentException - The exception that is thrown when one of the arguments provided to a method is not valid.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-5844759347694980989?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/5844759347694980989/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/exception-classes-in-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/5844759347694980989'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/5844759347694980989'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/exception-classes-in-net.html' title='Exception classes in .NET'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-4666922761028088472</id><published>2010-05-03T09:27:00.001-07:00</published><updated>2010-05-07T22:52:11.579-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='catch'/><category scheme='http://www.blogger.com/atom/ns#' term='Exception classes in .NET'/><category scheme='http://www.blogger.com/atom/ns#' term='DivideByZeroException'/><category scheme='http://www.blogger.com/atom/ns#' term='System.Exception'/><category scheme='http://www.blogger.com/atom/ns#' term='Exception Handling in .NET'/><category scheme='http://www.blogger.com/atom/ns#' term='try'/><category scheme='http://www.blogger.com/atom/ns#' term='HttpException.System.ArithmeticException'/><title type='text'>Exception Handling in .NET</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;If you write a program, it is for sure that it will have errors and issues. You cannot avoid them. But what you can do is write the code such a way that it is easy to find the errors and issues so that you can solve them easily. You need the real skill to write 'maintainable code'.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;What is maintainable code ?&lt;/span&gt;&lt;br /&gt;If an existing application is given to a new employee in the company and ask him to fix a problem in that,most probably he will come back with the answer : "oh, it is stupid code.. I can't figure out what they have written. Instead of trouble shooting the issues in this code, I can re write the entire application with less time."&lt;br /&gt;&lt;br /&gt;This is a common scenario in the programming world. The above answer shows the code is not a maintainable code. Over a period of time, there will be lot of changes required in existing applications to adapt to the new requirements. Only if you write 'maintainable code', you can enhance your application when new requirements come up and solve issues.&lt;br /&gt;&lt;br /&gt;There is no specific set of rules to make an application 'maintainable'. There are lot of factors involved in it including following coding standards, writing lot of comments within code, writing self explanatory code, separating application into multiple well defined layers, having good exception handling etc.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;What is an 'Exception' ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;'Exception' is an error situation that a program may encounter during runtime. For example, your program may be trying to write into a file, but your hard disk may be full. Or, the program may be trying to update a record in database, but that record may be already deleted. Such errors may happen any time and unless you handle such situation properly, your application may have un predictable behaviour.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;What is the difference between 'Exception' and 'Error' ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Error&lt;/b&gt;&amp;nbsp;is an expected situation in an application. For example, you want to create a file in the folder "C:\Projects\Test\". If you attempt to create a file when this folder doesn't exists, it will make the operating system throw an exception. But you should not leave it to the operating system to throw the exception. This has to be handled through code. You must first check for the existence of the folder before you attempt to write the file. If the folder doesn't exists, you must first create the folder. This is how a stable application should be written.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Exception&lt;/b&gt;&amp;nbsp;is a runtime error that the program may encounter during the execution of the program. For example, hard disk may be full when you attempt to write into a file, network connection may be lost while your application is communicating with another computer etc. There is no clear definition, but typically, Exceptions are unpredictable errors during runtime.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;What is 'Exception Handling'?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When you ride a bike, you may wear a helmet. When you go for boating, you might use a life jacket. A car driver might use seat belts while driving at high speed in a high way. What is the purpose ? To handle exceptions (accidents), right ? We do not know when it might happen, so we are prepared to 'handle' such situations any time.&lt;br /&gt;&lt;br /&gt;An exception can occur anytime during the execution of an application. Your application must be prepared to face such situations. An application will crash if an exception occurs and it is not handled.&lt;br /&gt;&lt;br /&gt;"An exception handler is a piece of code which will be called when an exception occurs."&lt;br /&gt;&lt;br /&gt;.NET Framework provides several classes to work with exceptions. The keywords&amp;nbsp;&lt;b&gt;try, catch&lt;/b&gt;&amp;nbsp;are used to handle exceptions in .NET. You have to put the code (that can cause an exception) in a&amp;nbsp;&lt;b&gt;try&lt;/b&gt;&amp;nbsp;block. If an exception occurs at any line of code inside a try block, the control of execution will be transfered to the code inside the catch block.&lt;br /&gt;&lt;br /&gt;Syntax :&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;try&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: darkgreen;"&gt;// Code which can cause an exception.&lt;/span&gt;&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: darkgreen;"&gt;// Code to handle exception&lt;/span&gt;&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;Just like a bike rider wrap his head in a helmet to protect from accident, the above syntax will protect the code within the try block from accidents (exceptions).&lt;br /&gt;&lt;br /&gt;If any statement within the try block raises an exception, the control of execution will be transfered to the first line within the catch block. You can write the error handling code in the catch block, like recording the error message into a log file, sending an email to the administrator about the problem occurred, showing an appropriate error message to the user etc.&lt;br /&gt;&lt;br /&gt;See the following code :&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;try&lt;br /&gt;{&lt;br /&gt;Statement 1&lt;br /&gt;Statement 2&lt;br /&gt;Statement 3&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;Statement 4&lt;br /&gt;Statement 5&lt;br /&gt;}&lt;br /&gt;            &lt;br /&gt;Statement 6&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In normal flow of program, the statements 1, 2, 3, 6 will be executed. Statements 4 and 5 will be executed only if an exception occurs.&lt;br /&gt;&lt;br /&gt;Assume there is an exception at statement 2. In this scenario, statements 1, 2, 4, 5 and 6 will be executed. Statement 3 will not be executed at all, because an exception occurred at statement 2 and program flow was transferred to the catch block.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;'finally' block&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can optionally use a 'finally' block along with the try-catch. The 'finally' block is guaranteed to be executed even if there is an exception.&lt;br /&gt;&lt;br /&gt;Sample Code :&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;try&lt;br /&gt;{&lt;br /&gt;Statement 1&lt;br /&gt;Statement 2&lt;br /&gt;Statement 3&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;Statement 4&lt;br /&gt;Statement 5&lt;br /&gt;}&lt;br /&gt;finally&lt;br /&gt;{&lt;br /&gt;Statement 6&lt;br /&gt;Statement 7&lt;br /&gt;}&lt;br /&gt;            &lt;br /&gt;Statement 8&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;In normal flow of program, the statements 1, 2, 3, 6, 7 and 8 will be executed. Statements 4 and 5 will be executed only if an exception occurs.&lt;br /&gt;&lt;br /&gt;Assume there is an exception at statement 2. In this scenario, statements 1, 2, 4, 5, 6, 7 and 8 will be executed.&lt;br /&gt;&lt;br /&gt;Note that the statements 6 and 7 are executed in both the cases. The bottom line is, the code within the 'finally' block is executed whether there is an exception or not.&lt;br /&gt;&lt;br /&gt;You can use the finally block to do any code cleanup. For example, you are doing some database operations inside a try block.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;try&lt;br /&gt;{&lt;br /&gt;Statement 1 - Open database&lt;br /&gt;Statement 2 - Execute Query&lt;br /&gt;Statement 3 - Close Database&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;Statement 4 - Show messagebox to user&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;In the above code sample, what will happen if an exception occurs when the statement 2 is executed ? The catch block will be executed and a message box will be shown to the user. But the Statement 3 is never executed in that case, which means the database will not be closed.&lt;br /&gt;&lt;br /&gt;Here is where the finally block will be helpful.&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier; font-size: small;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;try&lt;br /&gt;{&lt;br /&gt;Statement 1 - Open database&lt;br /&gt;Statement 2 - Execute Query&lt;br /&gt;}&lt;br /&gt;catch(Exception ex)&lt;br /&gt;{&lt;br /&gt;Statement 3 - Show messagebox to user&lt;br /&gt;}&lt;br /&gt;finally&lt;br /&gt;{&lt;br /&gt;Statement 4 - Close Database&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;See the improved code. We have moved the code to close the database to the 'finally' block. The statement to close the database will be executed whether there is an exception or not.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Why should we catch exceptions ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Why should you use a helmet when you ride a bike ? To protect your head from crashing when there is an accident, right ? Just like that, exception handling will protect your application from crashing when there is an exceptions.&lt;br /&gt;&lt;br /&gt;If an exception is not 'handled' in code, the application will crash and user will see an ugly message. Instead, you can catch the exception, log the errors and show a friendly message to the user.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-4666922761028088472?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/4666922761028088472/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/exception-handling-in-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/4666922761028088472'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/4666922761028088472'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/exception-handling-in-net.html' title='Exception Handling in .NET'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-2181332568124742697</id><published>2010-05-03T09:26:00.001-07:00</published><updated>2010-05-07T22:54:30.005-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='WriteXml'/><category scheme='http://www.blogger.com/atom/ns#' term='DataTable'/><category scheme='http://www.blogger.com/atom/ns#' term='How to create a DataTable'/><category scheme='http://www.blogger.com/atom/ns#' term='connectionString'/><category scheme='http://www.blogger.com/atom/ns#' term='ado.net tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='DataRow'/><category scheme='http://www.blogger.com/atom/ns#' term='GetXml()'/><category scheme='http://www.blogger.com/atom/ns#' term='DataSet'/><category scheme='http://www.blogger.com/atom/ns#' term='ADO.NET programming'/><title type='text'>DataSet, DataTable, DataRow</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;span class="v11"&gt;DataSet and DataTable are the key components in ADO.NET programming. In simple words, DataSet represents an in memory representation of the database. We can load an entire database into a DataSet and manipulate the data in memory. If you aremore familiar with DataSet, you can Add, Edit and Update data in the dataset and then just call a single method 'AcceptChanges()' whichwill save all the changes back to the database.&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v11"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v11"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v11"&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;A DataSet contains one or more DataTables&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;A DataTable contains DataRows.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;What is DataSet ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A DataSet is an in memory representation of data loaded from any&amp;nbsp;&lt;u&gt;data source&lt;/u&gt;. Even though the most common data sourceis&amp;nbsp;&lt;u&gt;database&lt;/u&gt;, we can use DataSet to load data from other data sources including XML files etc. In this article, we will talk about the role of DataSet in manipulating data from database.&lt;br /&gt;&lt;br /&gt;In .NET, a DataSet is a class provided by the .NET Framework. The DataSet class exposes several proeprties and methods that can be used to retrieve, manipulate and save data from various data sources.&lt;br /&gt;&lt;br /&gt;Just like any other classes in object oriented programming, we have to create an instance of DataSet class to work with data. Typically, we may create a new instance of a DataSet and use other classes provided by .NET Framework to populate the DataSet. See the following example:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Samples\\Employee.mdb";&lt;br /&gt;&lt;br /&gt;OleDbConnection myConnection = new OleDbConnection( connectionString );&lt;br /&gt;&lt;br /&gt;string query = "select * from EMPLOYEE_TABLE";&lt;br /&gt;&lt;br /&gt;OleDbDataAdapter myAdapter = new OleDbDataAdapter( query, myConnection );&lt;br /&gt;&lt;span style="color: orangered;"&gt;&lt;br /&gt;&lt;b&gt;DataSet employeeData = new DataSet();&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;br /&gt;myAdapter.Fill ( &lt;span style="color: orangered;"&gt;employeeData&lt;/span&gt; );&lt;/b&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here we are creating a&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;OleDbConnection&lt;/span&gt;&amp;nbsp;object and we are just passing the object to the&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;OleDbDataAdapter&lt;/span&gt;object. Also, we pass the 'select ...' query to the&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;OleDbDataAdapter&lt;/span&gt;. Next, we call the '.Fill()' method of the&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;OleDbDataAdapter&lt;/span&gt;. This step will populate the dataset ( called 'employeeData' ) with the data retrieved for the sql statement 'select * from EMPLOYEE'.&lt;br /&gt;&lt;br /&gt;As you already know, a DataSet can contain a collection of tables. But in the above case, our sql statement will retrieve data from only one table. So, our&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;DataSet&lt;/span&gt;&amp;nbsp;will have only one table.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Commonly used properties and methods of DataSet&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Property : Tables&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The&amp;nbsp;&lt;b&gt;Tables&lt;/b&gt;&amp;nbsp;propertly allows us to retrieve the tables contained in the DataSet. This property returns a&amp;nbsp;&lt;b&gt;DataTableCollection&lt;/b&gt;&amp;nbsp;object. The following sample code demonstrates iterating through the collection of tables in a data set and print the name of all the tables.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;DataSet employeeData = new DataSet();&lt;br /&gt;myAdapter.Fill( employeeData );&lt;br /&gt;&lt;br /&gt;// Repeat for each table in the DataSet collection.&lt;br /&gt;foreach ( DataTable table in employeeData.Tables )&lt;br /&gt;{&lt;br /&gt;MessageBox.Show ( table.TableName );&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Or, you can use the indexer to access any specific table in the collection.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;DataSet employeeData = new DataSet();&lt;br /&gt;myAdapter.Fill( employeeData );&lt;br /&gt;&lt;br /&gt;// Repeat for each table in the DataSet collection.&lt;br /&gt;for ( int i = 0; i &amp;lt; employeeData.Tables.Count; i++ )&lt;br /&gt;{&lt;br /&gt;DataTable table = employeeData.Tables[i];&lt;br /&gt;MessageBox.Show ( table.TableName );&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Method : GetXml()&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The GetXml() method returns the XML representation of the data from the DataSet.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;DataSet employeeData = new DataSet();&lt;br /&gt;myAdapter.Fill( employeeData );&lt;br /&gt;&lt;br /&gt;string xmlData = employeeData.GetXml();&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Method : WriteXml(...)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The WriteXml() method allows to save XML representation of the data from the DataSet to an XML file. There are many overloaded method available, which takes various parameters. The example shown below takes a file name as parameter and saves the data in DataSet into xml format to the file name specified as parameter. We can optionally save only the data or both data and schema.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;DataSet employeeData = new DataSet();&lt;br /&gt;myAdapter.Fill( employeeData );&lt;br /&gt;&lt;br /&gt;employeeData.WriteXml( "c:\\MyData.xml" );&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Method : ReadXml(...)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;The ReadXml() method allows to load the DataSet from an XML representation of the data. There are many overloaded method available, which takes various parameters. The example shown below takes a file name as parameter and loads the data from XML file into the DataSet. This method can be used to load either the data only or both data and schema from the XML.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;DataSet employeeData = new DataSet();&lt;br /&gt;employeeData.ReadXml( "c:\\MyData.xml" );&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There is another method called 'ReadXmlSchema()', which can be used to load only the schema from a file.&lt;br /&gt;&lt;br /&gt;The methods WriteXml() and ReadXml() are useful to save the data from a database into some temporary files, transport to other places or keep it as a local file and load later. Many applications, including the&amp;nbsp;&lt;a href="http://www.dotnetspider.com/tools/SpiderAlerts.aspx" style="color: #0080ff; text-decoration: none;"&gt;SpiderAlerts tool&lt;/a&gt;&amp;nbsp;available for download from this site, uses DataSet to manipulate data and saves/retrieves them from local disk using the WriteXml() and ReadXml() methods.&lt;br /&gt;&lt;br /&gt;The&amp;nbsp;&lt;a href="http://www.dotnetspider.com/tools/SpiderAlerts.aspx" style="color: #0080ff; text-decoration: none;"&gt;SpiderAlerts&lt;/a&gt;&amp;nbsp;tool communicates with webservices in our site and retrieves the alerts in the form of a DataSet. Once the Alerts are retrieved, it is saved into local computer using the WriteXml method. (This implementation may be changed soon in the future versions of this tool. We are considering saving(serializing) the DataSet into Isolated Storage (IsolatedStorage is a new feature part of the .NET Framework - it is a kind of hidden file system)&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;span class="Apple-style-span" style="line-height: 20px;"&gt;&lt;span class="v11"&gt;A DataTable is a class in .NET Framework and in simple words a DataTable object represents a table from a database.&lt;br /&gt;&lt;br /&gt;DataSet and DataTable are the key components in ADO.NET programming. While DataSet can be used to represent a database as a whole, a DataTable object can be used to represent a table in the Database/DataSet. A DataSet can contain several DataTables.&lt;br /&gt;&lt;br /&gt;In typical database oriented applications, DataSet and DataTable are used a lot to manipulate data. DataAdapter  or other classes can be used to populate a DataSet. Once a DataSet is populated, we can access the DataTables contained within the DataSet.&lt;br /&gt;&lt;br /&gt;Just like any database table contains multiple rows (records), a DataTable can contain multiple DataRows. Each row contains multiple fields representing each column in the table.&lt;br /&gt;&lt;br /&gt;The typical process to retrieve records from a database in ADO.NET includes the following steps:&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="v11"&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Open a connection to database&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Use a data adapter to fill a DataSet.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Access the DataTable contained in the DataSet&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;span class="v11"&gt;Access the DataRows contained in the DataTable.&lt;br /&gt;&lt;br /&gt;The following sample code explains these steps. This sample code retrieves data from an MS Access database.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Samples\\Employee.mdb";&lt;br /&gt;OleDbConnection myConnection = new OleDbConnection( connectionString );&lt;br /&gt;&lt;br /&gt;string query = "select * from EMPLOYEE_TABLE";&lt;br /&gt;&lt;br /&gt;OleDbDataAdapter myAdapter = new OleDbDataAdapter( query, myConnection );&lt;br /&gt;DataSet employeeData = new DataSet();&lt;br /&gt;myAdapter.Fill( employeeData );&lt;br /&gt;&lt;br /&gt;// Repeat for each table in the DataSet collection.&lt;br /&gt;foreach ( DataTable table in employeeData.Tables )&lt;br /&gt;{&lt;br /&gt; // Repeat for each row in the table.&lt;br /&gt; foreach ( DataRow row in table.Rows )&lt;br /&gt; {&lt;br /&gt;  MessageBox.Show( "Employee Number : " + row["EmployeeNumber"].ToString() );&lt;br /&gt;MessageBox.Show( "Name : " + row["Name"].ToString() );&lt;br /&gt;MessageBox.Show( "Address : " + row["Address"].ToString() );&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="v11"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;How to create a DataTable&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In most of the cases, we just access the DataTable in a DataSet. We do not need to create a new instance of the DataTable. When a DataSet is populated from database, the DataTable is created with proper schema and data.&lt;br /&gt;&lt;br /&gt;If we explicitely create DataTable, we have to create the proper schema. It is bit confusing if you are not very familiar  with the database structure and schema.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-2181332568124742697?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/2181332568124742697/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/dataset-datatable-datarow.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/2181332568124742697'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/2181332568124742697'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/dataset-datatable-datarow.html' title='DataSet, DataTable, DataRow'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-4513368736019578566</id><published>2010-05-03T09:25:00.003-07:00</published><updated>2010-05-07T22:56:01.094-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='myAdapter.Fill'/><category scheme='http://www.blogger.com/atom/ns#' term='connectionString'/><category scheme='http://www.blogger.com/atom/ns#' term='Create'/><category scheme='http://www.blogger.com/atom/ns#' term='Delete'/><category scheme='http://www.blogger.com/atom/ns#' term='Update'/><category scheme='http://www.blogger.com/atom/ns#' term='Read'/><category scheme='http://www.blogger.com/atom/ns#' term='Connection.Open()'/><category scheme='http://www.blogger.com/atom/ns#' term='ADO.NET sampleExecuteNonQuery()'/><title type='text'>Create, Read, Update, Delete - ADO.NET sample</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;span class="v11"&gt;This chapter demonstrates the basic database operations using the ADO.NET classes. The sample code in this chapter uses the OleDb Provider.&lt;br /&gt;&lt;br /&gt;Here is some sample code to execute a simple query.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v11"&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v11"&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Samples\\Employee.mdb";&lt;br /&gt;&lt;br /&gt;OleDbConnection myConnection = new OleDbConnection( connectionString );&lt;br /&gt;myConnection.Open();&lt;br /&gt;&lt;br /&gt;string query = "insert into EMPLOYEE_TABLE (EmployeeID, Name, Address) VALUES (101, 'John', '3960 CliffValley Way')";&lt;br /&gt;&lt;br /&gt;OleDbCommand myCommand = new OleDbCommand();&lt;br /&gt;myCommand.CommandText = query;&lt;br /&gt;myCommand.Connection = myConnection;&lt;br /&gt;myCommand.ExecuteNonQuery();&lt;br /&gt;&lt;br /&gt;myConnection.Close();&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Let us analyze the code. First we have declared a connection string. The connection string points to an MS Access database. Before you execute this code, make sure you have the database in the path specified. Or, change the path accordingly.&lt;br /&gt;&lt;br /&gt;In the next step, we are creating a&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;OleDbConnection&lt;/span&gt;object and passing the connection string to this object. The line 'myConnection.Open();' will open a connection to the MS Access database specified in the connection string. If the database doesn't exists or if it is not able to open a connection for some other reason, the '.Open' call will fail.&lt;br /&gt;&lt;br /&gt;Next step is, creating a&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;OleDbCommand&lt;/span&gt;&amp;nbsp;object. This command object is used to execute sql statements and uses the connection opened by the&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;OleDbConnection&lt;/span&gt;&amp;nbsp;object.&lt;br /&gt;&lt;br /&gt;Note that before executing a command, we have to establish a valid connection to the database.&lt;br /&gt;&lt;br /&gt;And finally, after we have executed with the command, we will close the connection.&lt;br /&gt;&lt;br /&gt;The above sample code executes a sql statement and returns no data from database. We are calling the method 'ExecuteNonQuery()' on the command object. If we have a 'select ...' statement which returns data from database, we cannot use the 'ExecuteNonQuery()' method.&lt;br /&gt;&lt;br /&gt;The following sample demonstrates using&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;OleDbDataAdapter&lt;/span&gt;Object and&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;DataSet&lt;/span&gt;&amp;nbsp;to retrieve data from databbase.&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: Courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Samples\\Employee.mdb";&lt;br /&gt;&lt;br /&gt;OleDbConnection myConnection = new OleDbConnection( connectionString );&lt;br /&gt;&lt;br /&gt;string query = "select * from EMPLOYEE_TABLE";&lt;br /&gt;&lt;br /&gt;OleDbDataAdapter myAdapter = new OleDbDataAdapter( query, myConnection );&lt;br /&gt;DataSet employeeData = new DataSet();&lt;br /&gt;myAdapter.Fill ( employeeData );&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here we are creating a&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;OleDbConnection&lt;/span&gt;&amp;nbsp;object and we are just passing the object to the&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;OleDbDataAdapter&lt;/span&gt;object. Also, we pass the 'select ...' query to the&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;OleDbDataAdapter&lt;/span&gt;. Next, we call the '.Fill()' method of the&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;OleDbDataAdapter&lt;/span&gt;. This step will populate the dataset ( called 'employeeData' ) with the data retrieved for the sql statement 'select * from EMPLOYEE'.&lt;br /&gt;&lt;br /&gt;As you already know, a DataSet can contain a collection of tables. But in our case, our sql statement will retrieve data from only one table. So, our&amp;nbsp;&lt;span style="color: blue; font-family: Courier;"&gt;DataSet&lt;/span&gt;&amp;nbsp;will have only one table.&lt;br /&gt;&lt;br /&gt;We can iterate through the table in the dataset and retrieve all the records. See the following code demonstrating this:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Samples\\Employee.mdb";&lt;br /&gt;OleDbConnection myConnection = new OleDbConnection( connectionString );&lt;br /&gt;&lt;br /&gt;string query = "select * from EMPLOYEE_TABLE";&lt;br /&gt;&lt;br /&gt;OleDbDataAdapter myAdapter = new OleDbDataAdapter( query, myConnection );&lt;br /&gt;DataSet employeeData = new DataSet();&lt;br /&gt;myAdapter.Fill( employeeData );&lt;br /&gt;&lt;br /&gt;// Repeat for each table in the DataSet collection.&lt;br /&gt;foreach ( DataTable table in employeeData.Tables )&lt;br /&gt;{&lt;br /&gt;// Repeat for each row in the table.&lt;br /&gt;foreach ( DataRow row in table.Rows )&lt;br /&gt;{&lt;br /&gt;MessageBox.Show( "Employee Number : " + row["EmployeeNumber"].ToString() );&lt;br /&gt;MessageBox.Show( "Name : " + row["Name"].ToString() );&lt;br /&gt;MessageBox.Show( "Address : " + row["Address"].ToString() );&lt;br /&gt;}&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="v11"&gt;&lt;br /&gt;&lt;br /&gt;The above code retrieves all the records from the employee table and displays all the fields. You can download a sample project demonstrating the basic database operations.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-4513368736019578566?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/4513368736019578566/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/create-read-update-delete-adonet-sample.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/4513368736019578566'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/4513368736019578566'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/create-read-update-delete-adonet-sample.html' title='Create, Read, Update, Delete - ADO.NET sample'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-8660160952894995304</id><published>2010-05-03T09:25:00.001-07:00</published><updated>2010-05-07T22:58:21.521-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MS Access'/><category scheme='http://www.blogger.com/atom/ns#' term='DataReader'/><category scheme='http://www.blogger.com/atom/ns#' term='Database Concepts'/><category scheme='http://www.blogger.com/atom/ns#' term='ado.net tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='DataRow'/><category scheme='http://www.blogger.com/atom/ns#' term='Database'/><category scheme='http://www.blogger.com/atom/ns#' term='DataAdapter'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle'/><category scheme='http://www.blogger.com/atom/ns#' term='Accessing database using ADO.NET in C# or VB.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='ADO.NET programming'/><category scheme='http://www.blogger.com/atom/ns#' term='sqlserver'/><title type='text'>Accessing database using ADO.NET in C# or VB.NET</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;This tutorial will teach you Database concepts and ADO.NET in a very simple and easy-to-understand manner with many code snippets and samples. This is primarily meant for beginners and if you are looking for any advanced ADO.NET topics, this may not be the right page for you.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;h2 style="color: #3366aa; font-family: Helvetica, Arial, 'Times New Roman'; font-size: 18px; margin-bottom: 2px; margin-left: 1px; margin-right: 2px; margin-top: 2px;"&gt;Database Concepts&lt;/h2&gt;&lt;br /&gt;Database is the media to store data. If you have an application that has to store and retrieve data, your application must be using a database.&lt;br /&gt;&lt;br /&gt;A File is the simplest form of saving the data in the disk, but is not the most efficient way of managing application data. A database is basically a collection of one or more files, but in a custom format, and data is organized in a specific format such a way that it can be retrieved and stored very efficiently.&lt;br /&gt;&lt;br /&gt;Some examples for databases are :&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;MS Access&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;SQL Server&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Oracle&lt;br /&gt;&lt;br /&gt;MS Access is a very light weight database provided by Microsoft for applications with less number of users and relatively small quantity of data. MS Access saves data into database files with the extension .mdb. Usually, MS Access comes along with MS Office package. If you already have the .mdb database file, you can freely use it with your application and you do not need MS Access software. The MS Access software is required only if you want to directly open the database and manipulate the data or change the database schema.&lt;br /&gt;&lt;br /&gt;SQL Server (Microsoft product) and Oracle (Oracle Corp.) are more complex, advanced, relational databases and they are much more expensive. It can support large number of users and very high quantity of data. If you are developing a software, which might be accessed simulatenously by 100s of users or if you expect your data may grow 100s of MBs, you might consider one of these. (We are learning Microsoft .NET.. so you might want to consider the SQL Server than Oracle, for which Microsoft provides special data access components!!)&lt;br /&gt;&lt;br /&gt;&lt;i&gt;In this tutorial, we will be using only MS Access for simplicity. Most of the samples provided in this site uses MS Access database for simplicity and easy download.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2 style="color: #3366aa; font-family: Helvetica, Arial, 'Times New Roman'; font-size: 18px; margin-bottom: 2px; margin-left: 1px; margin-right: 2px; margin-top: 2px;"&gt;ADO.NET&lt;/h2&gt;&lt;br /&gt;ADO.NET is the data access model that comes with the .NET Framework. ADO.NET provides the classes required to communicate with any database source (including Oracle, Sybase, Microsoft Access, Xml, and even text files).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2 style="color: #3366aa; font-family: Helvetica, Arial, 'Times New Roman'; font-size: 18px; margin-bottom: 2px; margin-left: 1px; margin-right: 2px; margin-top: 2px;"&gt;DataAccess Providers in .NET&lt;/h2&gt;&lt;br /&gt;ADO.NET comes with few providers, including:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;OleDb&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;SqlClient&lt;br /&gt;&lt;br /&gt;&lt;i&gt;There are other providers available, but we are not including them here as this tutorial is meant for beginners! When you want them, search for&amp;nbsp;&lt;a href="http://www.google.com/search?sourceid=navclient&amp;amp;ie=UTF-8&amp;amp;oe=UTF-8&amp;amp;q=ado%2Enet+providerstarget=%22_blank%22" style="color: #0080ff; text-decoration: none;"&gt;&lt;u&gt;ADO.NET providers&lt;/u&gt;&lt;/a&gt;&amp;nbsp;in Google or MSDN&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Microsoft made the SQL Server. So they gave a separate provider, specifically made for SQL Server. We can use the OleDb provider for all other database sources including MS Access, Oracle, Sybase etc. There is a separate provider available for Oracle.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;A DATA PROVIDER is a set of classes that can be used to access, retrieve and manipulate data from the databases.&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Both OleDb and SqlClient has its own set of classes, but they have the same concepts. We would like to classify the classes into two broad categories&amp;nbsp;&lt;i&gt;(this is not a microsoft classification, anyway!)&lt;/i&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Classes for communicate with database&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Classes for holding/manipulating data&lt;br /&gt;&lt;br /&gt;The job of first category of classes is to&amp;nbsp;&lt;i&gt;communicate with database and send or retrieve data from the database&lt;/i&gt;. The second category of the classes will be used as a&amp;nbsp;&lt;i&gt;carrier of data&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2 style="color: #3366aa; font-family: Helvetica, Arial, 'Times New Roman'; font-size: 18px; margin-bottom: 2px; margin-left: 1px; margin-right: 2px; margin-top: 2px;"&gt;Classes for communicating with database&lt;/h2&gt;&lt;br /&gt;The&amp;nbsp;&lt;b&gt;Connection&lt;/b&gt;,&amp;nbsp;&lt;b&gt;Command&lt;/b&gt;,&amp;nbsp;&lt;b&gt;DataReader&lt;/b&gt;, and&amp;nbsp;&lt;b&gt;DataAdapter&lt;/b&gt;&lt;br /&gt;objects are the core elements of the ADO.NET provider model.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;table bgcolor="silver" border="1"&gt;&lt;tbody&gt;&lt;tr valign="top"&gt;&lt;th&gt;Object&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;&lt;th&gt;SqlClient Objects&lt;/th&gt;&lt;th&gt;OleDb Objects&lt;/th&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td&gt;&lt;b&gt;Connection&lt;/b&gt;&lt;/td&gt;&lt;td&gt;Establishes a connection to a specific data source.&lt;/td&gt;&lt;td&gt;SqlConnection&lt;/td&gt;&lt;td&gt;OleDbConnection&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td&gt;&lt;b&gt;Command&lt;/b&gt;&lt;/td&gt;&lt;td&gt;Executes a command against a data source.&lt;/td&gt;&lt;td&gt;SqlCommand&lt;/td&gt;&lt;td&gt;OleDbCommand&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td&gt;&lt;b&gt;DataReader&lt;/b&gt;&lt;/td&gt;&lt;td&gt;Reads a forward-only, read-only stream of data from a data source.&lt;/td&gt;&lt;td&gt;SqlDataReader&lt;/td&gt;&lt;td&gt;OleDbDataReader&lt;/td&gt;&lt;/tr&gt;&lt;tr valign="top"&gt;&lt;td&gt;&lt;b&gt;DataAdapter&lt;/b&gt;&lt;/td&gt;&lt;td&gt;Populates a&amp;nbsp;&lt;b&gt;DataSet&lt;/b&gt;&amp;nbsp;and resolves updates with the data source.&lt;/td&gt;&lt;td&gt;SqlDataAdapter&lt;/td&gt;&lt;td&gt;OleDbDataAdapter&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;Each provider may have classes equivalent to above objects. The name of the classes vary slightly to represent the provider type appropriately.&lt;br /&gt;&lt;br /&gt;Depending on the type of database you work on, you will have to choose either OleDb or SqlClient (or, some other provider) objects. Since all our samples use MS Access database, we will be using OleDb objects in all the samples. If you like to use SqlServer, you just need to replace the OleDb objects with the equivalent SqlClient objects.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h2 style="color: #3366aa; font-family: Helvetica, Arial, 'Times New Roman'; font-size: 18px; margin-bottom: 2px; margin-left: 1px; margin-right: 2px; margin-top: 2px;"&gt;Classes for holding data&lt;/h2&gt;&lt;br /&gt;&lt;br /&gt;The following are the main classes used to hold data in Ado.NET:&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;b&gt;DataSet&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;b&gt;DataTable&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;b&gt;DataRow&lt;/b&gt;&lt;br /&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;A DataSet is an in-memory representation of the database.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;DataSet contains DataTables (and more...)&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;DataTable represents a database table&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;DataTable contains DataRows (and more...)&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;A DataRow represents a record in a database table.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;DataRow is a collection of all fields in a record.&lt;br /&gt;&lt;br /&gt;We can use the DataAdapter or DataReader to populate data in DataSet. Once we populate data from database, we can loop through all Tables in the DataSet and through each record in each Table.&lt;br /&gt;&lt;br /&gt;On the first look, this may look bit confusing, but once you understand the concept and get familiar with the Ado.NET classes, you will appreciate the power and flexibility of Ado.NET.&lt;br /&gt;&lt;br /&gt;Soon, we will publish several ADO.NET samples here. Please check back soon.&amp;nbsp;&lt;/li&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-8660160952894995304?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/8660160952894995304/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/accessing-database-using-adonet-in-c-or.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/8660160952894995304'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/8660160952894995304'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/accessing-database-using-adonet-in-c-or.html' title='Accessing database using ADO.NET in C# or VB.NET'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-133299101141853311</id><published>2010-05-03T09:24:00.001-07:00</published><updated>2010-05-07T23:00:49.604-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='VS.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='Debugging in VS.NET'/><title type='text'>Debugging in VS.NET</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;If you make a syntax error, then the compiler will tell you and you can easily solve the issue. But what if there is a logical error? You may never know what went wrong, just by looking into the code. During runtime, the application may give wrong results, which may not be noticed immediately by anyone. When someone report that your "calculator program" gives the result 10 when adding 5 and 4, what will you do? A logical error in a small calculator program may be an easy to fix issue, but what if it is a very complex accounting software?&lt;br /&gt;&lt;br /&gt;The&amp;nbsp;&lt;span class="v12b"&gt;Debugger&lt;/span&gt;&amp;nbsp;becomes a very handy tool in such situations. A Debugger is a&amp;nbsp;&lt;i&gt;software process&lt;/i&gt;&amp;nbsp;that help you monitor the execution of your code. Microsoft gives us a very powerful debugger, integrated with the VS.NET. When you execute your code in&amp;nbsp;&lt;i&gt;debug mode&lt;/i&gt;, you can watch how it executes each line of code. You can run (debug) the application step by step, line by line and see the value of each variable at any point of time. You can visually count how many times a&amp;nbsp;&lt;span style="color: blue; font-family: courier;"&gt;while&lt;/span&gt;loop executes and see whether it executes the&amp;nbsp;&lt;span style="color: blue; font-family: courier;"&gt;if&lt;/span&gt;block or&amp;nbsp;&lt;span style="color: blue; font-family: courier;"&gt;else&lt;/span&gt;&amp;nbsp;block.&lt;br /&gt;&lt;br /&gt;So, in short, debugger help you watch how your code is executed. You can see how your calculator program calculates 5 + 4 = 10 and easily figure out the logical error.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Debugging your project&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Running your project in&amp;nbsp;&lt;span class="v12b"&gt;Debug mode&lt;/span&gt;&amp;nbsp;doesn't need lot of work. Just choose the menu :&amp;nbsp;&lt;span class="v12b"&gt;Debug &amp;gt; Start&lt;/span&gt;&amp;nbsp;or press&amp;nbsp;&lt;span class="v12b"&gt;F5&lt;/span&gt;. Now your application will run in debug mode. To run your application in non-debug mode, choose the menu :&amp;nbsp;&lt;span class="v12b"&gt;Debug &amp;gt; Start without Debugging&lt;/span&gt;&amp;nbsp;or press&amp;nbsp;&lt;span class="v12b"&gt;Ctrl F5&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;You may not feel any difference whether you run in debug mode or non-debug mode. In both the cases, your application runs as usual! To find the difference, you can use&amp;nbsp;&lt;span class="v12b"&gt;breakpoints&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;.&lt;span class="v12b"&gt;BreakPoints&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;BreakPoints are used to stop the execution at certain lines of code in the application and monitor the values of various variables etc at that point of time. To put breakpoints, click on any line of code and press&amp;nbsp;&lt;span class="v12b"&gt;F9&lt;/span&gt;or click on the leftbar of any line of code. When a breakpoint is enabled, the line will be highlighted with BROWN color and a BROWN circle will appear on the left bar (See image below). To remove a breakpoint, press F9 again.&lt;br /&gt;&lt;br /&gt;Open your project and mark breakpoints in different lines of code. Now start the debugger by pressing F5. Note that every time the execution passes through the lines marked as 'breakpoint', execution stops there. You can press F5 to continue the execution again. Or, press F10 to continue the execution line by line! When the execution stops on a breakpoint, or when you continue execution line by line by pressing F10, you can point your mouse over any variable and it will show you the value of that variable at that point of time. You can see how the values are changed at each line of code and this helps you easily figure out the logical errors. This process is called 'Debugging'. Next time, when you hear someone complaining about his 'debugging nightmares', you know what it is!&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Change path of execution&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When the execution reaches a breakpoint, you can see a little YELLOW Arrow on the leftbar of the current line of code and the line will be highlighted with YELLOW color (See image below). When you press the F10, the execution will proceed to the next line of code.&lt;br /&gt;&lt;br /&gt;You can change this execution path by clicking on the yellow arrow on the leftbar and dragging it into any other line of code. For example, if you are currently inside an&amp;nbsp;&lt;span style="color: blue; font-family: courier;"&gt;if&lt;/span&gt;&amp;nbsp;block, you can drag the execution to the&amp;nbsp;&lt;span style="color: blue; font-family: courier;"&gt;else&lt;/span&gt;&amp;nbsp;block (or, to some other line of code), thus changing the application behaviour the way you want! Don't you agree that the Debugger is a very powerful tool?&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Quick Watch&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;While debugging, you can view the value of any variable instantly by pointing the mouse over the variable (See image below. You can see a very small light yellow window showing&amp;nbsp;&lt;i&gt;name = "Little John"&lt;/i&gt;. This is displayed when the mouse is pointed over the variable&amp;nbsp;&lt;i&gt;name&lt;/i&gt;). But this will work only for simple types like int, string etc. In case of types like DataTable, DataSet, ArrayList etc, you can right click on the object name and choose&amp;nbsp;&lt;span class="v12b"&gt;Quick Watch&lt;/span&gt;. A small window will open and will show you the complete object. You can expand the properties of the object and view the values of each proeprty. In case of a DataSet, you can Quick Watch the dataset and expand each table inside the dataset, each row in each table, each column in each row etc. Thus the Quick Watch will help you view the values of the 'complete object'.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Watch Window&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When you debug the application and step through each line, it is not really necessary to point the mouse on each variable to view the value. Just add the variable to the 'Watch Window' and the values are always visible in the little 'Watch Window' in the bottom of your VS.NET (see image below. The variable&amp;nbsp;&lt;i&gt;name&lt;/i&gt;is added to the watch window). To add any variable to Watch Window, righ click on the variable and choose 'Add Watch'. You can choose the same option from the 'Quick Watch' window also.&lt;br /&gt;&lt;br /&gt;The 'Watch Window' may be minimized by default. You can point your mouse on the 'Watch' icon in the bottom of the VS.NET to expand this window. Use the 'push button' in the watch window to keep it always expanded.If 'Watch Window' is not visible in the bottom, select the menu option from VS.NET main menu :&amp;nbsp;&lt;span class="v12b"&gt;Debug &amp;gt; Windows &amp;gt; Watch &amp;gt; Watch 1&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;System.Diagnostics.Debug.WriteLine&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You may use&amp;nbsp;&lt;span style="color: blue; font-family: courier;"&gt;System.Diagnostics.Debug.WriteLine&lt;/span&gt;to print any values into the output window while debugging.Ex:&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;System.Diagnostics.Debug.WriteLine( "*** My name is : " + name );System.Diagnostics.Debug.WriteLine( "+++ See the Output window now." );System.Diagnostics.Debug.WriteLine( "=== End." );&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;br /&gt;See the image below to see how it appears in the output window.&lt;br /&gt;&lt;img src="http://www.dotnetspider.com/Images/WinForms/debug.gif" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Advanced features&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The debugger comes with several other advanced features like conditional breakpoints, CallStack etc. You may find more information from MSDN or other web sites. To keep it simple and helpful for beginners, we have mentioned only the commonly used features of VS.NET debugger.&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-133299101141853311?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/133299101141853311/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/debugging-in-vsnet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/133299101141853311'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/133299101141853311'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/debugging-in-vsnet.html' title='Debugging in VS.NET'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-746286108675174205</id><published>2010-05-03T09:23:00.003-07:00</published><updated>2010-05-07T23:02:15.629-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='web.config'/><category scheme='http://www.blogger.com/atom/ns#' term='ConfigurationSettings.'/><category scheme='http://www.blogger.com/atom/ns#' term='web/IIS configuration'/><category scheme='http://www.blogger.com/atom/ns#' term='using System.Configuration'/><category scheme='http://www.blogger.com/atom/ns#' term='Application Configuration Files'/><category scheme='http://www.blogger.com/atom/ns#' term='Configuration Files'/><title type='text'>Application Configuration Files</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18px;"&gt;NET gives an easy way to store configuration information in a ApplicationConfiguration File. In the simple implementation, you can store information as Key-Value pairs.&lt;br /&gt;&lt;br /&gt;For example, consider a case where you have to use a DataSource in your application. If you hardcore the DataSource information in your code, you will have a bad time when you have to change this datasource. You have to change your source code and re-compile it. This won't work everytime you give your product to different customers or when you run your application in different machines!&lt;br /&gt;&lt;br /&gt;In earlier days, programmers used to store this information in special files called ".ini" files or in system registry. The application can read the information from the .ini file or registry and no need to re-compile the code when the values are changed in .ini file or registry.&lt;br /&gt;&lt;br /&gt;But this is a pain most of the time. It is not fun opening the registry, locate your entries and make appropriate changes. It is quite possible that you may mess up with some important entries in the registry and make your system not running any more. In fact, in secured systems, administrator may deny access to the registry and users will not have the choice to edit the registry at all.&lt;br /&gt;&lt;br /&gt;.NET gives you a simple and easy solution for this problem - the&amp;nbsp;&lt;i&gt;ApplicationConfiguration File&lt;/i&gt;. Each application can have a configuration file, which is actually an XML file. You can use any text editor (including notepad) to open the configuration file and change the values. The application will load the values from this configuration file and you do not have to change your source code everytime you change your DataSource or any other information stored in configuration file.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;&lt;u&gt;app.config&lt;/u&gt;&amp;nbsp;for Windows applications&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Windows applications in VS.NET uses the name 'app.config' by default for the configuration file. This will not be automatically created when you create a Windows application. If you need a configuration file for your application, open your project in VS.NET, go to the 'Solution Explorer' and right click on the project name. Choose&amp;nbsp;&lt;span class="v12b"&gt;Add &amp;gt; Add new item&amp;nbsp;&lt;/span&gt;from the menu and select 'Application Configuration file' from the list of choices. This will create an app.config file for you in the application root.&lt;br /&gt;&lt;br /&gt;By default, the app.config file will have the following content:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;configuration&gt; &lt;br /&gt;&lt;/configuration&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;To store values in configuration file, you can create xml elements in the&lt;br /&gt;format&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;add key="MyKey" value="MyValue"&gt;&lt;/add&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;See the sample config entries below:&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;configuration&gt;&lt;br /&gt;&lt;br /&gt;&lt;appsettings&gt;&lt;br /&gt;&lt;br /&gt;&lt;add key="DatabasePath" value="c:\\projects\data\spider.mdb"&gt;&lt;br /&gt;&lt;br /&gt;&lt;add key="SupportEmail" value="webmaster-6@dotnetspider.com"&gt;&lt;br /&gt;&lt;/add&gt;&lt;/add&gt;&lt;/appsettings&gt;&lt;br /&gt;&lt;/configuration&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And to read from this config file, just use the following code in your application:&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;&lt;span style="color: blue; font-family: courier;"&gt;string dbPath = System.Configuration.ConfigurationSettings.AppSettings["DatabasePath"];&lt;br /&gt;string email = System.Configuration.ConfigurationSettings.AppSettings["SupportEmail"];&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier; font-size: small;"&gt;ConfigurationSettings&lt;/span&gt;&amp;nbsp;is the class&lt;br /&gt;used to access the contents of the configuration file. Since this class is part&lt;br /&gt;of the namespace&amp;nbsp;&lt;span style="color: blue; font-family: courier; font-size: small;"&gt;System.Configuration&lt;/span&gt;,&lt;br /&gt;we have to use the fully qualified name&amp;nbsp;&lt;span style="color: blue; font-family: courier; font-size: small;"&gt;System.Configuration.ConfigurationSettings&lt;/span&gt;.&lt;br /&gt;As a shortcut, you can use the&amp;nbsp;&lt;span style="color: blue; font-family: courier; font-size: small;"&gt;using&lt;/span&gt;&amp;nbsp;directive&lt;br /&gt;on top of the file like below:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier; font-size: small;"&gt;using System.Configuration;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you have the above directive on top of the file, then you can directly use&lt;br /&gt;the class&amp;nbsp;&lt;span style="color: blue; font-family: courier; font-size: small;"&gt;ConfigurationSettings&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier; font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier; font-size: small;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;string dbPath = ConfigurationSettings.AppSettings["DatabasePath"];&lt;br /&gt;string email = ConfigurationSettings.AppSettings["SupportEmail"];&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;table bgcolor="green" cellpadding="0" cellspacing="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;table bgcolor="white" cellpadding="0" cellspacing="5"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;In&amp;nbsp;&lt;span style="color: green;"&gt;&lt;span class="v12b"&gt;VB.NET&lt;/span&gt;&lt;/span&gt;, you have to use "( ... )" instead of the "[ ... ]", as shown below:&lt;br /&gt;&lt;span style="color: blue; font-family: courier; font-size: small;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier; font-size: small;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;Dim dbPath as String = ConfigurationSettings.AppSettings("DatabasePath")&lt;br /&gt;Dim email as String = ConfigurationSettings.AppSettings("SupportEmail")&lt;/pre&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: courier; font-size: small;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="v12"&gt;&lt;span style="color: brown;"&gt;Note:&lt;br /&gt;&lt;br /&gt;When you compile your application, VS.NET will automatically create a file called &lt;your application="" name=""&gt;.exe.config in your bin\debug folder. The contents of the app.config will be automatically copied to this new config file when you compile the application. When you deliver the application to the end user, you have to deliver the exe and this new config file called &lt;your application="" name=""&gt;.exe.config and NOT the&amp;nbsp;&lt;i&gt;app.config&lt;/i&gt;. Users can modify the data in &lt;your application="" name=""&gt;.exe.config file and application will read the data from the config file, when restarted.&amp;nbsp;&lt;/your&gt;&lt;/your&gt;&lt;/your&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;&lt;u&gt;web.config&lt;/u&gt;&amp;nbsp;for web applications&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The web applications use the same concept, but they use a config file with the name 'web.config'. There are couple of things to note in this case.&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;web.config is created automatically by VS.NET when you create any web project.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;When you compile the web application, web.config is NOT renamed or copied to the BIN folder.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;web.config has several default entries in it to support web/IIS configuration &amp;amp; security.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;You can add the &lt;appsettings&gt; section in the web.config and add your key/value pairs in that section.&lt;/appsettings&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;You can have separate web.config files for each directory in your web application, in addition to the one in the root. For each web page, by default system will look for a web.config in the same folder as the page and if not found, then looks in the parent folder.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;table bgcolor="silver" cellpadding="5" cellspacing="1"&gt;&lt;tbody&gt;&lt;tr bgcolor="white"&gt;&lt;td width="468"&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/li&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-746286108675174205?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/746286108675174205/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/application-configuration-files.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/746286108675174205'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/746286108675174205'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/application-configuration-files.html' title='Application Configuration Files'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-4477472494813580983</id><published>2010-05-03T09:23:00.001-07:00</published><updated>2010-05-07T23:03:24.933-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='System.Net.WebRequest()'/><category scheme='http://www.blogger.com/atom/ns#' term='C# sample for retrieving html content from any websites'/><category scheme='http://www.blogger.com/atom/ns#' term='System.Net.WebRequest.Create(url)'/><category scheme='http://www.blogger.com/atom/ns#' term='System.IO.StreamReader'/><category scheme='http://www.blogger.com/atom/ns#' term='ystem.Net.WebRequest.GetResponse()'/><title type='text'>C# sample for retrieving html content from any websites</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;This chapter will teach you how to retrieve content of any website using .NET classes.&lt;br /&gt;&lt;br /&gt;This chapter and the attached sample application demonstrates the usage of following .NET classes and methods:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.Net.WebRequest() - Class to perform the web related operations.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.Net.WebRequest.Create(url) - Create a web request.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.Net.WebRequest.GetResponse() - Get the html content of the URL.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.IO.StreamReader - Read from file.&lt;/li&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-4477472494813580983?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/4477472494813580983/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/c-sample-for-retrieving-html-content.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/4477472494813580983'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/4477472494813580983'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/c-sample-for-retrieving-html-content.html' title='C# sample for retrieving html content from any websites'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-3433322307908127779</id><published>2010-05-03T09:22:00.001-07:00</published><updated>2010-05-07T23:05:38.826-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='System.IO.Path.GetExtension'/><category scheme='http://www.blogger.com/atom/ns#' term='DialogResult'/><category scheme='http://www.blogger.com/atom/ns#' term='MessageBox'/><category scheme='http://www.blogger.com/atom/ns#' term='C# sample for basic file operations'/><category scheme='http://www.blogger.com/atom/ns#' term='OpenFileDialog'/><category scheme='http://www.blogger.com/atom/ns#' term='Accessing database using ADO.NET in C# or VB.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='System.IO.File.Exists()'/><title type='text'>C# sample for basic file operations</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;This chapter will teach you the basic file operations. In the attached sample application, you can type some text and save into a text file. Also, you can select a text file and display the content in a textbox.&lt;br /&gt;&lt;br /&gt;In addition to the basic file operations, you can learn some good programming practices and error handling/validation techniques.&lt;br /&gt;&lt;br /&gt;This chapter and the attached sample application demonstrates the usage of following .NET classes and methods:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.IO.Path.GetExtension() - Method to check the extension of a file.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.IO.File.Exists() - Check if a file alread exists.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.Windows.Forms.OpenFileDialog - "File Open Dialog" to choose a file from the disk.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;DialogResult.OK - Result from a File Open Dialog.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;MessageBox.Show() - Displaying a message to the user.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;string.Trim() - Remove white space characters from beginning and end of string.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;throw new Exception() - Create and throw a new exception.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.IO.StreamWriter - Stream writer to write into files.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.IO.StreamReader - Read from file.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Application.Exit() - Closing an application.&lt;br /&gt;&lt;/li&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-3433322307908127779?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/3433322307908127779/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/c-sample-for-basic-file-operations.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/3433322307908127779'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/3433322307908127779'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/c-sample-for-basic-file-operations.html' title='C# sample for basic file operations'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-3722081670094334511</id><published>2010-05-03T09:21:00.001-07:00</published><updated>2010-05-07T23:25:01.356-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MessageBox icons'/><category scheme='http://www.blogger.com/atom/ns#' term='Displaying Simple MessageBox'/><category scheme='http://www.blogger.com/atom/ns#' term='MessageBox buttons'/><title type='text'>Displaying Simple MessageBox</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;This chapter and the attached sample application will give you a brief idea about the following:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Reading the text value from a textbox&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Displaying a message box&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;About the sample application&lt;/span&gt;&amp;nbsp;This application has 1 textbox and a button. If you type anything in the textbox and press the button, it will display the same text you typed in a MessageBox.&lt;br /&gt;&lt;br /&gt;Download and unzip the sample application from this page. After you unzip, you will get several files. Some of the important files are :&lt;br /&gt;&lt;br /&gt;1. Chapter1.csproj - This is the C# project file. Double click this file to&lt;br /&gt;open the project.&lt;br /&gt;&lt;br /&gt;2. Form1.cs - This is the file for the Form1 in teh sample application.&lt;br /&gt;&lt;br /&gt;After you open the project, see the 'Solution Explorer' bar on the right side of the Visual Studio. You can click on that to expand it, which will display the list of all files in the project. (Or, you can go to the menu 'View &amp;gt; Solution Explorer' to open the solution explorer.&lt;br /&gt;&lt;br /&gt;Click on 'Form1.cs' in the solution explorer to open the Form. Now you can see the Form in 'design mode'. Right click on the 'Form1.cs' in the solution explorer and choose 'View Code' to see the source code behind this Form (Or, press F7 from the Form to see the code).&lt;br /&gt;&lt;br /&gt;Let us analyze the code:&lt;br /&gt;&lt;br /&gt;The code has lot of Visual Studio generated code. For timebeing ignore all those code and scroll down to the event handler code in the bottom of the file.&lt;br /&gt;&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;&lt;span style="color: blue;"&gt;System.Windows.Forms.MessageBox.Show( "You typed : " + txtMessage.Text );&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;DialogResult result = MessageBox.Show( "Did you like this application ?", &lt;br /&gt;"Caption", MessageBoxButtons.YesNo, MessageBoxIcon.Question );&lt;br /&gt;if ( result == DialogResult.Yes ) &lt;br /&gt;      MessageBox.Show("You selected YES");&lt;br /&gt;else&lt;br /&gt;      MessageBox.Show("You selected NO");&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;The first line will simply display a messagebox and show the text typed by the user. 'MessageBox' is a class inside the&amp;nbsp;&lt;i&gt;namespace&lt;/i&gt;&amp;nbsp;'System.Windows.Forms'. We have a statement 'using System.Windows.Forms' on top of the source code. This is like a source code. This will help us avoid typing 'System.Windows.Forms.' everytime when we want to use a class inside this&amp;nbsp;&lt;i&gt;namespace&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;The next few lines of code do a bit more. Here we are displaying a message box, with some additional attributes.&lt;br /&gt;&lt;br /&gt;The second optional parameter of the 'Show' method is the 'caption' for the messagebox.&lt;br /&gt;&lt;br /&gt;The third parameter tells that the messagebox will have two buttons - YES and NO. You have several other options like MessageBoxButtons.OK, MessageBoxButtons.OKCancel etc.&lt;br /&gt;&lt;br /&gt;And, the last parameter says 'display a question Icon in the messagebox'. There are many other types of icons you can display.&lt;br /&gt;&lt;br /&gt;And another important part is, the MessageBox returns a value when the user press a button to close the messagebox. Our MessageBox asks a question 'Did you like this application ?" and gives two options to the user - YES or NO.&lt;br /&gt;&lt;br /&gt;The return value is of type 'DialogResult' and is assigned to the variable 'result'. We are checking the value of the result and depending on whether user pressed the YES button or NO button, appropriate message will be displayed.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-3722081670094334511?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/3722081670094334511/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/displaying-simple-messagebox.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/3722081670094334511'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/3722081670094334511'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/displaying-simple-messagebox.html' title='Displaying Simple MessageBox'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-9131703933492799745</id><published>2010-05-03T09:20:00.003-07:00</published><updated>2010-05-07T23:28:45.295-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='visual studio .net tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Mouse Move'/><category scheme='http://www.blogger.com/atom/ns#' term='Toolbox'/><category scheme='http://www.blogger.com/atom/ns#' term='WinForms'/><category scheme='http://www.blogger.com/atom/ns#' term='Mouse Click'/><category scheme='http://www.blogger.com/atom/ns#' term='Key Press'/><category scheme='http://www.blogger.com/atom/ns#' term='Button Click'/><category scheme='http://www.blogger.com/atom/ns#' term='Event driven programming'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual C# Projects'/><title type='text'>WinForms</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 18px;"&gt;&lt;span class="v11"&gt;WinForms is the most commonly used feature of .NET.&lt;br /&gt;'Windows' based applications in .NET is called 'WinForms'. The .NET framework comes with a good number of classes to support 'Form' based application development.&lt;br /&gt;A WinForm application will have atleast one 'Form' (window), which would be used for the interaction between the application and user. A Form can contain other controls like TextBox, Label, Button etc. Large WinForms applications will have several 'Forms', some of them used to capture data from user and some of them used to display data to user. By performing certain actions in each form, user can navigate to other 'Forms' in the application.&lt;br /&gt;&lt;br /&gt;&lt;span class="v11b"&gt;Event driven programming&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Event Driven programming model is the most commonly used feature in modern programming. In this model, you will write appropriate code for each event. Examples for events are&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v11"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v11"&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Button Click&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Mouse Move&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Mouse Click&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Key Press&lt;br /&gt;&lt;br /&gt;In Winforms application, users interact with the application using various&amp;nbsp;&lt;u&gt;actions&lt;/u&gt;in the window (like clicking a button, moving mouse, pressing keys in keyboard etc). These actions will generate various events. When an event is generated, the code written for that event will be executed.&lt;br /&gt;&lt;br /&gt;For example, in a user registration screen, you may have several controls like text boxes where user can enter their name, address, age etc. Once user enter all the information, he may press the 'Submit' button. As a developer, you would have written code in the button click event, to save this user entered data into a database. This is how typically a WinForms based application works in an event driven programming model.&lt;br /&gt;&lt;br /&gt;To create WinForms applications:&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Open Visual Studio .NET&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Select the menu : File &amp;gt; New &amp;gt; Project&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Choose from the project types : Visual C# Projects&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;From the Templates, choose the application type 'Windows Application'&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Enter the project name in the space for 'Name'.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Make sure the 'Location' is pointing to your folder. You may press the Browse button to select your personal folder, so that all your projects will be saved in your folder.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;span class="v11"&gt;Press 'OK' to create the projet. By default the project will be created with a sample form, named 'Form1'. You can drag and drop controls into this form, from the 'Toolbox' on the left hand side of the VS.NET.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;table bgcolor="silver" cellpadding="5" cellspacing="1"&gt;&lt;tbody&gt;&lt;tr bgcolor="white"&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/li&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-9131703933492799745?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/9131703933492799745/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/winforms.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/9131703933492799745'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/9131703933492799745'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/winforms.html' title='WinForms'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-9010470762820862093</id><published>2010-05-03T09:20:00.001-07:00</published><updated>2010-05-07T23:37:20.187-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='System.Xml'/><category scheme='http://www.blogger.com/atom/ns#' term='Namespaces in.net'/><category scheme='http://www.blogger.com/atom/ns#' term='c# namespace'/><category scheme='http://www.blogger.com/atom/ns#' term='System.Windows.Forms.Form'/><category scheme='http://www.blogger.com/atom/ns#' term='Namespaces'/><category scheme='http://www.blogger.com/atom/ns#' term='System.String'/><category scheme='http://www.blogger.com/atom/ns#' term='System.Data.SqlClient System.Data.OleDb'/><title type='text'>Namespaces</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;span class="v11"&gt;A&amp;nbsp;&lt;b&gt;Namespace&lt;/b&gt;&amp;nbsp;is a group of related classes. It is a good practice to group related classes into a namespace when you create a class library.&lt;br /&gt;&lt;br /&gt;The main advantage of using namespaces is, to avoid conflicts when you have multiple classes with the same name. For example, .NET comes with a class called 'Form'. Suppose you also write another class called 'Form' in your application and if you refer to the class 'Form', how does the compiler know which Form you are refering to ?&lt;br /&gt;&lt;br /&gt;Here is the importance of 'namespace'. You can refer to the .NET Form using the fully qualified name, including the namespace like this :&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;System.Windows.Forms.Form&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;And you can refer to your own Form like this :&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;MyApplication.Form&lt;/span&gt;, where MyApplication is your namespace.&lt;br /&gt;&lt;br /&gt;So, namespaces allow you to avoid name conflicts!&lt;br /&gt;&lt;br /&gt;All classes in .NET class library are grouped into namespaces. You can use all the classes using the fully qualified name, including the namespace also along with the class name.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v11"&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v11"&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.Windows.Forms.Form&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.String&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;span style="color: blue; font-family: courier;"&gt;System.Double&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you want to declare a Button object, you must do the following :&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;System.Windows.Forms.Button myButton;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;It is not mandatory to use the namespace also along with the name. You may use the&amp;nbsp;&lt;span style="color: blue; font-family: courier;"&gt;using&lt;/span&gt;&amp;nbsp;directive on top of the class and safely avoid the need to write the fully qualified name everytime when you refer to a class.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;using System.Windows.Forms.Button;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you have the above line of code on top of the class file, you don't need to type the namespace name&amp;nbsp;&lt;b&gt;System.Windows.Forms&lt;/b&gt;&amp;nbsp;with all the classes in this namespace. You can simply use class name directly as shown below:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;Button myButton;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;.NET Namespaces&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here is a list of&amp;nbsp;&lt;u&gt;some&lt;/u&gt;&amp;nbsp;of the namespaces in .NET class library.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.Xml&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.Data&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;System.Data.OleDb&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;span class="v11"&gt;&lt;span style="color: blue; font-family: courier;"&gt;System.Data.SqlClient&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-9010470762820862093?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/9010470762820862093/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/namespaces.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/9010470762820862093'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/9010470762820862093'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/namespaces.html' title='Namespaces'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-7850212593576260418</id><published>2010-05-03T09:19:00.003-07:00</published><updated>2010-05-07T23:38:09.847-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='private.constructor'/><category scheme='http://www.blogger.com/atom/ns#' term='Property in C# class'/><category scheme='http://www.blogger.com/atom/ns#' term='public'/><title type='text'>Property in C# class</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;How do you access member variables of any class from outside the class ? In most of the languages including C++ , you will make the member variables&amp;nbsp;&lt;span style="color: blue;"&gt;public&lt;/span&gt;&amp;nbsp;so that you can create an instance of the class and directly access the public fields, as shown below:&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;public class Car&lt;br /&gt;{&lt;br /&gt; // private fields.&lt;br /&gt; public string color;&lt;br /&gt;&lt;br /&gt; // constructor&lt;br /&gt; public Car()&lt;br /&gt; {&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;The above class has one public field : color. You may access this field from outside the class as shown below:&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;Car car = new Car();&lt;br /&gt;&lt;br /&gt;car.color = "red";&lt;br /&gt;&lt;br /&gt;string color = car.color;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;But this is the old way ! This would still work with C#, but the suggested approach is to use "Property" instead  of directly accessing member variables.&lt;br /&gt;&lt;br /&gt;The following code snippet shows how to create "Property" in a class.&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;public class Car&lt;br /&gt;{&lt;br /&gt; // private fields.&lt;br /&gt; private string color;&lt;br /&gt;&lt;br /&gt; // constructor&lt;br /&gt; public Car()&lt;br /&gt; {&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public string Color&lt;br /&gt; {&lt;br /&gt;  get&lt;br /&gt;  {&lt;br /&gt;   return color; // return the value from privte field.&lt;br /&gt;  }&lt;br /&gt;  set&lt;br /&gt;  {&lt;br /&gt;   color = value; // save value into private field.&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;The above class has one private field - color. Then we have one "Property" called 'Color', which is used to represent the private field. Note that the field is private and the Property is public. (We have used the same name with upper/lower case to represent the 'Property' and 'field', but you may give any name you want.)&lt;br /&gt;&lt;br /&gt;Each property has two parts :&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;b&gt;get&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;b&gt;set&lt;/b&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The&amp;nbsp;&lt;b&gt;get&lt;/b&gt;&amp;nbsp;part is executed when you access the value of the Property as shown below:&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;Car car = new Car();&lt;br /&gt;&lt;br /&gt;string color = car.Color;&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;When executed, the above&amp;nbsp;&lt;b&gt;get&lt;/b&gt;&amp;nbsp;accessor will return the value stored in the field 'color'.&lt;br /&gt;The&amp;nbsp;&lt;b&gt;set&lt;/b&gt;&amp;nbsp;part is executed when you assign a value to the Property as shown below:&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;Car car = new Car();&lt;br /&gt;&lt;br /&gt;car.Color = "RED";&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;When executed, the above&amp;nbsp;&lt;b&gt;set&lt;/b&gt;&amp;nbsp;accessor will assign the value "RED" to the private field 'color'. (Note that&lt;span style="color: blue;"&gt;'value'&lt;/span&gt;&amp;nbsp;is a keyword, which will have the value assigned to it.) &lt;br /&gt;&lt;span class="v12b"&gt;So, what is the difference ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;On the first look, there is no difference! You can achieve the same behaviour by writing 2 different methods ( like SetColor(...), GetColor() ).&lt;br /&gt;First advantage of using property is, code looks cleaner than having 2 separate methods. You can simply call a property as if it was a field in the class Well, then you may ask why make it 2 methods, we can make it a public field, so that we can access it by creating an instance of the class.&lt;br /&gt;The main advantage over using a Property instead of a public field is, with the property, you will get a chance to write few lines of code (if you want) in the get and set accessors. So, you can perform some validation or any other logic before returning any values or assigning to the private field.&lt;br /&gt;&lt;br /&gt;See the modifed class below:&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;public class Car&lt;br /&gt;{&lt;br /&gt; // private fields.&lt;br /&gt;  private string color;&lt;br /&gt;&lt;br /&gt; // constructor&lt;br /&gt; public Car()&lt;br /&gt; {&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public string Color&lt;br /&gt; {&lt;br /&gt;  get&lt;br /&gt;  {&lt;br /&gt;   if ( color == "" ) &lt;br /&gt;    return "GREEN";&lt;br /&gt;   else&lt;br /&gt;    return color;&lt;br /&gt;  }&lt;br /&gt;  set&lt;br /&gt;  {&lt;br /&gt;   if ( value == "" )&lt;br /&gt;    thrown new Exception ("Wrong value.");&lt;br /&gt;   else&lt;br /&gt;    color = value;&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;Let us analyze the&amp;nbsp;&lt;b&gt;get&lt;/b&gt;&amp;nbsp;part first. Here we are checking whether there is a valid value in the field 'color' before we return the value. If it is empty, we are getting a chance to return a default value 'Green'. This way, we can make sure that whoever calls the property 'Color' will always get a valid color, never an empty string.&lt;br /&gt;&lt;br /&gt;In the&amp;nbsp;&lt;b&gt;set&lt;/b&gt;&amp;nbsp;part, we are doing a validation to make sure we always assign a a valid value to our field. If someone assign an empty string to the 'Color' property, he will get an exception (error).&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;Car car = new Car();&lt;br /&gt;&lt;br /&gt;car.Color = "";&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The above code will throw an error because we are trying to assign an empty string and the&amp;nbsp;&lt;b&gt;set&lt;/b&gt;&amp;nbsp;accessor will throw an error if it an empty string. This way, we can make sure that we allow only valid values to be assigned.&lt;br /&gt;So, i guess now you would appreciate the purpose of "Property". So, no more public fields! Always have private fields and write public properties as wrapper for them if required to expose them to outside the class.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-7850212593576260418?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/7850212593576260418/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/property-in-c-class.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/7850212593576260418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/7850212593576260418'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/property-in-c-class.html' title='Property in C# class'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-15190940647356664</id><published>2010-05-03T09:19:00.001-07:00</published><updated>2010-05-07T23:39:16.804-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='using System'/><category scheme='http://www.blogger.com/atom/ns#' term='Exception classes in .NET'/><category scheme='http://www.blogger.com/atom/ns#' term='c# object oriented programming'/><category scheme='http://www.blogger.com/atom/ns#' term='Classes and Object model in .NET'/><title type='text'>Classes and Object model in .NET</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;span class="v11"&gt;We will start with an introduction to what is object oriented programming, how to write simple classes, creating objects etc.&lt;br /&gt;&lt;br /&gt;&lt;span class="v11b"&gt;What is a 'class' ?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In modern object oriented programming, large computer programs are divided into several 'classes'. Typically, a large project will have several hundred classes. A class represents an entity in a program. For example, if you are doing a small program called calculator, you will typically have a single (or more) class called 'Calculator' (you can give any name for your class). The class will have several 'methods', that will do the functionality of the class.&lt;br /&gt;&lt;br /&gt;So, your calculator may have methods like the following:&lt;br /&gt;Add()&lt;br /&gt;Subtract()&lt;br /&gt;Multiply()&lt;br /&gt;Divide()&lt;br /&gt;&lt;br /&gt;Here is a sample calculator class, written in C# :&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v11"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v11"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;&lt;span style="color: blue; font-family: 'courier new';"&gt;&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;public class Calculator&lt;br /&gt;{&lt;br /&gt;             public int Add(int value1, int value2)&lt;br /&gt;             {&lt;br /&gt;                        return value1 + value2;&lt;br /&gt;              }&lt;br /&gt;&lt;br /&gt;             public int Subtract(int value1, int value2)&lt;br /&gt;             {&lt;br /&gt;                       return value1 - value2;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;             public int Multiply(int value1, int value2)&lt;br /&gt;             {&lt;br /&gt;                      return value1 * value2;&lt;br /&gt;             }&lt;br /&gt;&lt;br /&gt;            public int Divide(int value1, int value2)&lt;br /&gt;            {&lt;br /&gt;                     return value1 / value2;&lt;br /&gt;            }&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;span class="v11"&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="v11b"&gt;Classes and objects&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: grey;"&gt;[To be added.]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="v11b"&gt;Object model in .NET&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: grey;"&gt;[To be added.]&lt;/span&gt;&amp;nbsp;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-15190940647356664?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/15190940647356664/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/classes-and-object-model-in-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/15190940647356664'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/15190940647356664'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/classes-and-object-model-in-net.html' title='Classes and Object model in .NET'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-6887122042017328247</id><published>2010-05-03T09:18:00.000-07:00</published><updated>2010-05-07T23:42:57.198-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Int32'/><category scheme='http://www.blogger.com/atom/ns#' term='float'/><category scheme='http://www.blogger.com/atom/ns#' term='object'/><category scheme='http://www.blogger.com/atom/ns#' term='uint'/><category scheme='http://www.blogger.com/atom/ns#' term='DataTypes in C#'/><category scheme='http://www.blogger.com/atom/ns#' term='bool'/><category scheme='http://www.blogger.com/atom/ns#' term='Int16'/><category scheme='http://www.blogger.com/atom/ns#' term='long'/><category scheme='http://www.blogger.com/atom/ns#' term='sbyte'/><category scheme='http://www.blogger.com/atom/ns#' term='Double'/><category scheme='http://www.blogger.com/atom/ns#' term='char'/><category scheme='http://www.blogger.com/atom/ns#' term='doubl'/><category scheme='http://www.blogger.com/atom/ns#' term='int'/><category scheme='http://www.blogger.com/atom/ns#' term='byte'/><category scheme='http://www.blogger.com/atom/ns#' term='string'/><title type='text'>DataTypes in C#</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;DataTypes are the basic building block of any language. Microsoft has tried to standardise the datatypes in .NET framework by introducing a limited, fixed set of types that can be used to represent almost anything in programming world.&lt;br /&gt;&lt;br /&gt;C++ was very rich in datatypes, but that leads to confusion too. Especially, when you write components that may be consumed by applications written in other platforms, you have to make sure the types used are compatible with other platforms too!&lt;br /&gt;&lt;br /&gt;.NET types start from a clean slate. All .NET languages share the same types. So, they are all compatible and no worries.This means, you can call C# code from VB.NET and vice versa, without worrying about type conversions.&lt;br /&gt;&lt;br /&gt;.NET data types are either&amp;nbsp;&lt;span style="color: blue;"&gt;struct&lt;/span&gt;ures or&amp;nbsp;&lt;span olor="blue"&gt;class&lt;/span&gt;es, part of the&amp;nbsp;&lt;span style="color: blue;"&gt;System&lt;/span&gt;&amp;nbsp;namespace. For example, the following data types are implemented as&amp;nbsp;&lt;span style="color: blue;"&gt;struct&lt;/span&gt;&amp;nbsp;in .NET:&lt;br /&gt;&lt;span style="color: blue;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;span style="color: blue;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;span style="color: blue;"&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Int16&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Int32&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;span style="color: blue;"&gt;Double&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;(&lt;span style="color: blue;"&gt;String&lt;/span&gt;&amp;nbsp;is implemented as a&amp;nbsp;&lt;span style="color: blue;"&gt;class&lt;/span&gt;&amp;nbsp;in .NET, for various reasons.)&lt;br /&gt;&lt;br /&gt;If you are not very familiar with&amp;nbsp;&lt;span style="color: blue;"&gt;struct&lt;/span&gt;&amp;nbsp;and&amp;nbsp;&lt;span style="color: blue;"&gt;class&lt;/span&gt;, don't worry about it. You can just use them as if they are simple data types.&lt;br /&gt;&lt;br /&gt;Here is how you can declare variables of type Int, Double and String:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue;"&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Int16 age, employeeNumber;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;Double salary;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;span style="color: blue;"&gt;String name, address;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You can use any of the .NET data types directly in any .NET language - in C#, VB.NET or xyz.NET.But in addition to the .NET types, each language provides a set of primitive types, which map to the corresponding types in .NET class library. This is why you may see some people use&amp;nbsp;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&amp;nbsp;and some others use&amp;nbsp;&lt;span style="color: blue;"&gt;String&lt;/span&gt;. There is no big difference.&amp;nbsp;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&amp;nbsp;is a primitive data type in C# and&amp;nbsp;&lt;span style="color: blue;"&gt;String&lt;/span&gt;&amp;nbsp;is the corresponding class in .NET class library. The&amp;nbsp;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&amp;nbsp;in C# is mapped to the class in .NET class library. So, whether you use&amp;nbsp;&lt;span style="color: blue;"&gt;string&lt;/span&gt;&amp;nbsp;or&lt;span style="color: blue;"&gt;String&lt;/span&gt;,there is no real difference.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;DataTypes in C# and the corresponding class/struct in .NET class library&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The following list shows the list of data types available in C# and their corresponding class/struct in .NET class library.&lt;br /&gt;&lt;br /&gt;&lt;table align="center" border="" cellpadding="3" cellspacing="1" valign="”top”"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class="v12b"&gt;C# Data type&lt;/td&gt;&lt;td class="v12b"&gt;Mapped to .NET class/struct&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;sbyte&lt;/td&gt;&lt;td&gt;System.SByte&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;byte&lt;/td&gt;&lt;td&gt;System.Byte&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;char&lt;/td&gt;&lt;td&gt;System.Char&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;float&lt;/td&gt;&lt;td&gt;System.Single&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;decimal&lt;/td&gt;&lt;td&gt;System.Decimal&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;double&lt;/td&gt;&lt;td&gt;System.Double&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ushort&lt;/td&gt;&lt;td&gt;System.UInt16&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;short&lt;/td&gt;&lt;td&gt;System.Int16&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;uint&lt;/td&gt;&lt;td&gt;System.UInt32&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;int&lt;/td&gt;&lt;td&gt;System.Int32&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;ulong&lt;/td&gt;&lt;td&gt;System.UInt64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;long&lt;/td&gt;&lt;td&gt;System.Int64&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;bool&lt;/td&gt;&lt;td&gt;System.Boolean&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;string&lt;/td&gt;&lt;td&gt;System.String&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;object&lt;/td&gt;&lt;td&gt;System.Object&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Value Types &amp;amp; Reference Types&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In C# data types are classified into two :&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;value types&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;reference types&lt;br /&gt;&lt;br /&gt;The following tables shows some of the differences between values types and reference types.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;table align="center" border="" cellpadding="3" cellspacing="1" valign="”top”"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td align="center" class="v12b"&gt;value types&lt;/td&gt;&lt;td align="center" class="v12b"&gt;reference types&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;allocated on stack&lt;/td&gt;&lt;td&gt;allocated on heap&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;a value type variable contains the data itself&lt;/td&gt;&lt;td&gt;reference type variable contains the address of memory location where data is actually stored.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;when you copy a value type variable to another one, the actual data is copied and each variable can be independently manipulated.&lt;/td&gt;&lt;td&gt;when copying a reference type variable to another variable, only the memory address is copied. Both variables will still point to thesame memory location, which means, if you change one variable, the value will be changed for the other variable too.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;integer, float, boolean, double etc are value types.&lt;/td&gt;&lt;td&gt;string and object are reference types.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;struct&lt;/span&gt;&amp;nbsp;is value type.&lt;/td&gt;&lt;td&gt;&lt;span style="color: blue;"&gt;class&lt;/span&gt;es and&amp;nbsp;&lt;span style="color: blue;"&gt;interface&lt;/span&gt;s are reference types.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-6887122042017328247?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/6887122042017328247/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/datatypes-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/6887122042017328247'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/6887122042017328247'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/datatypes-in-c.html' title='DataTypes in C#'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-7828555837285136602</id><published>2010-05-03T09:17:00.000-07:00</published><updated>2010-05-07T23:44:27.195-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='while'/><category scheme='http://www.blogger.com/atom/ns#' term='foreach'/><category scheme='http://www.blogger.com/atom/ns#' term='C# sample for basic file operations'/><category scheme='http://www.blogger.com/atom/ns#' term='C# Language Syntax'/><title type='text'>C# Language Syntax</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;b&gt;C# Language Syntax and essentials&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; font-size: 12px; line-height: 20px;"&gt;&lt;b&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="v11"&gt;his article will show you the basic statements in C# language and language syntax.&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Declaring Variables&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;b&gt;&lt;span class="v11"&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: small;"&gt;&lt;b&gt;&lt;span class="v11"&gt;&lt;hr color="silver" style="height: 1px;" /&gt;&lt;br /&gt;&lt;br /&gt;The following sample shows different ways you can declare a variable:&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;int a;&lt;br /&gt;int salary, incomeTax, sum;&lt;br /&gt;int count = 10;&lt;br /&gt;&lt;br /&gt;string name;&lt;br /&gt;string fullName= "Little John";&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Loop Statements&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr color="silver" style="height: 1px;" /&gt;&lt;br /&gt;&lt;span style="color: brown;"&gt;&lt;b&gt;while&lt;/b&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;int i = 0;&lt;br /&gt;while ( i &amp;lt; 5 )&lt;br /&gt;{&lt;br /&gt;Console.WriteLine ( i );&lt;br /&gt;++i;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;The above loop repeates 5 times and prints the value of i.&lt;br /&gt;The output of above code would be like this :&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;0&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: brown;"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/span&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;for ( int i = 0; i &amp;lt; 5; i++ )&lt;br /&gt;{&lt;br /&gt;Console.WriteLine ( i );&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;The above loop repeates 5 times just like the&amp;nbsp;&lt;b&gt;while&lt;/b&gt;&amp;nbsp;loop and prints the value of i.&lt;br /&gt;The output of above code would be like this :&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;0&lt;br /&gt;1&lt;br /&gt;2&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: brown;"&gt;&lt;b&gt;do ... while&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;int i = 0;&lt;br /&gt;do&lt;br /&gt;{&lt;br /&gt;     Console.WriteLine ( i );&lt;br /&gt;     i++;&lt;br /&gt;}&lt;br /&gt;while ( i &amp;lt; 5 );&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;The above loop is pretty much same as the&amp;nbsp;&lt;b&gt;while&lt;/b&gt;&amp;nbsp;loop. The only difference is, the condition is checked only after executing the code inside the loop.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: brown;"&gt;&lt;b&gt;foreach&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;string []  names = new string[]{ "Little John", "Pete", "Jim", "Bill" };&lt;br /&gt;foreach ( string name in names )&lt;br /&gt;{&lt;br /&gt;         Console.WriteLine ( name );&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;/b&gt;foreach&amp;nbsp;loop can be used to iterate through a collection like array, ArrayList etc.&lt;br /&gt;The above code displays the following output:&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;Little john&lt;br /&gt;Pete&lt;br /&gt;Jim&lt;br /&gt;Bill&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Conditional Operators&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr color="silver" style="height: 1px;" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: brown;"&gt;&lt;b&gt;if ... else&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is the conditional operator, used to selectively execute portions of code, based on some conditions.&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;string name = "Little John";&lt;br /&gt;if ( name == "Jim" )&lt;br /&gt;{&lt;br /&gt;     Console.WriteLine( "you are in 'if' block" );&lt;br /&gt;}&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;     Console.WriteLine( "you are in 'else' block" );&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;in the above case, it prints :&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;you are in 'else' block&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;Flow Control Statements&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr color="silver" style="height: 1px;" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: brown;"&gt;&lt;b&gt;break&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;'break' statement is used to break out of loops ('while', 'for', switch' etc).&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;string []  names = new string[] { "Little John", "Pete", "Jim", "Bill" };&lt;br /&gt;foreach ( string name in names )&lt;br /&gt;{&lt;br /&gt;     Console.WriteLine ( name );&lt;br /&gt;     if ( name == "Pete" )&lt;br /&gt;      &lt;b&gt;break&lt;/b&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;In the above sample, it iterates through the array of 4 items, but when it encounters the name "Pete", it exits the loop and will not continue in the loop anymore.&lt;br /&gt;The output of above sample would be :&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;Little John&lt;br /&gt;Pete&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: brown;"&gt;&lt;b&gt;continue&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;'continue' statement is also used to in the loops ('while', 'for' etc). When executed, 'continue' statement will move the exection to the next iteration in the loop, without continuing the lines of code after the 'continue' inside the loop.&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;string []  names = new string[]{ "Little John", "Pete", "Jim", "Bill" };&lt;br /&gt;&lt;br /&gt;foreach ( string name in names )&lt;br /&gt;{&lt;br /&gt;        if ( name == "Pete" )&lt;br /&gt;             &lt;b&gt;continue&lt;/b&gt;;&lt;br /&gt;&lt;br /&gt;         Console.WriteLine ( name );&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;In the above sample, when the value of name is "Pete", it executes the 'continue' which will change the execution to the next iteration, without executing the lines below it. So, it will not print the name, if the name is "Pete".&lt;br /&gt;The output of above sample would be :&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;Little John&lt;br /&gt;Jim&lt;br /&gt;Bill&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: brown;"&gt;&lt;b&gt;switch&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;if you have to writeseveral if...else conditions in your code, switch statement is a better way of doing it. The following sample is self explanatory:&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;int i = 3;&lt;br /&gt;switch ( i )&lt;br /&gt;{&lt;br /&gt;    case 5:&lt;br /&gt;                 Console.WriteLine( "Value of i is : " + 5 );&lt;br /&gt;                  break;&lt;br /&gt;     case 6:&lt;br /&gt;                  Console.WriteLine( "Value of i is : " + 6 );&lt;br /&gt;                   break;&lt;br /&gt;      case 3:&lt;br /&gt;                   Console.WriteLine( "Value of i is : " + 3 );&lt;br /&gt;                   break;&lt;br /&gt;      case 4:&lt;br /&gt;                    Console.WriteLine( "Value of i is : " + 4 );&lt;br /&gt;                    break;&lt;br /&gt;       default:&lt;br /&gt;                    Console.WriteLine( "Value of i is : " + i );&lt;br /&gt;                    break;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;br /&gt;In the above sample, depending on the value of the conditional item, it executes appripriate&amp;nbsp;&lt;b&gt;case&lt;/b&gt;. In our code, since the value of i is 3, it executes the third case. The output will be as shown below:&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;Value of i is : 3&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;table bgcolor="#ccffcc"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/b&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-7828555837285136602?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/7828555837285136602/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/c-language-syntax.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/7828555837285136602'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/7828555837285136602'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/c-language-syntax.html' title='C# Language Syntax'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-4874724598889781846</id><published>2010-05-03T09:16:00.000-07:00</published><updated>2010-05-07T23:45:14.981-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='&quot;Hello World&quot; Application in .net'/><category scheme='http://www.blogger.com/atom/ns#' term='&quot;Hello World&quot; using c#'/><title type='text'>"Hello World" Application</title><content type='html'>&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;b&gt;It is time to get started with code. In this chapter, we will show you how to write your first C# program. This chapter assumes that you have already installed and configured Visual Studio .NET in your computer.&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;Here we will guide you through step by step process to create your first sample .NET application. All our sample code will be using C# syntax. Readers are suggested to stick to this new elegant language, than going back to your favorite VB style.&lt;br /&gt;&lt;br /&gt;Hello World Application using C#&lt;br /&gt;&lt;br /&gt;Let us get started the traditional way, with a 'Hello World' application. We hope you all have Visual Studio.NET installed on your computer. If you have VS.NET, goto the menu option File &amp;gt; New &amp;gt; Project. Select 'Visual C# projects' and choose the project template 'Console Application'. This will create a default&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;A simple C# program would look like the following.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;pre style="border-bottom-style: inset; border-bottom-width: 1px; border-color: initial; border-left-style: inset; border-left-width: 1px; border-right-style: inset; border-right-width: 1px; border-top-style: inset; border-top-width: 1px; color: blue; font-family: Courier; font-size: medium; height: auto; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: scroll; overflow-y: scroll; padding-bottom: 6px; padding-left: 6px; padding-right: 6px; padding-top: 6px;"&gt;&lt;span style="color: blue; font-family: 'courier new';"&gt;&lt;br /&gt; using System;&lt;br /&gt;&lt;br /&gt; public class Hello&lt;br /&gt; {&lt;br /&gt;  public static void Main (string[] args)&lt;br /&gt;  {&lt;br /&gt;   Console.WriteLine("Hello C# World");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; &lt;/span&gt;&lt;br /&gt; &lt;/pre&gt;&lt;br /&gt;When you create a new Console Application, it will create a default class and you can just insert one line of code into it:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;&lt;br /&gt;Console.WriteLine("Hello C# World");&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now compile and run your first program by pressing Ctrl + F5. You will see the following result :&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&amp;gt; Hello C# World&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;You are done! You got your first C# program successfully running.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;table border="1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td align="center"&gt;&lt;br /&gt;If you do not have VS.NET, you may use any editor (including notepad) to create your first C# program. Create a new file with the name sample.cs and type the C# code shown. Now go to the command prompt and navigate to the folder where you have the .NET framework installed. Compile your csharp file by using the command 'csc':&lt;br /&gt;&lt;br /&gt;&lt;b&gt;csc c:\samples\sample.cs&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;csc is the C# compiler. The above command will produce the output file sample.exe. You can run the sample.exe and you will see the output from the program.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="v11b"&gt;Analyzing your first program&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;See the first line of code :&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: 'courier new';"&gt;using System;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;"System" is a namespace and the "using" directive says that all classes in the "System" namespace can beused in this class without using the fully qualified name. In our class, "Console" is a class in the namespace "System". To use this class you have to actually write :&lt;span style="color: blue; font-family: 'courier new';"&gt;System.Console.WriteLine ("...");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;But the&amp;nbsp;&lt;span style="color: blue; font-family: 'courier new';"&gt;using System;&lt;/span&gt;&amp;nbsp;directive on top of the classallows us to use the class without including the namespace. So, you can now simply write :&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: 'courier new';"&gt;Console.WriteLine("...");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;If you are familiar with Object Oriented Programming, you might not need more explanation for the next line - declaring a class.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;public static void Main (string[] args)&lt;/span&gt;&amp;nbsp;- is the Main method, which is thestarting point of the application.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: courier;"&gt;string[] args&lt;/span&gt;&amp;nbsp;is the list of arguments that are passed to this application. (In our case, we are not passing any command line parameters).&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-family: 'courier new';"&gt;Console.WriteLine("...")&lt;/span&gt;&amp;nbsp;is another line of important code.&amp;nbsp;&lt;b&gt;Console&lt;/b&gt;&amp;nbsp;is a class, part of .NET class library included in&amp;nbsp;&lt;b&gt;System&lt;/b&gt;&amp;nbsp;namespace.&amp;nbsp;&lt;b&gt;WriteLine&lt;/b&gt;&amp;nbsp;is a method part if this class and used to printoutput to the default Console.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-4874724598889781846?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/4874724598889781846/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/hello-world-application.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/4874724598889781846'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/4874724598889781846'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/hello-world-application.html' title='&quot;Hello World&quot; Application'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-3479646464672054476</id><published>2010-05-03T09:12:00.000-07:00</published><updated>2010-05-07T23:47:05.184-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='visual studio .net tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='visual studio .net free download'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio .NET 2010'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio .NET 2008'/><category scheme='http://www.blogger.com/atom/ns#' term='visual studio .net'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio .NET 2005'/><category scheme='http://www.blogger.com/atom/ns#' term='Visual Studio .NET 3.5'/><title type='text'>Visual Studio .NET</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;b&gt;What is Visual Studio.NET ?&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;Many people always get confused with Visual Studio .NET (VS.NET) and .NET technology. VS.NET is just an editor, provided by Microsoft to help developers&amp;nbsp;&lt;i&gt;write .NET programs easily&lt;/i&gt;&amp;nbsp;. VS.NET editor automatically generates lot of code, allows developers to drag and drop controls to a form, provide short cuts to compile and build the application etc.&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="v12b"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;&lt;div style="text-align: justify;"&gt;Understand Visual Studio .NET&lt;/div&gt;&lt;/span&gt; &lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;VisualStudio is a very user friendly tool. But there are enough stuff to confuse any one new to Visual Studio family. The purpose of this chapter is to make you familiar with different options in Visual Studio.NET (VS.NET) We will not cover the entire visual studio guide. We are just explaining the most commonly used features of VS.NET.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;When you work on any&amp;nbsp;&lt;i&gt;project&lt;/i&gt;, VS.NET has several child windows to assist you in the application development. These windows are attached on the left, bottom and right sides of the main window. You can click on these small windows to expand it and see the content of them. Some of the most commonly used child windows are explained below. Most of these windows will be enabled only when you have created a project and working on a WebForm/WinForm.&lt;/div&gt;&lt;/span&gt;&lt;br /&gt;&lt;table style="text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;b&gt;Toolbox&lt;/b&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;s all the drag and drop controls for your application. Depending on the kind of application you are working on, the toolbox will show appropriate controls and you can drag and drop them to your form. If you are developing a web application, toolbox will show ASP.NET controls and if you are developing a Windows application, it will show Windows controls (like Radio button, text box, buttons etc).&lt;/div&gt;&lt;br /&gt;You can simply drag and drop any controls from the toolbox to your form. After you drag and drop any control, double click on the control to go the default event associated with the control.&lt;br /&gt;&lt;br /&gt;The Toolbox will be enabled only when you have a WebForm or WinForm opened in&amp;nbsp;&lt;i&gt;Design mode&lt;/i&gt;&amp;nbsp;and is usually located on TOP LEFT corner of the VS.NET.&lt;br /&gt;&lt;br /&gt;By default, all windows including Toolbox will be displayed as&amp;nbsp;&lt;i&gt;Minimized&lt;/i&gt;&amp;nbsp;(&lt;i&gt;Marked as A in picture&lt;/i&gt;). You will see only the small icon and the text 'Toolbox' written vertically on the left bar of VS.NET. You can click on this minimized window to expand it (&lt;i&gt;Expanded window is marked as C.&lt;/i&gt;). When you move the mouse away from the window, it will again automatically minimize. You can keep the toolbox always expanded by pressing the&amp;nbsp;&lt;i&gt;pushpin&lt;/i&gt;&amp;nbsp;(&lt;i&gt;Marked with B.&lt;/i&gt;)&lt;br /&gt;&lt;br /&gt;The above behaviour is common for all the windows explained below. They will be minimized by default and you can point the mouse over it to expand it. Use the pushbutton to keep it expanded.&lt;/td&gt;&lt;td&gt;&lt;span style="color: #990099;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #990099;"&gt;&lt;center&gt;&lt;br /&gt;&lt;/center&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;table style="text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span class="Apple-style-span" style="color: #990099;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #990099;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #990099;"&gt;&lt;center&gt;&lt;br /&gt;&lt;/center&gt;&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Design mode &amp;amp; HTML mode&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;If you are developing a web application, you can switch between design mode and HTML mode for any web form. When you are in&amp;nbsp;&lt;i&gt;HTML mode&lt;/i&gt;, it will show you the HTML tags and ASP.NET code and you can manually edit it. YOu can switch to the&amp;nbsp;&lt;i&gt;Design mode&lt;/i&gt;&amp;nbsp;by clicking the Design button on BOTTOM LEFT corner of VS.NET. In design mode, you can see how your ASP.NET page is going to look like when some one view your web page. Also, you can drag and drop controls from the toolbox, which will automatically generate the HTML for it.&lt;br /&gt;&lt;br /&gt;Typically, developers switch between these two modes very frequently. You can go to design mode to drag/drop controls, right click on the controls to set correct properties etc. Then, click on the HTML mode to view the generated HTML. You can manually cmake changes to the automatically generated HTML. If you change any properties in&amp;nbsp;&lt;i&gt;HTML mode&lt;/i&gt;, the changes will be reflected when you switch to&amp;nbsp;&lt;i&gt;Design Mode&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;table style="text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;b&gt;Solution Explorer&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Solution Explorer&lt;/i&gt;, located on TOP RIGHT corner of VS.NET, displays your solution, all projects included in each solution and the list of files in each project. They are listed in the form of a tree control.&lt;br /&gt;&lt;br /&gt;ypically, for a single application, you will have 1 solution and one or more projects. When you create a new application, you are have to create single Visual Studio project. In more complex applications, there may be more than one projects. All these projects are grouped into a single solution. Even if you do not create a solution separately, a solution will be automatically created for you.&lt;br /&gt;&lt;br /&gt;To add a new file to your project, you can right click on the project name (&lt;b&gt;JustTest&lt;/b&gt;is the project name in the picture) and choose the menu option&amp;nbsp;&lt;b&gt;Add&lt;/b&gt;. It will give you the option to choose a file type. You can choose an appropriate type.&lt;br /&gt;&lt;br /&gt;For WinForms and WebForms, you can see the file in design mode and the code associated with it. Double click on any form and it will be opened in design mode. Right click on any form and select the menu option 'View Code' to view the code associate with the form.&lt;/td&gt;&lt;td&gt;&lt;span style="color: #990099;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #990099;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #990099;"&gt;&lt;center&gt;&lt;br /&gt;&lt;/center&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;table style="text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;span style="color: #990099;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #990099;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #990099;"&gt;&lt;center&gt;&lt;br /&gt;&lt;/center&gt;&lt;/span&gt;&lt;/td&gt;&lt;td&gt;&lt;b&gt;Output&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Output&lt;/i&gt;&amp;nbsp;window, located on BOTTOM LEFT corner of VS.NET, displays the result of your project compilation. When you compile your project, all errors, warnings and compilation results will be displayed in this window.&lt;br /&gt;&lt;br /&gt;In addition to the Output window, they are few other windows located in the BOTTOM LEFT corner of VS.NET.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Task List&lt;/b&gt;&amp;nbsp;- shows individual tasks. Typically, when you compile your project, all errors and warnings will be added to your task list. You can double click on any item in the task list to go directly to the code associated with the task&lt;br /&gt;&lt;br /&gt;.&lt;b&gt;Command Window&lt;/b&gt;&amp;nbsp;- you can execute code statements here. When you are debugging, you can evaluate the value of any variables by typing ? followed by the variable name.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Find Results&lt;/b&gt;&amp;nbsp;- when you search for any text in file(s) using VS.NET, the results will be displayed in this window.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;Projects&lt;/b&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;VS.NET allows you to create several types of projects. Most of the time you will be using one of two categories:&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px; text-align: justify;"&gt;Windows Application - to create any standard windows application.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;ASP.NET Web Application - to create a web site.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;table id="Table1" style="text-align: justify;"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;b&gt;Creating a Project&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;To create a new project, choose the main menu :&amp;nbsp;&lt;b&gt;File &amp;gt; New &amp;gt; Project&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;It will give you several options. First you must select a type from the left side of the popup - you may choose&lt;i&gt;Visual Basic Projects&lt;/i&gt;&amp;nbsp;or&amp;nbsp;&lt;i&gt;Visual C# projects&lt;/i&gt;&amp;nbsp;based on the language you plan to use for development.&lt;br /&gt;&lt;br /&gt;After selecting a type, you choose a template from the right side. You may choose&amp;nbsp;&lt;i&gt;Windows Application&lt;/i&gt;,&amp;nbsp;&lt;i&gt;ASP.NET Web Application&lt;/i&gt;&amp;nbsp;or any other&amp;nbsp;&lt;i&gt;template&lt;/i&gt;based on the nature of the application you want.&lt;/td&gt;&lt;td&gt;&lt;span style="color: #990099;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: #990099;"&gt;&lt;center&gt;&lt;br /&gt;&lt;/center&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;When you create a&amp;nbsp;&lt;i&gt;Windows Project&lt;/i&gt;&amp;nbsp;or&amp;nbsp;&lt;i&gt;ASP.NET Web Project&lt;/i&gt;, VS.NET will add a sample file by default. You can simply&amp;nbsp;&lt;i&gt;Build&lt;/i&gt;&amp;nbsp;your new project and see how it works.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;Building a project&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt; &lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;To try this, create a new&amp;nbsp;&lt;i&gt;Windows Project&lt;/i&gt;&amp;nbsp;as explained above. It will create a sample form. Go to the main menu and select the menu item&amp;nbsp;&lt;b&gt;Build &amp;gt; Build Solution&lt;/b&gt;.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;This process will compile all the files included in your project and show you the result in the&amp;nbsp;&lt;i&gt;Output&lt;/i&gt;&amp;nbsp;window. If the result shows '0 failed', your build is success and your application is ready to deliver!!&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;To&amp;nbsp;&lt;i&gt;Run&lt;/i&gt;&amp;nbsp;the application you just&amp;nbsp;&lt;i&gt;Built&lt;/i&gt;, go to the main menu and select&amp;nbsp;&lt;b&gt;Debug &amp;gt; Start Without Debugging&lt;/b&gt;. This will launch the application you just developed.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;You can drag and drop several controls to the form and try running it.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;When you compile (build) the code, if there is any errors or warnings, the details will be shown in the 'Task List' window. You can click on the specific item in this window to go directly to the line of code associated with the error.&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-3479646464672054476?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/3479646464672054476/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/visual-studio-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/3479646464672054476'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/3479646464672054476'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/visual-studio-net.html' title='Visual Studio .NET'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-1884737819535467830</id><published>2010-05-03T08:55:00.001-07:00</published><updated>2010-05-07T23:47:42.539-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Introducing the .NET Framework'/><category scheme='http://www.blogger.com/atom/ns#' term='What Is .NET ?'/><title type='text'>Introducing the .NET Framework with C#</title><content type='html'>&lt;div style="text-align: left;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;h1 style="color: #3366aa; font-family: Helvetica, Arial, 'Times New Roman'; font-size: 22px; margin-bottom: 3px; margin-left: 1px; margin-right: 3px; margin-top: 3px; text-align: justify;"&gt;What Is .NET ?&lt;/h1&gt;&lt;span id="ctl00_ContentPlaceHolder1_lblAuthorText"&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;hr color="gold" style="height: 1px; text-align: left;" width="70%" /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;div style="text-align: justify;"&gt;&lt;b&gt;This chapter gives you an introduction to the .NET technology and explains what is .NET.&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;b&gt;.NET is a major technology change for Microsoft and the software world. Just like the computer world moved from DOS to Windows, now they are moving to .NET. But don't be surprised if you find anyone saying that "I do not like .NET and I would stick with the good old COM and C++". There are still lot of people who like to use the bullock-cart instead of the latest Honda car.&lt;/b&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;The simple answer is 'it is the technology from Microsoft, on which all other Microsoft technologies will be depending on in future.'.&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;.NET technology was introduced by Microsoft, to catch the market from the SUN's Java. Few years back, Microsoft had only VC++ and VB to compete with Java, but Java was catching the market very fast. With the world depending more and more the Internet/Web and java related tools becoming the best choice for the web applications, Microsoft seemed to be loosing the battle. Thousands of programmers moved to java from VC++ and VB. This was alarming for Microsoft and many of the Microsoft fan's kept on asking "is Microsoft sleeping?". And Microsoft had the answer. One fine morning, they announced : "We are not sleeping. We have the answer for you.". And that answer was .NET.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;But Microsoft has a wonderful history of starting late but catching up quickly. This is true in case of .NET too. Microsoft put their best men at work for a secret project called&amp;nbsp;&lt;b&gt;Next Generation Windows Services (NGWS).&lt;/b&gt;, under the direct supervision of Mr. Bill Gates. The outcome of the project is what we now know as .NET. Even though .NET has borrowed most of it's ideas from Sun's J2EE, it has really outperformed their competitors.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Microsoft's VC++ was a powerful tool. But it was too complex. It has too many datatypes, and developers had to learn many libraries including WIndows SDK, MFC, ATL, COM etc. There were many datatype compatibility issues while exchanging data between different layers. Visual Basic was too easy, and many serious programmers hated it just for that reason. Even though Visual basic was very easy to use, it was not very flexible to develop serious applications. SUN's Java became a very good choice for these reasons. It had the flixibility and power of C++ and at the same time easy enough to catch the attention of VB programmers.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Microsoft recognised these factors and they introducd the .NET considering all these factors. All unwanted complexities are eliminated and a pure object oriented programming model was introduced. This makes programmer's life very easy.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;.NET framework comes with a single class library. And thats all programmers need to learn!! Whether they write the code in C# or VB.NET or J#, it doesn't matter, you just use the .NET class library. There is no classes specific to any language. There is nothing more you can do in a language, which you can't do in any other .NET language. You can write code in C# or VB.NET with the same number of lines of code, same performance and same efficiency, because eveyone uses same .NET class library.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="v12b"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;&lt;div style="text-align: justify;"&gt;What is .NET ?&lt;/div&gt;&lt;/span&gt; &lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; color: #666362; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 20px;"&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px; text-align: justify;"&gt;It is a platform neutral framework.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px; text-align: justify;"&gt;Is a layer between the operating system and the programming language.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px; text-align: justify;"&gt;It supports many programming languages, including VB.NET, C# etc.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px; text-align: justify;"&gt;.NET provides a common set of class libraries, which can be accessed from any .NET based programming language. There will not be separate set of classes and libraries for each language. If you know any one .NET language, you can write code in any .NET language!!&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;In future versions of Windows, .NET will be freely distributed as part of operating system and users will never have to install .NET separately.&lt;/div&gt;&lt;span class="v12b"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;&lt;div style="text-align: justify;"&gt;What is Not ?&lt;/div&gt;&lt;/span&gt; &lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px; text-align: justify;"&gt;.NET is not an operating system.&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;.NET is not a programming language.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="v12b"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;&lt;div style="text-align: justify;"&gt;".NET is a framework"&lt;/div&gt;&lt;/span&gt; &lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Are you confused by this definition? Well, that is OK. It is really confusing!&lt;/div&gt;&lt;div style="text-align: justify;"&gt;We cannot define .NET as a 'single thing'. It is a new, easy, and extensive programming platform. It is not a programming language, but it supports several programming languages. By default .NET comes with few programming languages including C# (C Sharp), VB.NET, J# and managed C++. .NET is a common platform for all the supported languages. It gives a common class library, which can be called from any of the supported languages. So, developers need not learn many libraries when they switch to a different language. Only the syntax is different for each language.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;When you write code in any language and compile, it will be converted to an 'Intermediate Language' (Microsoft Intermediate Language - MSIL). So, your compiled executable contains the IL and not really executable machine language. When the .NET application runs, the .NET framework in the target computer take care of the execution. (To run a .NET application, the target computer should have .NET framework installed.) The .NET framework converts the calls to .NET class libraries to the corresponding APIs of the Operating system.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Whether you write code in C# or VB.NET, you are calling methods in the same .NET class libraries. The same .NET framework executes the C# and VB.NET applications. So, there won't be any performance difference based on the language you write code.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="v12b"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;&lt;div style="text-align: justify;"&gt;What is Visual Studio.NET ?&lt;/div&gt;&lt;/span&gt; &lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Many people always get confused with Visual Studio .NET (VS.NET) and .NET technology. VS.NET is just an editor, provided by Microsoft to help developers&amp;nbsp;&lt;i&gt;write .NET programs easily&lt;/i&gt;. VS.NET editor automatically generates lot of code, allows developers to drag and drop controls to a form, provide short cuts to compile and build the application etc.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;VS.NET is not a&amp;nbsp;&lt;b&gt;required&lt;/b&gt;&amp;nbsp;thing to do .NET programming. You can simply use a notepad or any other simple editor to write your .NET code!!! And you can compile your .NET programs from the command prompt.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Well, what I said is true theoretically.. but if you decide to use notepad for .NET programming, by the time you develop few sample applications, Microsoft would have introduced some other new technology and .NET would be outdated. You may not want that. So, let us go by VS.NET, just like every other .NET guys.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="v12b"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;&lt;div style="text-align: justify;"&gt;.NET supported languages&lt;/div&gt;&lt;/span&gt; &lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Currently .NET supports the following languages:&lt;/div&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px; text-align: justify;"&gt;C#&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px; text-align: justify;"&gt;VB.NET&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px; text-align: justify;"&gt;C++&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;li style="line-height: 18px; margin-left: 15px;"&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;J#&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The above languages are from Microsoft. Many third parties are writing compilers for other languages with .NET support.&lt;span class="v12b"&gt;Difference between VB and VB.NET&lt;/span&gt;Believe us, there is not much in common between VB and VB.NET other than the name. VB.NET is a totally new programming language. It just retains the syntax of old VB. So, if you are a vb programmer, probably you may like VB.NET than C# just because of the syntax.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;In addition to this, VB.NET still support many of the old VB functions just for backward compatibility. But if you are a serious .NET programmer, we strongly suggest never use old VB functions in VB.NET. So, switching from VB to VB.NET is just like learning a new programming language, with very small similarities between them.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="v12b"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;&lt;div style="text-align: justify;"&gt;C# or VB.NET ? Which one to choose ?&lt;/div&gt;&lt;/span&gt; &lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;As we mentioned in earlier chapters, it makes no much difference. Whether you write code in VB.NET or C#, when you compile, your code will get converted to MSIL (Microsoft Intermediate language). It is this MSIL which you deliver to your customer in the form of a DLL or EXE. The MSIL is executed by the same .NET framework, whether you wrote it originally in C# or VB.NET.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The MSIL generated by C# and VB.NET is almost 99% is the same! Many believe that C# has the power of C++ and VB.NET has the user friendliness of VB. That is not true. Both are equally powerfull and friendly.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;VB.NET has backward compatibility with old Visual basic. So, it supports old vb functions. C# is a fresh, clean language. So strongly support using C# instead of VB.NET just for this clean compiler.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Many old VB guys usually like to stick with VB.NET and are kind of scared of C#. We are sure that you will not take more than few days to get familiar with C# syntax. This online tutorial is based on C# and all samples will be provided in C#.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="v12b"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;&lt;div style="text-align: justify;"&gt;Is it platform independent ?&lt;/div&gt;&lt;/span&gt; &lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Many people ask this question "Java is platform independent, what about .NET ?".&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The answer is "Yes" and "No" !&lt;/div&gt;&lt;div style="text-align: justify;"&gt;The code you write is platform independent, because whatever you write is getting compiled into MSIL. There is no native code, which depends on your operating system or CPU. But when you execute the MSIL, the .NET framework in the target system will convert the MSIL into native platform code.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;So, if you run your .NET exe in a WIndows machine, the&amp;nbsp;&lt;i&gt;.NET framework for Windows&lt;/i&gt;&amp;nbsp;will convert it into Windows native code and execute. If you run your .NET application in Unix or Linux, the&amp;nbsp;&lt;i&gt;.NET framework for Unix/Linux&lt;/i&gt;will convert your code into Unix/Linux native code and execute. So, your code is purely platform independent and runs anywhere!&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;But wait, we said it wrong... there is no&amp;nbsp;&lt;i&gt;.NET framework for Unix or Linux&lt;/i&gt;available now. Microsoft has written the .NET framework only for Windows. If you or some one else write a .NET framework for other platforms in future, your code will run there too. So, let us wait until someone write .NET framework for Linux before you run your .NET code in Linux.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="v12b"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;&lt;div style="text-align: justify;"&gt;Is it worth learning .NET ?&lt;/div&gt;&lt;/span&gt; &lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Are you sure you have a very good job now and your job is safe for next 10 years? Then, probably you don't need to waste your time to learn this new technology.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;If you are not sure about the future of your job, better spend sometime and make sure you have fuel to run for next few years!&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="v12b"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;&lt;div style="text-align: justify;"&gt;How long it will take to learn .NET ?&lt;/div&gt;&lt;/span&gt; &lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;It all depends on how fast you can learn. If you are familiar with Visual Basic or C++, you can come to speed in .NET within 1-2 months. If you are a new to programming, we estimate 6 months will be a reasonable period to become comfortable with .NET world.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="v12b"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="v12b"&gt;&lt;div style="text-align: justify;"&gt;Future of .NET&lt;/div&gt;&lt;/span&gt; &lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;Microsoft is moving all its technologies to be .NET based or .NET related. The next version of SQL Server even supports writing&amp;nbsp;&lt;i&gt;stored procedures&lt;/i&gt;&amp;nbsp;in .NET languages. .NET runtime will be part of all Operating Systems by default.&lt;/div&gt;&lt;div style="text-align: justify;"&gt;In short, if you like to work on Microsoft technologies for programming, .NET would be the only choice you will have.&lt;/div&gt;&lt;/li&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: justify;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-1884737819535467830?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/1884737819535467830/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/introducing-net-framework-with-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/1884737819535467830'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/1884737819535467830'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/introducing-net-framework-with-c.html' title='Introducing the .NET Framework with C#'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4777054191702843272.post-6148086850009067174</id><published>2010-05-01T03:53:00.001-07:00</published><updated>2010-05-01T07:41:57.653-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='dotnet pdf'/><category scheme='http://www.blogger.com/atom/ns#' term='Define .NET framework ?'/><category scheme='http://www.blogger.com/atom/ns#' term='.NET framework'/><category scheme='http://www.blogger.com/atom/ns#' term='Dotnet online course'/><category scheme='http://www.blogger.com/atom/ns#' term='Dotnet projects'/><category scheme='http://www.blogger.com/atom/ns#' term='.Dotnet basics'/><title type='text'>.Net Framework</title><content type='html'>&lt;div align="center" class="bodytext" style="font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 12px;"&gt;&lt;b&gt;&lt;span style="color: #660000;"&gt;.NET framework&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div align="center" class="bodytext" style="font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 12px;"&gt;&lt;b&gt;&lt;span style="color: #660000;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class="bodytext" style="font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 12px;"&gt;&lt;language, library="" tool,=""&gt;A software development and execution environment designed by {Microsoft} as a direct competitor to {Java}. &amp;nbsp;.NET framework should not be confused with {Microsoft}'s past labeling of a line of products as ".NET". .NET simplifies interoperability between languages and machines on {Microsoft Windows} especially, although not specifically, for web based services. &amp;nbsp;Essentially the .NET framework consists of the CLR (common language runtime), CTS (common type system), CLS (common language system), and IL (intermediate language). The CLR consists of a number of resources provided to .NET applications such as the security model, type system and .NET classes (c.f. Java classes). &amp;nbsp;The CTS is the range of all types that .NET understands although it is not necessarily the case that a .NET program will understand all of these types. The CLS however is a subset of the CTS which all .NET languages must support: any two .NET languages can interoperate via. the CLS. All .NET languages are at some stage compiled into the IL, a {byte-code} like language. &amp;nbsp;However unlike a standard Java run time environment, the IL is converted to {machine code} either upon installation of the software or at {run time} by a {just in time compiler} (JIT). &amp;nbsp;The IL is not interpretted. .NET's main weakness is that Microsoft have ignored the {Unix} and {mainframe} environments, effectively ruling .NET out of use in many {enterprise} environments. &amp;nbsp;However there is {Mono} - an {open source} .NET framework for Unix}. .NET was based on research by Steven Lucco on a product called {OmniVM}, sold by {Colusa software}. &amp;nbsp;Attracted to OmniVM since VB and C/C++ environments were already available, Microsoft bought Colusa in 1996. &amp;nbsp;Microsoft provides .NET compilers for {C#}, {C++}, {VB}, and {Jscript}. (2003-09-24)&lt;/language,&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4777054191702843272-6148086850009067174?l=dotnetfirez.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetfirez.blogspot.com/feeds/6148086850009067174/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/net-framework.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/6148086850009067174'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4777054191702843272/posts/default/6148086850009067174'/><link rel='alternate' type='text/html' href='http://dotnetfirez.blogspot.com/2010/05/net-framework.html' title='.Net Framework'/><author><name>kathir</name><uri>http://www.blogger.com/profile/12882214548134657492</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_bciqPIMppbI/SqOcN3FC01I/AAAAAAAAAFQ/MlmF5GjI80I/S220/OgAAAGZPMdiwLeArJrdYFvXDifzxKOMFjYbfI7nq9GzyemndiSLtdpFCT0Rf3GKISlNKHE-WB_zqcOdIUCimmjkncAwAm1T1UIDrG_i9RXQ1thHILfdB0erqfl2G.jpg'/></author><thr:total>0</thr:total></entry></feed>
