<?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-3068650074752359005</id><updated>2011-12-08T12:09:44.921-08:00</updated><title type='text'>Application Development</title><subtitle type='html'>The purpose of this Blog is to spread the News and Facts about Application Development. If you want any of your articles or any interesting news about application development , keep in touch.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ravindra Patel</name><uri>http://www.blogger.com/profile/01282844182571885522</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>39</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-8449035499622209863</id><published>2010-08-28T03:13:00.000-07:00</published><updated>2010-08-28T03:27:58.543-07:00</updated><title type='text'></title><content type='html'>&lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Windows&lt;span class="superscript"&gt;®&lt;/span&gt;  Communication Foundation (WCF), formerly code-named "Indigo," is about to  radically change the face of distributed programming for developers using the  Microsoft&lt;span class="superscript"&gt;®&lt;/span&gt; .NET Framework. WCF unifies the  existing suite of .NET distributed technologies into a single programming model  that improves the overall developer experience through a consistent  architecture, new levels of functionality and interoperability, and all the  extensibility points you could want. This article introduces you to WCF  programming and shows you how to get started.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;As its name suggests, WCF provides the .NET  Framework with a basis for writing code to communicate across components,  applications, and systems. WCF was designed according to the tenets of service  orientation. A service is a piece of code you interact with through messages.  Services are passive. They wait for incoming messages before doing any work.  Clients are the initiators. Clients send messages to services to request  work.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleImageSpacer"&gt;&lt;br /&gt;&lt;div class="ArticleImageCaptionText"&gt;Figure 1&lt;strong&gt; Services and  Endpoints &lt;/strong&gt;&lt;/div&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Services expose one or more endpoints where  messages can be sent. Each endpoint consists of an address, a binding, and a  contract (see &lt;strong&gt;Figure 1&lt;/strong&gt;). The address specifies where to send  messages. The binding describes how to send messages. And the contract describes  what the messages contain. Clients need to know this information before they can  access a service.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Services can package up endpoint descriptions to  share with clients, typically by using Web Services Description Language (WSDL).  Then clients can use the provided service description to generate code within  their environment capable of sending and receiving the proper messages (see  &lt;strong&gt;Figure 2&lt;/strong&gt;).&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleImageSpacer"&gt;&lt;br /&gt;&lt;div class="ArticleImageCaptionText"&gt;Figure 2&lt;strong&gt; Sharing Endpoint  Descriptions &lt;/strong&gt;&lt;/div&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Windows Communication Foundation provides a new  library of classes found in the System.ServiceModel namespace that bring these  service-oriented concepts to life. This is what's typically referred to as the  WCF programming model.&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S1"&gt;WCF Programming Model&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;With WCF, you're either writing services that  expose endpoints or you're writing clients that interact with endpoints. Hence,  endpoints are central to the WCF programming model and infrastructure. WCF  models endpoints with the .NET classes and interfaces shown in &lt;strong&gt;Figure  3&lt;/strong&gt;. This mapping is true whether you're writing WCF clients or  services.&lt;/div&gt;&lt;span style="color: rgb(102, 102, 102);"&gt; &lt;div class="MTPS_CollapsibleRegion"&gt; &lt;div class="CollapseRegionLink" jquery1282990579218="3"&gt;&lt;!-- ApplyClick with current id --&gt;&lt;img class="LibC_o" style="border-width: 0px; vertical-align: middle;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" /&gt;  Figure 3 WCF Classes  and Interfaces &lt;/div&gt; &lt;div class="MTPS_CollapsibleSection" style="display: block;"&gt;&lt;br /&gt;&lt;table class="charttable"&gt; &lt;tbody&gt; &lt;tr valign="top"&gt; &lt;th&gt;Element&lt;/th&gt; &lt;th&gt;Class or Interface&lt;/th&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt;Endpoint &lt;/td&gt; &lt;td&gt;System.ServiceModel.ServiceEndpoint&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt;Address&lt;/td&gt; &lt;td&gt;System.Uri&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt;Binding&lt;/td&gt; &lt;td&gt;System.ServiceModel.Binding &lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt;Contract &lt;/td&gt; &lt;td&gt;Interfaces annotated with System.ServiceModel  attributes&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;When building a WCF service, you typically start by  defining a .NET interface definition to serve as the service contract. Then you  implement the service contract in a .NET class, known as the service type, and  configure its behavior. Next, you define the endpoints the service will expose,  specifying the address, binding, and contract for each one. Finally, you host  the service type in an application using the WCF hosting infrastructure. Once  the service type is hosted, clients can retrieve its endpoint descriptions and  begin integrating with it.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;When building a WCF client, you first need the  description of the target endpoint you want to access. The endpoint description  can be used to dynamically create a typed proxy. WCF provides a tool named  SvcUtil.exe for automating this process. Then you can write code against the  typed proxy to access the service by sending the appropriate messages to the  target endpoint.&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S2"&gt;Service Contracts and Dispatch Behavior&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;You model service contracts in .NET using  traditional C# interface definitions. You can use any .NET interface as a  starting point, such as the one shown here: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl06" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl06_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;  &lt;div class="CopyCodeButton"&gt;&lt;a title="&lt;span title=" click="" to="" correct="" class="copyCode" id="0"&gt;" href="javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl06_code');"&gt;    &lt;/a&gt;&lt;/div&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl06_code" space="preserve"&gt;namespace ServiceLibrary&lt;br /&gt;{&lt;br /&gt; public interface IEchoService&lt;br /&gt; {&lt;br /&gt;     string Echo(string msg);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;To make this a WCF service contract, you must annotate  the interface itself with [ServiceContract] and each operation you want to  expose with [OperationContract]: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl07" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl07_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;  &lt;div class="CopyCodeButton"&gt;&lt;a title="&lt;span title=" click="" to="" correct="" class="copyCode" id="6"&gt; href="javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl07_code');"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl07_code" space="preserve"&gt;using System.ServiceModel;&lt;br /&gt;&lt;br /&gt;namespace ServiceLibrary&lt;br /&gt;{&lt;br /&gt; [ServiceContract(Namespace="http://example.org/echo/")]&lt;br /&gt; public interface IEchoService&lt;br /&gt; {&lt;br /&gt;     [OperationContract]&lt;br /&gt;     string Echo(string msg);&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;These attributes influence the mapping between the  worlds of .NET and SOAP. WCF uses the information found in the service contract  to perform dispatching and serialization. Dispatching is the process of deciding  which method to call for an incoming SOAP message. Serialization is the process  of mapping between the data found in a SOAP message and the corresponding .NET  objects used in the method invocation. This mapping is controlled by an  operation's data contract.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;WCF dispatches based on the message action. Each  method in a service contract is automatically assigned an action value based on  the service namespace and method name. For example, the default action for the  Echo method just shown is http://example.org/echo/Echo. You can customize the  action value for each method using [OperationContract]. A value of * can be used  for any action when a specific match doesn't exist.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;In the following example, WCF will dispatch  messages with an action of urn:echo:string to the Echo method. Messages with any  other action are dispatched to the EchoMessage method: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl08" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl08_"&gt;  &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl08_code" space="preserve"&gt;[ServiceContract(Namespace="http://example.org/echo/")]&lt;br /&gt;public interface IEchoService&lt;br /&gt;{&lt;br /&gt; [OperationContract(Action="urn:echo:string")]&lt;br /&gt; string Echo(string msg);&lt;br /&gt;&lt;br /&gt; [OperationContract(Action="*")]&lt;br /&gt; Message EchoMessage(Message msg);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S3"&gt;Data Contracts&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Once the target method has been determined based on  the action, WCF relies on the method's data contract to perform serialization.  The data contract is defined by the types used in the method signature. In the  previous example, EchoMessage is generic and could be used to process a variety  of incoming SOAP messages. Therefore I've used Message to model the input and  output. Message is a special type used to represent all messages flowing through  WCF. When using Message, WCF does not perform type-based serialization. Instead,  it just gives you direct access to what's found in the SOAP message.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;When Message is not used, WCF performs  serialization to map between the data found in the SOAP message and the  corresponding .NET objects needed to invoke the method. For example, in the case  of Echo, WCF maps the SOAP payload to a .NET string. WCF provides an implicit  mapping for all .NET primitive types (string, int, double, and so on).&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;The way WCF serializes .NET classes depends on the  serialization engine in use. The default serialization engine is known as  DataContract, a simplified version of XmlSerializer, the default serialization  engine used in ASMX today. DataContract defines attributes for annotating class  definitions to influence the serialization process. Here's an example of it in  use: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl09" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl09_"&gt;  &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl09_code" space="preserve"&gt;[DataContract(Namespace="http://example.org/person")]&lt;br /&gt;public class Person&lt;br /&gt;{&lt;br /&gt; [DataMember(Name="first", Order=0)]&lt;br /&gt; public string First;&lt;br /&gt; [DataMember(Name="last", Order=1)]&lt;br /&gt; public string Last;&lt;br /&gt; [DataMember(IsRequired=false, Order=2)]&lt;br /&gt; private string id;&lt;br /&gt; ...&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;With DataContract, only fields marked with DataMember  will be serialized. And you can serialize private fields. This is much different  from the way XmlSerializer works. Now you can use Person in an operation  contract: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl10" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl10_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;  &lt;div class="CopyCodeButton"&gt;&lt;a title="&lt;span title=" click="" to="" correct="" class="copyCode" id="9"&gt;href="javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl10_code');"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl10_code" space="preserve"&gt;[ServiceContract(Namespace="http://example.org/echo/")]&lt;br /&gt;public interface IEchoService&lt;br /&gt;{&lt;br /&gt; ... // previous methods omitted&lt;br /&gt;&lt;br /&gt; [OperationContract]&lt;br /&gt; Person EchoPerson(Person p);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;When EchoPerson is invoked, WCF will serialize Person  instances according to the DataContract attributes specified on the Person  class. DataContract produces a very simple XML structure—a sequence of elements.  You can control the name of each element, the order, and whether a particular  element is required, but that's about it.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;If you need to do anything more sophisticated, WCF  lets you fall back to using XmlSerializer. You indicate your desire to use  XmlSerializer by annotating the interface with [XmlSerializerFormat]: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl11" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl11_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;  &lt;div class="CopyCodeButton"&gt;&lt;a title="&lt;span title=" click="" to="" correct="" class="copyCode" id="12"&gt;" href="javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl11_code');"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl11_code" space="preserve"&gt;[ServiceContract]&lt;br /&gt;[XmlSerializerFormat]&lt;br /&gt;public interface IEchoService { ... }&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;This tells WCF to use XmlSerializer for all types in  the contract, according to the XmlSerializer defaults and the various  System.Xml.Serialization customization attributes. This makes it much easier to  move existing ASMX services forward to WCF.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;WCF also supports serializing types marked with  [Serializable], which allows .NET remoting types to work with WCF without  change. WCF provides an implicit mapping for [Serializable] types where all  public/private fields are automatically serialized.&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S4"&gt;Message and Service Contracts&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;All of the examples up to this point have relied on  WCF to automatically map the method signature to the SOAP message. The parameter  list and return type are always mapped to the SOAP body for the request and  response, respectively. If you need to support headers, you can write another  class that models the structure of the entire SOAP envelope for the particular  operation, specifying which fields map to headers versus the body. You define  this mapping with the [MessageContract] attributes: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl12" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl12_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;  &lt;div class="CopyCodeButton"&gt;&lt;a title="&lt;span title=" click="" to="" correct="" class="copyCode" id="15"&gt;" href="javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl12_code');"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl12_code" space="preserve"&gt;[MessageContract]&lt;br /&gt;public class EchoPersonMessage&lt;br /&gt;{&lt;br /&gt; [MessageBody]&lt;br /&gt; public Person Person;&lt;br /&gt; [MessageHeader]&lt;br /&gt; public Authorization Authorization;&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;In this example, the Person field is mapped to the  SOAP body while the Authorization field is mapped to a SOAP header. Now you can  use EchoPersonMessage in an operation contract: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl13" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl13_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;  &lt;div class="CopyCodeButton"&gt;&lt;a title="&lt;span title=" click="" to="" correct="" class="copyCode" id="18"&gt;" href="javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl13_code');"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl13_code" space="preserve"&gt;[ServiceContract]&lt;br /&gt;public interface IEchoService&lt;br /&gt;{&lt;br /&gt; ... // previous methods omitted&lt;br /&gt;&lt;br /&gt; [OperationContract]&lt;br /&gt; void EchoPerson(EchoPersonMessage msg);&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;Using MessageContract is a more advanced technique that  is only necessary when you need direct control over the SOAP contract.&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S5"&gt;Implementing Service Contracts&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Now you can implement the service contract by  simply implementing the .NET interface in a class: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl14" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl14_"&gt;  &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl14_code" space="preserve"&gt;using System.ServiceModel;&lt;br /&gt;namespace ServiceLibrary&lt;br /&gt;{&lt;br /&gt; public class EchoService : IEchoService&lt;br /&gt; {&lt;br /&gt;     public string Echo(string msg)&lt;br /&gt;     {&lt;br /&gt;         return msg;&lt;br /&gt;     }&lt;br /&gt;     ... // remaining methods omitted&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;By doing this, EchoService is guaranteed to support the  service contract defined by IEchoService. When using an interface to define the  service contract, you don't need any contract-related attributes on the class  definition. However, you may want to use [ServiceBehavior] to influence its  local behavior:&lt;br /&gt;&lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl15" msxsl="urn:schemas-microsoft-com:xslt"&gt;&lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl15_"&gt;&lt;span style="text-decoration: underline;"&gt;&lt;/span&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl15_code" space="preserve"&gt;using System.ServiceModel;&lt;br /&gt;&lt;br /&gt;namespace ServiceLibrary&lt;br /&gt;{&lt;br /&gt; ... // interface definition omitted&lt;br /&gt;&lt;br /&gt; [ServiceBehavior(&lt;br /&gt;    InstanceContextMode=InstanceContextMode.Single,&lt;br /&gt;    ConcurrencyMode=ConcurrencyMode.Multiple)]&lt;br /&gt; public class EchoService : IEchoService&lt;br /&gt; {&lt;br /&gt;    ...&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;This particular example tells WCF to manage a  singleton instance of the service type and to allow multithreaded access to the  instance. There is also an [OperationBehavior] attribute for controlling  operation-level behavior.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Behaviors influence processing within the host, but  have no impact on the service contract whatsoever. Behaviors are one of the  primary WCF extensibility points. Any class that implements IServiceBehavior can  be applied to a service through the use of a custom attribute or configuration  element.&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S6"&gt;Hosting the Service and Defining  Endpoints&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;To use EchoService, you need to host it in a  .NET-based application. The ServiceHost class gives you direct control over the  WCF hosting infrastructure. You instantiate ServiceHost based on a particular  service type. The following code shows how to do this in a console application:  &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl16" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl16_"&gt;  &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl16_code" space="preserve"&gt;using System;&lt;br /&gt;using System.ServiceModel;&lt;br /&gt;using ServiceLibrary;&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt; static void Main(string[] args)&lt;br /&gt; {&lt;br /&gt;     using (ServiceHost host = new ServiceHost(&lt;br /&gt;         typeof(EchoService), new Uri("http://localhost:8080/echo")))&lt;br /&gt;     {&lt;br /&gt;         ...&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;In addition to specifying the service type, you  also specify the base addresses for the different transports you plan to use. In  this example, I've specified a base address of http://localhost:8080/echo. This  will be used as the base for any relative HTTP addresses I might specify when  adding endpoints. The base HTTP address is also used as the default for  retrieving the service description.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;You then add the service endpoints. Again, a  service may have one or more endpoints and each endpoint consists of an address,  a binding, and a contract. You provide this information to your ServiceHost by  calling AddServiceEndpoint. This is where you specify the service contract you  defined earlier (IEchoService). For the binding, you typically choose from one  of the many predefined bindings that ship with WCF and an appropriate address  given the binding's transport. Here's an example: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl17" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl17_"&gt;  &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl17_code" space="preserve"&gt;host.AddServiceEndpoint(typeof(IEchoService),&lt;br /&gt; new BasicHttpBinding(), "svc");&lt;br /&gt;host.AddServiceEndpoint(typeof(IEchoService),&lt;br /&gt; new NetTcpBinding(), "net.tcp://localhost:8081/echo/svc");&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;In this particular example, I've specified  IEchoService as the contract for both endpoints, but with each endpoint using a  different binding and address. The first endpoint uses the BasicHttpBinding and  a relative HTTP address of svc (which would make its absolute address  http://localhost:8080/echo/svc). The second endpoint uses the NetTcpBinding and  an address of net.tcp://localhost:8081/echo/svc. Therefore, this service allows  consumers to communicate with it over either HTTP or TCP using different WS-*  protocols, as defined by each binding.&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S7"&gt;Choosing and Customizing Bindings&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;The WCF infrastructure relies heavily on endpoint  definitions to control how messages are processed. In fact, WCF uses the  endpoint definitions to dynamically build the appropriate message processing  runtime within hosts and clients. The binding has the most significant influence  on this process.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;The binding controls three aspects of message  communication: the suite of WS-* protocols, including WS-Security,  WS-ReliableMessaging, and so on; the message encoding, such as XML 1.0, Message  Transmission Optimization Mechanism (MTOM), and binary; and the transport  protocol, including HTTP, TCP, and Microsoft Message Queuing (MSMQ). A given  binding specifies one message encoding and one transport, but it can specify  numerous WS-* protocols. Given that, there are an overwhelming number of  permutations that could be used. To simplify things, WCF provides a set of  predefined bindings that fit the most common use cases. &lt;strong&gt;Figure  4&lt;/strong&gt; lists some of these and describes what they embody.&lt;/div&gt;&lt;span style="color: rgb(102, 102, 102);"&gt; &lt;div class="MTPS_CollapsibleRegion"&gt; &lt;div class="CollapseRegionLink" jquery1282990579218="4"&gt;&lt;!-- ApplyClick with current id --&gt;&lt;img class="LibC_o" style="border-width: 0px; vertical-align: middle;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" /&gt;  Figure 4 Predefined  WCF Bindings &lt;/div&gt; &lt;div class="MTPS_CollapsibleSection" style="display: block;"&gt;&lt;br /&gt;&lt;table class="charttable"&gt; &lt;tbody&gt; &lt;tr valign="top"&gt; &lt;th&gt;Class Name&lt;/th&gt; &lt;th&gt;Element Name&lt;/th&gt; &lt;th&gt;Transport&lt;/th&gt; &lt;th&gt;Encoding&lt;/th&gt; &lt;th&gt;WS-* Protocols&lt;/th&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt;BasicHttpBinding &lt;/td&gt; &lt;td&gt;basicHttpBinding&lt;/td&gt; &lt;td&gt;HTTP&lt;/td&gt; &lt;td&gt;XML 1.0 &lt;/td&gt; &lt;td&gt;WS-I Basic Profile 1.1&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt;WSHttpBinding&lt;/td&gt; &lt;td&gt;wsHttpBinding&lt;/td&gt; &lt;td&gt;HTTP&lt;/td&gt; &lt;td&gt;XML 1.0&lt;/td&gt; &lt;td&gt;Message security, reliable sessions, and transactions&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt;WSDualHttpBinding&lt;/td&gt; &lt;td&gt;wsDualHttpBinding&lt;/td&gt; &lt;td&gt;HTTP&lt;/td&gt; &lt;td&gt;XML 1.0&lt;/td&gt; &lt;td&gt;Message security, reliable sessions, and transactions&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt;NetTcpBinding&lt;/td&gt; &lt;td&gt;netTcpBinding&lt;/td&gt; &lt;td&gt;TCP&lt;/td&gt; &lt;td&gt;Binary&lt;/td&gt; &lt;td&gt;Transport security, reliable sessions, and transactions&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt;NetNamedPipeBinding &lt;/td&gt; &lt;td&gt;netNamedPipeBinding&lt;/td&gt; &lt;td&gt;Named Pipes&lt;/td&gt; &lt;td&gt;Binary &lt;/td&gt; &lt;td&gt;Transport security, reliable sessions, and transactions&lt;/td&gt;&lt;/tr&gt; &lt;tr valign="top"&gt; &lt;td&gt;NetMsmqBinding &lt;/td&gt; &lt;td&gt;netMsmqBinding&lt;/td&gt; &lt;td&gt;MSMQ&lt;/td&gt; &lt;td&gt;Binary &lt;/td&gt; &lt;td&gt;Transport security and queue  transactions&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Developers who care primarily about  interoperability and don't need WS-* functionality will typically use  BasicHttpBinding. Developers who care about interoperability, but also need  message-based security, reliable messaging, and transactions will typically  choose WSHttpBinding. Developers using WCF on both sides (client and service)  can choose from NetTcpBinding and NetNamedPipeBinding, which provide significant  optimizations. Those building asynchronous systems can choose NetMsmqBinding.  There are also a few bindings that aren't listed here, such as  MsmqIntegrationBinding for integrating with existing MSMQ applications,  NetPeerTcpBinding for building peer-to-peer services, and WSFederationBinding  for federated security. A service can support any combination of these  bindings.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Once you choose a binding and instantiate it, you  can customize some of its characteristics through the properties exposed on the  binding class. The following example shows how to enable transport-based  security on the BasicHttpBinding: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl19" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl19_"&gt;  &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl19_code" space="preserve"&gt;BasicHttpBinding b = new BasicHttpBinding();&lt;br /&gt;b.Security.Mode = BasicHttpSecurityMode.Transport;&lt;br /&gt;b.Security.Transport.ClientCredentialType =&lt;br /&gt; HttpClientCredentialType.Basic;&lt;br /&gt;host.AddServiceEndpoint(typeof(IEchoService), b, "svc");&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;If the predefined bindings and their customizations  still don't fit your needs, you can also write a custom binding by implementing  a class that derives from Binding.&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S8"&gt;Opening the Host&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Now that you've configured the host with endpoint  information, WCF can build the runtime needed to support your configuration.  This occurs when you call Open on a particular ServiceHost: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl20" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl20_"&gt;  &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl20_code" space="preserve"&gt;host.Open();&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;Once the call to Open returns, the WCF runtime is built  and ready to receive messages at the addresses specified by each endpoint.  During this process, WCF generates an endpoint listener for each supplied  endpoint and the code needed to support the WS-* protocols specified by the  binding. (An endpoint listener is the piece of code that actually listens for  incoming messages using the specified transport and address.)&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;You can retrieve information about the service at  run time through the object model exposed by ServiceHost. This allows you to  retrieve anything you might want to know about the initialized service, such as  what endpoints it exposes and what endpoint listeners are currently  active.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;&lt;strong&gt;Figure 5&lt;/strong&gt; shows a complete example  of the console application that hosts EchoService. &lt;strong&gt;Figure 6&lt;/strong&gt;  shows the output. Notice there are two additional endpoint listener addresses  that I didn't specify in a ServiceEndpoint. WCF automatically provided these  using the base HTTP address for retrieving the service description.&lt;/div&gt;&lt;span style="color: rgb(102, 102, 102);"&gt; &lt;div class="MTPS_CollapsibleRegion"&gt; &lt;div class="CollapseRegionLink" jquery1282990579218="5"&gt;&lt;!-- ApplyClick with current id --&gt;&lt;img class="LibC_o" style="border-width: 0px; vertical-align: middle;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" /&gt;  Figure 5 Console App  Hosting EchoService &lt;/div&gt; &lt;div class="MTPS_CollapsibleSection" style="display: block;"&gt;&lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl60_ctl00_ctl00" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl60_ctl00_ctl00_"&gt;  &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl60_ctl00_ctl00_code" space="preserve"&gt;class Program&lt;br /&gt;{&lt;br /&gt; static void Main(string[] args)&lt;br /&gt; {&lt;br /&gt;     using (ServiceHost host = new ServiceHost(&lt;br /&gt;         typeof(EchoService), new Uri("http://localhost:8080/echo")))&lt;br /&gt;     {&lt;br /&gt;         // define the service endpoints&lt;br /&gt;         host.AddServiceEndpoint(typeof(IEchoService),&lt;br /&gt;             new BasicHttpBinding(), "svc");&lt;br /&gt;         host.AddServiceEndpoint(typeof(IEchoService),&lt;br /&gt;             new NetTcpBinding(), "net.tcp://localhost:8081/echo/svc");&lt;br /&gt;         host.Open();&lt;br /&gt;&lt;br /&gt;         Console.WriteLine(&lt;br /&gt;             "{0} is open and has the following endpoints:\n",&lt;br /&gt;             host.Description.ServiceType);&lt;br /&gt;&lt;br /&gt;         int i=1;&lt;br /&gt;         foreach (ServiceEndpoint end in host.Description.Endpoints)&lt;br /&gt;         {&lt;br /&gt;             Console.WriteLine("Endpoint #{0}", i++);&lt;br /&gt;             Console.WriteLine("Address: {0}",&lt;br /&gt;                 end.Address.Uri.AbsoluteUri);&lt;br /&gt;             Console.WriteLine("Binding: {0}",&lt;br /&gt;                 end.Binding.Name);&lt;br /&gt;             Console.WriteLine("Contract: {0}\n",&lt;br /&gt;                 end.Contract.Name);&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;         Console.WriteLine(&lt;br /&gt;             "The following EndpointListeners are active:\n");&lt;br /&gt;         foreach (EndpointListener l in host.EndpointListeners)&lt;br /&gt;             Console.WriteLine(l.Listener.Uri.AbsoluteUri);&lt;br /&gt;&lt;br /&gt;         // keep the process alive&lt;br /&gt;         Console.ReadLine();&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleImageSpacer"&gt;&lt;br /&gt;&lt;div class="ArticleImageCaptionText"&gt;Figure 6&lt;strong&gt; Output of Console  App &lt;/strong&gt;&lt;/div&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;If you browse to http://localhost:8080/echo, you'll  see the default WCF help page (see &lt;strong&gt;Figure 7&lt;/strong&gt;) and if you browse  to http://localhost:8080/echo?wsdl, you'll see the generated WSDL definition.  The other endpoint listener (http://localhost:8080/echo/mex) knows how to speak  WS-MetadataExchange. It's important to note that this sample is not using IIS in  any way. WCF provides built-in integration with httpsys, which allows any  application to automatically become an HTTP listener.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleImageSpacer"&gt;&lt;img style="width: 28px;" alt="" src="http://i.msdn.microsoft.com/cc163647.fig07%28en-us%29.gif" /&gt;  &lt;div class="ArticleImageCaptionText"&gt;Figure 7&lt;strong&gt; EchoService Help  Page &lt;/strong&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S9"&gt;Configuring Service Endpoints&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Hardcoding endpoint information into the host  application is not ideal since endpoint details may change over time. It's not  hard to imagine how you could store the endpoint information in a configuration  file or database and read it while initializing ServiceHost. Since this is a  common need, WCF automatically provides this functionality through the  predefined &lt;system.servicemodel&gt; configuration section.&lt;/system.servicemodel&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;The following configuration file defines the same  two endpoints that were specified by calling AddServiceEndpoint: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl25" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl25_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;  &lt;div class="CopyCodeButton"&gt;&lt;a title="&lt;span title=" click="" to="" correct="" class="copyCode" id="21"&gt;" href="javascript:CopyCode('ctl00_MTContentSelector1_mainContentContainer_ctl25_code');"&gt;  &lt;/a&gt;&lt;/div&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl25_code" space="preserve"&gt;&lt;configuration&gt;&lt;br /&gt;&lt;system.servicemodel&gt;&lt;br /&gt; &lt;services&gt;&lt;br /&gt;   &lt;service type="ServiceLibrary.EchoService"&gt;&lt;br /&gt;     &lt;endpoint address="svc" binding="basicHttpBinding" contract="ServiceLibrary.IEchoService"&gt;&lt;br /&gt;     &lt;endpoint address="net.tcp://localhost:8081/echo/svc" binding="netTcpBinding" contract="ServiceLibrary.IEchoService"&gt;&lt;br /&gt;   &lt;/endpoint&gt;&lt;br /&gt; &lt;/endpoint&gt;&lt;br /&gt;&lt;/service&gt;&lt;br /&gt;&lt;/services&gt;&lt;br /&gt;&lt;/system.servicemodel&gt;&lt;/configuration&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;If you add this configuration file to the host  application shown in &lt;strong&gt;Figure 5&lt;/strong&gt; and comment out the calls to  AddServiceEndpoint, you'll see the same results in the output. This increases  deployment flexibility since the communication details are completely factored  out of the compiled code. You can also configure bindings within  &lt;system.servicemodel&gt;. &lt;strong&gt;Figure 8&lt;/strong&gt; shows how to configure  basicHttpBinding to use transport security like I had done in code.&lt;/system.servicemodel&gt;&lt;/div&gt;&lt;span style="color: rgb(102, 102, 102);"&gt; &lt;div class="MTPS_CollapsibleRegion"&gt; &lt;div class="CollapseRegionLink" jquery1282990579218="6"&gt;&lt;!-- ApplyClick with current id --&gt;&lt;img class="LibC_o" style="border-width: 0px; vertical-align: middle;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" /&gt;  Figure 8 Configuring  Transport Security &lt;/div&gt; &lt;div class="MTPS_CollapsibleSection" style="display: block;"&gt;&lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl62_ctl00_ctl00" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl62_ctl00_ctl00_"&gt;  &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl62_ctl00_ctl00_code" space="preserve"&gt;&lt;configuration&gt;&lt;br /&gt;&lt;system.servicemodel&gt;&lt;br /&gt; &lt;services&gt;&lt;br /&gt;   &lt;service type="ServiceLibrary.EchoService"&gt;&lt;br /&gt;     &lt;endpoint address="https://localhost:8082/echo/svc" binding="basicHttpBinding" bindingconfiguration="MyBindingConfiguration" contract="ServiceLibrary.IEchoService"&gt;&lt;br /&gt;     ...&lt;br /&gt;   &lt;/endpoint&gt;&lt;br /&gt; &lt;/service&gt;&lt;br /&gt; &lt;bindings&gt;&lt;br /&gt;   &lt;basichttpbinding&gt;&lt;br /&gt;     &lt;binding name="MyBindingConfiguration"&gt;&lt;br /&gt;       &lt;security mode="Transport"&gt;&lt;br /&gt;         &lt;transport clientcredentialtype="Basic"&gt;&lt;br /&gt;       &lt;/transport&gt;&lt;br /&gt;     &lt;/security&gt;&lt;br /&gt;   &lt;/binding&gt;&lt;br /&gt; &lt;/basichttpbinding&gt;&lt;br /&gt;&lt;/bindings&gt;&lt;br /&gt;&lt;/services&gt;&lt;br /&gt;&lt;/system.servicemodel&gt;&lt;/configuration&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;You can even define new custom bindings from  scratch using the &lt;custombinding&gt; element, which would be equivalent to  deriving a new class from Binding. When it comes to configuring endpoints,  bindings, and even behaviors, anything you can do in code, you can also do  through configuration.&lt;/custombinding&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleImageSpacer"&gt;&lt;br /&gt;&lt;div class="ArticleImageCaptionText"&gt;Figure 9&lt;strong&gt; Using the GUI to Define an  Endpoint &lt;/strong&gt;&lt;/div&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Although IntelliSense&lt;span class="superscript"&gt;®&lt;/span&gt; for the configuration file works well in Visual  Studio&lt;span class="superscript"&gt;®&lt;/span&gt; 2005, some developers still prefer to  avoid XML altogether. The WinFX&lt;span class="superscript"&gt;®&lt;/span&gt; SDK includes a  tool called SvcConfigEditor, which provides a graphical interface for working  with the various &lt;system.servicemodel&gt; settings. &lt;strong&gt;Figure 9&lt;/strong&gt;  shows how to configure endpoints using this tool.&lt;/system.servicemodel&gt;&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S10"&gt;Using Activation Services&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Although I've been experimenting with console  applications, ServiceHost makes it easy to host WCF services in a variety of  applications, including Windows Forms applications and managed Windows Services.  In all of these application scenarios, you're responsible for managing the  process hosting WCF. This is known as self-hosting in WCF terms.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;In addition to self-hosting, WCF also makes it  possible to activate services by using IIS along with traditional Web hosting  techniques. You can accomplish this by using a .svc file (similar to .asmx) that  specifies the service type to host: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl29" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl29_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;&lt;br /&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl29_code" space="preserve"&gt;&lt;%@Service class="ServiceLibrary.EchoService" %&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;You place this file in a virtual directory and deploy  your service type to its \bin directory or the Global Assembly Cache (GAC). When  using this technique you specify the service endpoint in the web.config, but you  don't need to specify the address since it's implied by the location of the .svc  file. &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl30" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl30_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;&lt;br /&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl30_code" space="preserve"&gt;&lt;configuration&gt;&lt;br /&gt;&lt;system.servicemodel&gt;&lt;br /&gt; &lt;services&gt;&lt;br /&gt;   &lt;service type="ServiceLibrary.EchoService"&gt;&lt;br /&gt;     &lt;endpoint address="" binding="basicHttpBinding" contract="ServiceLibrary.IEchoService"&gt;&lt;br /&gt;   &lt;/endpoint&gt;&lt;br /&gt;   ...&lt;br /&gt;&lt;/service&gt;&lt;/services&gt;&lt;/system.servicemodel&gt;&lt;/configuration&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Now if you browse to the .svc file, you'll notice  the help page is displayed, showing that a ServiceHost was automatically created  within an ASP.NET application domain. This is accomplished by an HTTP module  that filters incoming .svc requests and automatically builds and opens the  appropriate ServiceHost when needed.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;If you install the WinFX extensions for Visual  Studio 2005, you'll find a new Web Site project template called Indigo Service  (this name will change). When you create a new Web site based on this template,  it automatically gives you the .svc file along with the corresponding  implementation class (found in App_Code). It also comes with a default endpoint  configuration in web.config.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;On IIS versions 5.1 and 6.0 the WCF activation  model is tied to the ASP.NET pipeline, and therefore to HTTP. IIS 7.0, which is  planned for release with Windows Vista&lt;span class="superscript"&gt;™&lt;/span&gt;,  introduces a transport-neutral activation mechanism known as Windows Activation  Services (WAS). With WAS, you'll be able to leverage .svc-like activation over  any transport.&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S11"&gt;Programming Clients&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Programming WCF clients involves sending messages  to a service endpoint according to its address, binding, and contract. To  accomplish this, you first create a ServiceEndpoint representing the target  endpoint. The following example shows how to create a ServiceEndpoint, based on  the service's HTTP endpoint, in a client console application: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl31" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl31_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;&lt;br /&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl31_code" space="preserve"&gt;using System;&lt;br /&gt;using System.ServiceModel;&lt;br /&gt;using ServiceLibrary;&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt; static void Main(string[] args)&lt;br /&gt; {&lt;br /&gt;     ServiceEndpoint httpEndpoint = new ServiceEndpoint(&lt;br /&gt;         ContractDescription.GetContract(typeof(IEchoService)),&lt;br /&gt;         new BasicHttpBinding(), new EndpointAddress(&lt;br /&gt;             "http://localhost:8080/echo/svc");&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;This code assumes that the client has access to the  same IEchoService interface definition that the service used and that the client  knows what binding and address to use. Then you can create a ChannelFactory  based on the ServiceEndpoint: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl32" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl32_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;&lt;br /&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl32_code" space="preserve"&gt;ChannelFactory&lt;iechoservice&gt; factory =&lt;br /&gt; new ChannelFactory&lt;iechoservice&gt;(httpEndpoint);&lt;br /&gt;&lt;/iechoservice&gt;&lt;/iechoservice&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;ChannelFactory creates typed proxies. In this case, it  creates proxies of type IEchoService, which you can use to invoke the operations  defined by the contract: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl33" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl33_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;&lt;br /&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl33_code" space="preserve"&gt;IEchoService svc = factory.CreateChannel();&lt;br /&gt;Console.WriteLine(svc.Echo("Hello, world"));&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;If the service requires a customized binding, you  will need to create the binding and customize it before creating  ServiceEndpoint. If you want to access the TCP endpoint, simply create another  ServiceEndpoint specifying the TCP endpoint details and supply it to  ChannelFactory instead of the HTTP endpoint. Everything else would work the  same.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;The proxy shields you from the different addresses  and bindings in use, allowing you to write application code against the service  contract. &lt;strong&gt;Figure 10&lt;/strong&gt; shows the complete client console  application.&lt;/div&gt;&lt;span style="color: rgb(102, 102, 102);"&gt; &lt;div class="MTPS_CollapsibleRegion"&gt; &lt;div class="CollapseRegionLink" jquery1282990579218="7"&gt;&lt;!-- ApplyClick with current id --&gt;&lt;img class="LibC_o" style="border-width: 0px; vertical-align: middle;" src="http://i.msdn.microsoft.com/Global/Images/clear.gif" /&gt;   Figure 10 EchoService Client App &lt;/div&gt; &lt;div class="MTPS_CollapsibleSection" style="display: block;"&gt;&lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl68_ctl00_ctl00" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl68_ctl00_ctl00_"&gt;  &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl68_ctl00_ctl00_code" space="preserve"&gt;using System; &lt;br /&gt;using System.ServiceModel;&lt;br /&gt;using ServiceLibrary;&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;{&lt;br /&gt; static void Main(string[] args)&lt;br /&gt; {&lt;br /&gt;     try&lt;br /&gt;     {&lt;br /&gt;         // define service endpoints on client&lt;br /&gt;         ServiceEndpoint httpEndpoint = new ServiceEndpoint(&lt;br /&gt;             ContractDescription.GetContract(&lt;br /&gt;                typeof(IEchoService)),new BasicHttpBinding(),&lt;br /&gt;             new EndpointAddress("http://localhost:8080/echo/svc"));&lt;br /&gt;&lt;br /&gt;         ServiceEndpoint tcpEndpoint= new ServiceEndpoint(&lt;br /&gt;             ContractDescription.GetContract(&lt;br /&gt;                typeof(IEchoService)),&lt;br /&gt;             new NetTcpBinding(), new EndpointAddress(&lt;br /&gt;                "net.tcp://localhost:8081/echo/svc"));&lt;br /&gt;&lt;br /&gt;         IEchoService svc = null;&lt;br /&gt;&lt;br /&gt;         // create channel factory based on HTTP endpoint&lt;br /&gt;         using (ChannelFactory&lt;iechoservice&gt; httpFactory =&lt;br /&gt;             new ChannelFactory&lt;iechoservice&gt;(httpEndpoint))&lt;br /&gt;         {&lt;br /&gt;             // create channel proxy for endpoint&lt;br /&gt;             svc = httpFactory.CreateChannel();&lt;br /&gt;             // invoke service operation&lt;br /&gt;             Console.WriteLine("Invoking HTTP endpoint: {0}",&lt;br /&gt;                 svc.Echo("Hello, world"));&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;         // create channel factory based on TCP endpoint&lt;br /&gt;         using (ChannelFactory&lt;iechoservice&gt; tcpFactory =&lt;br /&gt;             new ChannelFactory&lt;iechoservice&gt;(tcpEndpoint))&lt;br /&gt;         {&lt;br /&gt;             // create channel proxy for endpoint&lt;br /&gt;             svc = tcpFactory.CreateChannel();&lt;br /&gt;             // invoke service operation&lt;br /&gt;             Console.WriteLine("Invoking TCP endpoint: {0}",&lt;br /&gt;                 svc.Echo("Hello, world"));&lt;br /&gt;         }&lt;br /&gt;     }&lt;br /&gt;     catch (Exception e)&lt;br /&gt;     {&lt;br /&gt;         Console.WriteLine(e);&lt;br /&gt;     }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/iechoservice&gt;&lt;/iechoservice&gt;&lt;/iechoservice&gt;&lt;/iechoservice&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S12"&gt;Configuring Client Endpoints&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Hardcoding endpoint information into client code is  also less than ideal. So WCF provides a similar configuration mechanism for  specifying client endpoints within &lt;system.servicemodel&gt;. The following  application configuration file specifies the same client endpoint details used  in the code: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl36" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl36_"&gt;  &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl36_code" space="preserve"&gt;&lt;configuration&gt;&lt;br /&gt;&lt;system.servicemodel&gt;&lt;br /&gt; &lt;client&gt;&lt;br /&gt;   &lt;endpoint name="httpEndpoint" address="http://localhost:8080/echo/svc" binding="basicHttpBinding" contract="ServiceLibrary.IEchoService"&gt;&lt;br /&gt;   &lt;endpoint name="tcpEndpoint" address="net.tcp://localhost:8081/echo/svc" binding="netTcpBinding" contract="ServiceLibrary.IEchoService"&gt;&lt;br /&gt; &lt;/endpoint&gt;&lt;br /&gt;&lt;/endpoint&gt;&lt;br /&gt;&lt;/client&gt;&lt;br /&gt;&lt;/system.servicemodel&gt;&lt;/configuration&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/system.servicemodel&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Notice that I've given each client endpoint a name.  You can use this name in your code when creating a ChannelFactory, as  illustrated in the following code: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl37" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl37_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;&lt;br /&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl37_code" space="preserve"&gt;using (ChannelFactory&lt;iechoservice&gt; httpFactory =&lt;br /&gt; new ChannelFactory&lt;iechoservice&gt;("httpEndpoint"))&lt;br /&gt;{&lt;br /&gt; svc = httpFactory.CreateChannel();&lt;br /&gt; Console.WriteLine("Invoking HTTP endpoint: {0}",&lt;br /&gt;     svc.Echo("Hello, world"));&lt;br /&gt;}&lt;br /&gt;&lt;/iechoservice&gt;&lt;/iechoservice&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;Now when you want to create a ChannelFactory for the  TCP endpoint, you can simply change the configuration name to tcpEndpoint. You  can also configure bindings in the client configuration file just like I did in  the service configuration file.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;If you add this configuration file to the client  console application shown in &lt;strong&gt;Figure 10&lt;/strong&gt;, comment out the code to  create the ServiceEndpoint objects, and specify the endpoint names when  constructing each ChannelFactory, the result will be the same.&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S13"&gt;Generating Client Proxies&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;The preceding examples assumed the client had  access to the same interface definition used to implement the service. This is  common when .NET is used to implement both sides (in traditional .NET remoting  scenarios), but that's not always the case, and it's never the case when the  service wasn't implemented with the .NET Framework. The preceding examples also  assumed the client knew the precise endpoint details in advance, which isn't  always common either.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;When clients don't have access to such information,  they can discover it using the WS-MetadataExchange specification. Services share  endpoint descriptions with clients through WSDL definitions. Most service  platforms provide tools for generating client-side code from WSDL definitions.  The WinFX SDK provides SvcUtil.exe for this purpose.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;When executing SvcUtil.exe, you specify the URL of  the WSDL definition and it will generate the necessary .NET code and  configuration elements that define the endpoints and bindings used by the  service endpoints. &lt;strong&gt;Figure 11&lt;/strong&gt; shows the output of running  SvcUtil.exe against http://localhost:8080/echo. Notice that it generates two  files: EchoService.cs and output.config.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleImageSpacer"&gt;&lt;br /&gt;&lt;div class="ArticleImageCaptionText"&gt;Figure 11&lt;strong&gt; SvcUtil.exe  Output &lt;/strong&gt;&lt;/div&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;EchoService.cs contains a .NET interface definition  equivalent to the one the service implemented. Output.config contains the client  endpoint information needed to access the service (similar to what I just wrote  manually). You'll need to merge the contents of output.config with your  application configuration file manually. With this in place, you can write  client code using the same techniques shown in the previous examples, only using  the generated interface and configuration file.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;In general, the WCF client programming model is  explicit about the service boundary. You create a typed channel against a  specific service endpoint and then send messages through it. Although this helps  emphasize the tenets of service orientation, it can be tedious to work at this  level all the time. To help you, SvcUtil.exe also generates a proxy class that  completely hides the ChannelFactory and ServiceEndpoint creation details. If you  open EchoService.cs, you'll find the following class definition: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl39" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl39_"&gt; &lt;div class="CodeSnippetTitleBar"&gt;&lt;br /&gt;&lt;/div&gt; &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl39_code" space="preserve"&gt;public partial class EchoServiceProxy :&lt;br /&gt;System.ServiceModel.ClientBase&lt;iechoservice&gt;, IEchoService&lt;br /&gt;{&lt;br /&gt; public EchoServiceProxy()&lt;br /&gt; {&lt;br /&gt; } &lt;br /&gt; public EchoServiceProxy(string endpointConfigurationName) :&lt;br /&gt;         base(endpointConfigurationName)&lt;br /&gt; {&lt;br /&gt; }&lt;br /&gt;...&lt;br /&gt;&lt;/iechoservice&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;This proxy class can simplify your client  application code. All you have to do is instantiate the proxy, specify the name  of the endpoint configuration, and make method calls. Here's an example: &lt;span id="ctl00_MTContentSelector1_mainContentContainer_ctl40" msxsl="urn:schemas-microsoft-com:xslt"&gt; &lt;div class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl40_"&gt;  &lt;div dir="ltr" style="background-color: rgb(221, 221, 221);"&gt;&lt;pre class="libCScode" id="ctl00_MTContentSelector1_mainContentContainer_ctl40_code" space="preserve"&gt;using (EchoServiceProxy proxy = new EchoServiceProxy("IEchoService"))&lt;br /&gt;{&lt;br /&gt; // invoke service operation&lt;br /&gt; Console.WriteLine("Invoking HTTP endpoint: {0}",&lt;br /&gt;     proxy.Echo("Hello, world"));&lt;br /&gt;}&lt;br /&gt;using (EchoServiceProxy proxy = new EchoServiceProxy("IEchoService1"))&lt;br /&gt;{&lt;br /&gt; // invoke service operation&lt;br /&gt; Console.WriteLine("Invoking TCP endpoint: {0}",&lt;br /&gt;     proxy.Echo("Hello, world"));&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;The generated configuration file (output.config)  defines the IEchoService and IEchoService1 endpoint configurations.&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S14"&gt;Logging Messages&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;As you begin working with the WCF programming  model, you may find it useful to trace the SOAP messages traveling between  clients and services. Windows Communication Foundation provides built-in support  for message logging, which can be turned on through your application  configuration file.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleImageSpacer"&gt;&lt;br /&gt;&lt;div class="ArticleImageCaptionText"&gt;Figure  12&lt;strong&gt; SvcTraceViewer.exe &lt;/strong&gt;&lt;/div&gt;&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;SvcConfigEditor provides a Diagnostics tab where  you can enable the messaging logging features. Once you enable messaging logging  and rerun the app, you'll see the trace file appear in the specified location.  The WinFX SDK also provides SvcTraceViewer.exe for viewing the information in a  trace file (see &lt;strong&gt;Figure 12&lt;/strong&gt;).&lt;/div&gt;&lt;br /&gt;&lt;div style="color: rgb(102, 102, 102);" class="ArticleTypeTitle" id="S15"&gt;Conclusion&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;WCF is a new step in distributed programming for  developers using the .NET Framework. If you currently build systems using any of  today's .NET distributed technologies, it's time to start paying attention to  WCF and the future it holds. It's only a matter of time before all .NET-targeted  code related to communications will be written using WCF.&lt;/div&gt; &lt;div style="color: rgb(102, 102, 102);" class="ArticleNormalPara"&gt;Note that all of the code samples shown in this  article are based on Visual Studio 2005 and the WCF November 2005 CTP.&lt;br /&gt;&lt;br /&gt;Refer to link: http://msdn.microsoft.com/hi-in/magazine/cc163647(en-us).aspx&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/3068650074752359005-8449035499622209863?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/8449035499622209863/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=8449035499622209863' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/8449035499622209863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/8449035499622209863'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2010/08/windows-communication-foundation-wcf.html' title=''/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-3142814590102481160</id><published>2009-07-02T03:37:00.000-07:00</published><updated>2009-07-02T03:41:01.806-07:00</updated><title type='text'>LINQ To SQL</title><content type='html'>&lt;h2&gt;Introduction &lt;/h2&gt; &lt;p&gt;&lt;a href="http://msdn2.microsoft.com/en-us/netframework/aa904594.aspx"&gt;LINQ&lt;/a&gt; is  one of the most important features in .NET Framework 3.5 (Visual Studio 2008).  It's the new way to mapping database tables to classes, and as we know, we call  this &lt;a href="http://en.wikipedia.org/wiki/Object-relational_mapping"&gt;O/R  Mapping&lt;/a&gt;. An article on how to write LINQ code quickly is always welcome for  beginners, and I think that reading samples is the best way to learn a new  technique.&lt;/p&gt; &lt;p&gt;These are samples created while I was learning and using LINQ, and I want to  share them now. Hope they will be helpful. I will use Northwind database as a  sample, which you can download from the link at the top of this article.&lt;/p&gt; &lt;p&gt;I recommend that you read &lt;a href="http://msdn2.microsoft.com/en-us/vcsharp/aa336746.aspx"&gt;101 LINQ  Samples&lt;/a&gt; if you would like to learn more.&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;// Basic    &lt;br /&gt;// &lt;span class="code-keyword"&gt;Select&lt;/span&gt; * &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products     &lt;br /&gt;var query1 = &lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products                  &lt;span class="code-keyword"&gt;select&lt;/span&gt; p;    &lt;br /&gt;// &lt;span class="code-keyword"&gt;Select&lt;/span&gt; ProductID, ProductName, UnitPrice &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products&lt;br /&gt; var query2 = &lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products                  &lt;span class="code-keyword"&gt;select&lt;/span&gt; new&lt;br /&gt; {&lt;br /&gt; p.ProductID,                      p.ProductName,                      p.UnitPrice&lt;br /&gt;                };&lt;br /&gt;&lt;br /&gt;Note: &lt;code&gt;query2&lt;/code&gt; will create a new class which contains three  properties that map the &lt;code&gt;ProductId&lt;/code&gt;, &lt;code&gt;ProductName&lt;/code&gt;, and  &lt;code&gt;UnitPrice&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;// &lt;span class="code-keyword"&gt;Where&lt;/span&gt;     // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; * &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products &lt;span class="code-keyword"&gt;Where&lt;/span&gt; ProductID = &lt;span class="code-digit"&gt;1&lt;/span&gt;    &lt;br /&gt;var query3 = &lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products                  &lt;span class="code-keyword"&gt;where&lt;/span&gt; p.ProductID == &lt;span class="code-digit"&gt;1&lt;/span&gt;                  &lt;span class="code-keyword"&gt;select&lt;/span&gt; p;&lt;br /&gt;&lt;br /&gt;    // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; * &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products &lt;span class="code-keyword"&gt;Where&lt;/span&gt; SupplierId =5 &lt;span class="code-keyword"&gt;and&lt;/span&gt; UnitPrice &gt; &lt;span class="code-digit"&gt;20&lt;/span&gt;&lt;br /&gt; var query4 = &lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products                  &lt;span class="code-keyword"&gt;where&lt;/span&gt; p.SupplierID == &lt;span class="code-digit"&gt;5&lt;/span&gt; &amp;amp;&amp;amp; p.UnitPrice &gt; &lt;span class="code-digit"&gt;20&lt;/span&gt;                  &lt;span class="code-keyword"&gt;select&lt;/span&gt; p;      &lt;br /&gt;&lt;br /&gt;// &lt;span class="code-keyword"&gt;Select&lt;/span&gt; * &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products &lt;span class="code-keyword"&gt;Where&lt;/span&gt; SupplierId =5 &lt;span class="code-keyword"&gt;Or&lt;/span&gt; SupplierId=6&lt;br /&gt;    var query5 = &lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products                  &lt;span class="code-keyword"&gt;where&lt;/span&gt; p.SupplierID == &lt;span class="code-digit"&gt;5&lt;/span&gt; || p.SupplierID == &lt;span class="code-digit"&gt;6&lt;/span&gt;                  &lt;span class="code-keyword"&gt;select&lt;/span&gt; p;&lt;br /&gt;&lt;br /&gt;Note: The condition in the &lt;code&gt;where&lt;/code&gt; block is a logical express, a  boolean value is returned just like in &lt;code&gt;&lt;span class="code-keyword"&gt;if&lt;/span&gt;()&lt;/code&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre id="pre2" style="margin-top: 0px;" lang="sql"&gt;// &lt;span class="code-keyword"&gt;Order&lt;/span&gt; &lt;span class="code-keyword"&gt;By&lt;/span&gt;&lt;br /&gt;   // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; * &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products &lt;span class="code-keyword"&gt;Order&lt;/span&gt; &lt;span class="code-keyword"&gt;By&lt;/span&gt; ProductId&lt;br /&gt;   var query6 = &lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                orderby p.ProductID&lt;br /&gt;                &lt;span class="code-keyword"&gt;select&lt;/span&gt; p;&lt;br /&gt;&lt;br /&gt;   // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; * &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products &lt;span class="code-keyword"&gt;Order&lt;/span&gt; &lt;span class="code-keyword"&gt;By&lt;/span&gt; ProductId &lt;span class="code-keyword"&gt;Desc&lt;/span&gt;&lt;br /&gt;   var query7 = &lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                orderby p.ProductID descending&lt;br /&gt;                &lt;span class="code-keyword"&gt;select&lt;/span&gt; p;&lt;br /&gt;&lt;br /&gt;   // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; * &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products &lt;span class="code-keyword"&gt;Order&lt;/span&gt; &lt;span class="code-keyword"&gt;By&lt;/span&gt; CategoryId, UnitPrice &lt;span class="code-keyword"&gt;Desc&lt;/span&gt;&lt;br /&gt;   var query8 = &lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                orderby p.CategoryID, p.UnitPrice descending&lt;br /&gt;                &lt;span class="code-keyword"&gt;select&lt;/span&gt; p;&lt;/pre&gt; &lt;p&gt;Note: The default order is &lt;code&gt;ascending&lt;/code&gt;, the &lt;code&gt;order by  p.ProductID&lt;/code&gt; is same as &lt;code&gt;order by p.ProductID ascending&lt;/code&gt;, just  like in T-SQL.&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre id="pre3" style="margin-top: 0px;" lang="sql"&gt;// &lt;span class="code-keyword"&gt;Top&lt;/span&gt;&lt;br /&gt;   // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; &lt;span class="code-keyword"&gt;Top&lt;/span&gt; &lt;span class="code-digit"&gt;10&lt;/span&gt; * &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products&lt;br /&gt;   var query9 = (&lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                &lt;span class="code-keyword"&gt;select&lt;/span&gt; p).Take(&lt;span class="code-digit"&gt;10&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;   // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; &lt;span class="code-keyword"&gt;Top&lt;/span&gt; &lt;span class="code-digit"&gt;1&lt;/span&gt; * &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products&lt;br /&gt;   var query10 = (&lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                  &lt;span class="code-keyword"&gt;select&lt;/span&gt; p).Take(&lt;span class="code-digit"&gt;1&lt;/span&gt;);&lt;br /&gt;   // &lt;span class="code-keyword"&gt;or&lt;/span&gt;&lt;br /&gt;   var query11 = (&lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                  &lt;span class="code-keyword"&gt;select&lt;/span&gt; p).First();&lt;/pre&gt; &lt;p&gt;Note: If it just returns one record, I recommend using &lt;code&gt;First&lt;/code&gt;  instead of &lt;code&gt;Take(&lt;span class="code-digit"&gt;1&lt;/span&gt;)&lt;/code&gt;.&lt;br /&gt;&lt;/p&gt;&lt;pre id="pre4" style="margin-top: 0px;" lang="sql"&gt;// &lt;span class="code-keyword"&gt;Top&lt;/span&gt; &lt;span class="code-keyword"&gt;with&lt;/span&gt; &lt;span class="code-keyword"&gt;Order&lt;/span&gt; &lt;span class="code-keyword"&gt;By&lt;/span&gt;&lt;br /&gt;   // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; &lt;span class="code-keyword"&gt;Top&lt;/span&gt; &lt;span class="code-digit"&gt;10&lt;/span&gt; * &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products &lt;span class="code-keyword"&gt;Order&lt;/span&gt; &lt;span class="code-keyword"&gt;By&lt;/span&gt; ProductId&lt;br /&gt;   var query12 = (&lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                  orderby p.ProductID&lt;br /&gt;                  &lt;span class="code-keyword"&gt;select&lt;/span&gt; p).Take(&lt;span class="code-digit"&gt;10&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;// &lt;span class="code-keyword"&gt;Distinct&lt;/span&gt;&lt;br /&gt;   // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; &lt;span class="code-keyword"&gt;Distinct&lt;/span&gt; CategoryId &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products&lt;br /&gt;   var query13 = (&lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                  &lt;span class="code-keyword"&gt;select&lt;/span&gt; p.CategoryID).&lt;span class="code-keyword"&gt;Distinct&lt;/span&gt;();&lt;br /&gt;&lt;br /&gt;// &lt;span class="code-keyword"&gt;Group&lt;/span&gt; &lt;span class="code-keyword"&gt;By&lt;/span&gt;&lt;br /&gt;   // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; CategoryId, Count(CategoryID) &lt;span class="code-keyword"&gt;As&lt;/span&gt; NewField&lt;br /&gt;   // &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products &lt;span class="code-keyword"&gt;Group&lt;/span&gt; &lt;span class="code-keyword"&gt;By&lt;/span&gt; CategoryId&lt;br /&gt;   var query14 = &lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                 &lt;span class="code-keyword"&gt;group&lt;/span&gt; p &lt;span class="code-keyword"&gt;by&lt;/span&gt; p.CategoryID &lt;span class="code-keyword"&gt;into&lt;/span&gt; g&lt;br /&gt;                 &lt;span class="code-keyword"&gt;select&lt;/span&gt; new {&lt;br /&gt;                     CategoryId = g.&lt;span class="code-keyword"&gt;Key&lt;/span&gt;,&lt;br /&gt;                     NewField = g.Count()&lt;br /&gt;                 };&lt;br /&gt;&lt;br /&gt;   // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; CategoryId, Avg(UnitPrice) &lt;span class="code-keyword"&gt;As&lt;/span&gt; NewField &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products &lt;span class="code-keyword"&gt;Group&lt;/span&gt; &lt;span class="code-keyword"&gt;By&lt;/span&gt; CategoryId&lt;br /&gt;   var query15 = &lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                 &lt;span class="code-keyword"&gt;group&lt;/span&gt; p &lt;span class="code-keyword"&gt;by&lt;/span&gt; p.CategoryID &lt;span class="code-keyword"&gt;into&lt;/span&gt; g&lt;br /&gt;                 &lt;span class="code-keyword"&gt;select&lt;/span&gt; new {&lt;br /&gt;                     CategoryId = g.&lt;span class="code-keyword"&gt;Key&lt;/span&gt;,&lt;br /&gt;                     NewField = g.Average(k =&gt; k.UnitPrice)&lt;br /&gt;                 };&lt;br /&gt;&lt;br /&gt;   // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; CategoryId, Sum(UnitPrice) &lt;span class="code-keyword"&gt;As&lt;/span&gt; NewField &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products &lt;span class="code-keyword"&gt;Group&lt;/span&gt; &lt;span class="code-keyword"&gt;By&lt;/span&gt; CategoryId&lt;br /&gt;   var query16 = &lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                 &lt;span class="code-keyword"&gt;group&lt;/span&gt; p &lt;span class="code-keyword"&gt;by&lt;/span&gt; p.CategoryID &lt;span class="code-keyword"&gt;into&lt;/span&gt; g&lt;br /&gt;                 &lt;span class="code-keyword"&gt;select&lt;/span&gt; new {&lt;br /&gt;                     CategoryId = g.&lt;span class="code-keyword"&gt;Key&lt;/span&gt;,&lt;br /&gt;                     NewField = g.Sum(k =&gt; k.UnitPrice )&lt;br /&gt;                 };&lt;br /&gt;&lt;br /&gt;// &lt;span class="code-keyword"&gt;Union&lt;/span&gt;&lt;br /&gt;   // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; * &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products &lt;span class="code-keyword"&gt;Where&lt;/span&gt; CategoryId =1 &lt;span class="code-keyword"&gt;union&lt;/span&gt; &lt;span class="code-keyword"&gt;Select&lt;/span&gt; *&lt;br /&gt;   // &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products &lt;span class="code-keyword"&gt;Where&lt;/span&gt; CategoryId = &lt;span class="code-digit"&gt;2&lt;/span&gt;&lt;br /&gt;   var query17 = (&lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                  &lt;span class="code-keyword"&gt;where&lt;/span&gt; p.CategoryID == &lt;span class="code-digit"&gt;1&lt;/span&gt;&lt;br /&gt;                  &lt;span class="code-keyword"&gt;select&lt;/span&gt; p).&lt;span class="code-keyword"&gt;Union&lt;/span&gt;(&lt;br /&gt;                      &lt;span class="code-keyword"&gt;from&lt;/span&gt; m &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                      &lt;span class="code-keyword"&gt;where&lt;/span&gt; m.CategoryID == &lt;span class="code-digit"&gt;2&lt;/span&gt;&lt;br /&gt;                      &lt;span class="code-keyword"&gt;select&lt;/span&gt; m&lt;br /&gt;                  );&lt;br /&gt;&lt;br /&gt;// Two tables&lt;br /&gt;   // &lt;span class="code-keyword"&gt;Select&lt;/span&gt; A.ProductId, A.ProductName, B.CategoryId, B.CategoryName&lt;br /&gt;   // &lt;span class="code-keyword"&gt;From&lt;/span&gt; Products A, Categories B&lt;br /&gt;   //    &lt;span class="code-keyword"&gt;Where&lt;/span&gt; A.CategoryID = B.CategoryID &lt;span class="code-keyword"&gt;and&lt;/span&gt; A.SupplierId =1&lt;br /&gt;   var query18 = &lt;span class="code-keyword"&gt;from&lt;/span&gt; p &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Products&lt;br /&gt;                 &lt;span class="code-keyword"&gt;from&lt;/span&gt; m &lt;span class="code-keyword"&gt;in&lt;/span&gt; db.Categories&lt;br /&gt;                 &lt;span class="code-keyword"&gt;where&lt;/span&gt; p.CategoryID == m.CategoryID &amp;amp;&amp;amp; p.SupplierID == &lt;span class="code-digit"&gt;1&lt;/span&gt;&lt;br /&gt;                 &lt;span class="code-keyword"&gt;select&lt;/span&gt; new {&lt;br /&gt;                     p.ProductID,&lt;br /&gt;                     p.ProductName,&lt;br /&gt;                     m.CategoryID,&lt;br /&gt;                     m.CategoryName&lt;br /&gt;                 };&lt;/pre&gt; &lt;h2&gt;&lt;br /&gt;&lt;/h2&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-3142814590102481160?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/3142814590102481160/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=3142814590102481160' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/3142814590102481160'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/3142814590102481160'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2009/07/linq-to-sql.html' title='LINQ To SQL'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-1452903721425649576</id><published>2009-07-02T03:30:00.000-07:00</published><updated>2009-07-02T03:37:07.488-07:00</updated><title type='text'>Language Integrated Query (LINQ) to SQL</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Introducing LINQ to Relational Data&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;LINQ introduced the concept of a unified data access technique to eliminate challenges of accessing data from a disparity of sources. LINQ has been extended to include the ability to access relational data through LINQ to SQL and LINQ to Entities. LINQ to SQL offers a direct mapping to the Microsoft SQL Server family of databases and allows you to query and manipulate objects associated with database tables. LINQ to Entities offers a more flexible mapping to relational data stored in other databases beyond just SQL Server. You build against a conceptual schema that is mapped to an actual schema. The remainder of this article will concentrate on LINQ to SQL.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;LINQ to SQL Object Model&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;a name="more"&gt;LINQ to SQL allows you to query and manipulate objects associated with database  tables. Creating an object model involves creating a typed object that  represents the database connection along with classes that map to database  entities. The following list of objects are involved:  &lt;/a&gt;&lt;ul&gt;&lt;li&gt;&lt;a name="more"&gt;&lt;b&gt;DataContext&lt;/b&gt; - A base class that is a disposable type that gets  extended to represent a strongly typed connection to the database.  &lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a name="more"&gt;&lt;b&gt;Classes and Collections&lt;/b&gt; - Represent objects and collection of objects  that map to database entities.  &lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a name="more"&gt;&lt;b&gt;Methods&lt;/b&gt; - Are used to extend classes or to represent stored procedure  calls. &lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;a name="more"&gt;There are a few different ways to create an object model. The two most  straight forward approaches are to use the provided designer within Visual  Studio 2008 to auto-generate the objects and mappings or adding attributes to  existing objects. For this example I downloaded the &lt;/a&gt;&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=06616212-0356-46A0-8DA2-EEBC53A68034&amp;amp;displaylang=en"&gt;Northwind  sample database&lt;/a&gt; and loaded it in my SQL Server so that I could retrieve data  from it for testing. I created a new solution and added a console application. I  then added a LINQ to SQL data class to the console application. I used the  Server Explorer to setup a new connection to the Northwind database my local SQL  Server, and then dragged all of the tables from the Server Explorer on to the  design surface for the data class. Finally I right clicked on the design surface  and chose "Layout Diagram" to auto arrange all of the newly added tables and  relationships. Refer to Figure 1 for an example of the completed design surface&lt;/p&gt;&lt;br /&gt;&lt;h3&gt;Test Driving LINQ to SQL through Examples&lt;/h3&gt;Now that we've covered the  background let's use a couple of examples of LINQ to SQL. Our examples will  demonstrate the use of the DataContext object along with an example of querying  the Northwind sample database using expressions.  &lt;h3&gt;Querying Data&lt;/h3&gt;The following example code uses LINQ syntax to query data  from the database and then loop through it to print it to the console. You'll  notice how the query expression syntax is the same as what you would find  whether it be LINQ to XML or another form of LINQ. Also notice how the  NorthwindDataClassesDataContext object is wrapped within a using construct.  &lt;code&gt;The NorthwindDataClassesDataContext&lt;/code&gt; is an object that extends the  DataContext class and represents a strongly typed connection to our database.  The &lt;code&gt;NorthwindDataClassesDataContext&lt;/code&gt; is a disposable type, so  wrapping it in a using block ensures it is properly disposed after use.&lt;br /&gt;&lt;br /&gt;&lt;span class="codeKeyword"&gt;using&lt;/span&gt; (NorthwindDataClassesDataContext context =   &lt;span class="codeKeyword"&gt;new&lt;/span&gt; NorthwindDataClassesDataContext())   {  &lt;br /&gt;var results = from customers &lt;span class="codeKeyword"&gt;in&lt;/span&gt; context.Customers                      where customers.City == "London"                      orderby customers.CompanyName                      select customers;&lt;br /&gt; &lt;span class="codeKeyword"&gt;foreach&lt;/span&gt; (var customer &lt;span class="codeKeyword"&gt;in&lt;/span&gt; results)&lt;br /&gt; {&lt;br /&gt;   Console.WriteLine("Company is {0} and contact is {1}",   customer.CompanyName, customer.ContactName&lt;br /&gt;);&lt;br /&gt; }    &lt;span class="codeComment"&gt;// Pause to see the output&lt;/span&gt;   Console.ReadLine();   }&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Modifying Data Using the Created Object Model&lt;/h3&gt;The previous example  focused on the retrieval of data. We'll now examine the basic data manipulation,  create, update, and delete operations and how LINQ to SQL makes them simple. The  object model used to manipulate the data is the model generated in one of the  earlier sections. After each operation we'll use the SubmitChanges() method to  save the changes to the database. We'll execute some simple query expressions  with the &lt;code&gt;Count()&lt;/code&gt; method to verify the modifications were made as  desired. As the example will show, you can use instance of objects, make  modifications to them, and the changes that you make are tracked in a change set  and pushed back to the database.&lt;br /&gt;&lt;br /&gt;&lt;span class="codeKeyword"&gt;using&lt;/span&gt; (NorthwindDataClassesDataContext context =   &lt;span class="codeKeyword"&gt;new&lt;/span&gt; NorthwindDataClassesDataContext())   {&lt;br /&gt;   &lt;span class="codeComment"&gt;// Add a new record and verify it exists through Count&lt;/span&gt;&lt;br /&gt; var customer = &lt;span class="codeKeyword"&gt;new&lt;/span&gt; Customer()&lt;br /&gt; {&lt;br /&gt; CompanyName = "Drama Cafe",   CustomerID = "DRACA",   ContactName = "Tom Smith",   City = "Beverly Hills",   Address = "123 Melrose Place",   PostalCode = "90210"&lt;br /&gt; };&lt;br /&gt; context.Customers.InsertOnSubmit(customer);&lt;br /&gt; context.SubmitChanges();&lt;br /&gt; Console.WriteLine("Number of DRACA records: {0}",   context.Customers.Where(c =&gt; c.CustomerID == "DRACA").Count());      &lt;span class="codeComment"&gt;// Modify the record and verify it is changed through Count&lt;/span&gt;     customer.ContactName = "Joe Smith";&lt;br /&gt; context.SubmitChanges();&lt;br /&gt; Console.WriteLine("Number of Joe Smith records: {0}",   context.Customers.Where(c =&gt; c.ContactName == "Joe Smith").Count());      &lt;span class="codeComment"&gt;// Delete a record and verify it is removed through Count&lt;/span&gt;     context.Customers.DeleteOnSubmit(customer);&lt;br /&gt; context.SubmitChanges();&lt;br /&gt; Console.WriteLine("Number of DRACA records: {0}",   context.Customers.Where(c =&gt; c.CustomerID == "DRACA").Count());&lt;br /&gt; &lt;span class="codeComment"&gt;// Pause to see the output&lt;/span&gt;     Console.ReadLine();&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Calling Stored Procedures&lt;/h3&gt;The previous retrieve, create, update, and  delete operations involved dynamically generated SQL statements. It is also  possible to call stored procedures in place of dynamically generated SQL. The  sample code below demonstrates how to call stored procedures. The Northwind  database has a stored procedure called "Ten Most Expensive Products" we will use  for this example. Once again using the Server Explorer navigate to the Stored  Procedures in the tree view and drag the stored procedure to the design surface.  You'll want to right click on the design surface and select "Show Methods Pane"  if it isn't already available. You should now see a method,  &lt;code&gt;Ten_Most_Expensive_Products()&lt;/code&gt;, that has been created and we'll use  in our next code example to get the list of top products and display the prices  to the console.&lt;br /&gt;&lt;br /&gt;&lt;span class="codeKeyword"&gt;using&lt;/span&gt; (NorthwindDataClassesDataContext context =   &lt;span class="codeKeyword"&gt;new&lt;/span&gt; NorthwindDataClassesDataContext())   {     &lt;span class="codeComment"&gt;&lt;br /&gt;// Use the ten most expensive products stored procedure&lt;/span&gt;     var results = from products &lt;span class="codeKeyword"&gt;in&lt;/span&gt; context.Ten_Most_Expensive_Products()       select products;      &lt;span class="codeKeyword"&gt;&lt;br /&gt;foreach&lt;/span&gt; (var product &lt;span class="codeKeyword"&gt;in&lt;/span&gt; results)    &lt;br /&gt;{&lt;br /&gt; Console.WriteLine("Product price is {0}", product.UnitPrice);&lt;br /&gt;   }      &lt;span class="codeComment"&gt;// Pause to see the output&lt;/span&gt;     Console.ReadLine();&lt;br /&gt;&lt;span style="font-weight: bold;"&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/3068650074752359005-1452903721425649576?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/1452903721425649576/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=1452903721425649576' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/1452903721425649576'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/1452903721425649576'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2009/07/language-integrated-query-linq-to-sql.html' title='Language Integrated Query (LINQ) to SQL'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-8363208781564852871</id><published>2009-06-30T22:12:00.000-07:00</published><updated>2009-06-30T22:13:08.958-07:00</updated><title type='text'>Scheduling and Event Logging Windows Service</title><content type='html'>In previous post we had seen how to create a windows service. In this part we will see how can we log events in windows service and how to schedule service to occur at specific interval. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;First we will see how we can Log events in EventViewer event of Windows Service. Steps are as follows. &lt;br /&gt;&lt;br /&gt;- Add an EventLog to your windows service class, from Toolbox. &lt;br /&gt;&lt;br /&gt;- Give an ID say "MyEventLog1", Set Log to "MyEventLog" and Source to "MyEventLogSource" &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This will help you to differentiate your log in event viewer. And you can also create a new view of your event source log. Create new Log View on application and rename it to "MyEventLogSource". Now clear logs, then each new entry with log source "MyEventLogSource" will be logged in the new view. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now how will we write a new log entry in Windows Service. &lt;br /&gt;&lt;br /&gt;Write the following code in OnStart Code block of your Service. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;MyEventLog1.WriteEntry("My Windows Service Started......."); &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This will be write a log entry. But make sure that you write this code in try-catch block, because on some OS, Windows Service do not have permission to log events. At that time your service will generate an unhandeled exception and it will stop immediately and you will unable to identify the problem that why your service is stopped immediately after it starts. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There can be two types of windows service. &lt;br /&gt;&lt;br /&gt;1) Windows service that run only once. There is no any scheduling of the service. If you want to run it again the you must start the service again. It will stop automatically after it complete its job. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2) Windows service that run at specific interval. This service is useful to run Insert command from one server to other backup server. Or it can be use to complete tasks that are added in Database. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The first type of Windows service is very easy. Just put your code in OnStart event of the Windows Service. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Scheduling Windows Service with Timer Control&lt;br /&gt;&lt;br /&gt;For scheduling a Windows service declare two global variables in your service class (Make sure not in Service.designer.cs Designer class) &lt;br /&gt;This timer control is not System.Timer, this control is &lt;br /&gt;System.Threading.Timer&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;private Timer stateTimer; &lt;br /&gt;&lt;br /&gt;private TimerCallback timerDelegate; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Timer is useful for creating the scheduling the Service. TimerCallback is useful for specifying the function which will be called when timer interval ends(Tick event fires). &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now write this code in your OnStart block. &lt;br /&gt;&lt;br /&gt;timerDelegate = new TimerCallback(DoSomething); &lt;br /&gt;stateTimer = new Timer(timerDelegate, null, 0, 5000); // 5000 = 5 secs &lt;br /&gt;&lt;br /&gt;In above code the timerDelegate is a callback function which will specify the Function that will be called each time your timer fires tick event. &lt;br /&gt;&lt;br /&gt;Now the stateTimer is assigned to a new timer object which specify timerDelegate, initial delay and interval. In above example '0' is initial delay which specify after timer object is created how much to delay for firing first Tick event. '5000' this specify the interval, this indicate the delay of firing the tick event since the last tick event is fired. Both Initial delay and Interval are specified in milisecond. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now we will see how to create the function. &lt;br /&gt;&lt;br /&gt;protected void DoSomething(object sender) &lt;br /&gt;{ &lt;br /&gt;MyEventLog1.WriteEntry("Windows Service event fired at " + DateTime.Now.ToString()); &lt;br /&gt;} &lt;br /&gt;&lt;br /&gt;Above I have specified the function to be fired at tick event of timer. It will log in EventViewer with date and time. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In next part we will see how can we add a configuration file to the Windows Service, how to install the service and common problem while using with Windows Server 2003 system.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-8363208781564852871?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/8363208781564852871/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=8363208781564852871' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/8363208781564852871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/8363208781564852871'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2009/06/scheduling-and-event-logging-windows.html' title='Scheduling and Event Logging Windows Service'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-2139997062916089484</id><published>2009-06-30T21:56:00.000-07:00</published><updated>2009-06-30T22:02:09.616-07:00</updated><title type='text'>Resizing Data Controls in ASP.NET Applications</title><content type='html'>&lt;table class="articleViewer" style="top: -21px;"&gt;&lt;tbody&gt;&lt;tr style="font-weight: bold;"&gt; &lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a class="pageTitle" id="#Page1"&gt;Introduction&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td class="content" colspan="2"&gt;  &lt;div class="KonaBody" wnwra="true"&gt; &lt;p class="MsoNormal"&gt;This article explains about resizing web controls in runtime.  In browser output, usually resizing is achieved during Development for fixing  the control’s width and height. But sometimes we require resizing the DataGrid,  DataList or other data controls to adjust for clearly reading the displayed  data. It is rare to see the &lt;a class="kLink" oncontextmenu="return false;" id="KonaLink0" onmouseover="adlinkMouseOver(event,this,0);" style="position: static; text-decoration: underline ! important;" onclick="adlinkMouseClick(event,this,0);" onmouseout="adlinkMouseOut(event,this,0);" href="http://aspalliance.com/1654_Resizing_Data_Controls_in_ASPNET_Applications.all#" target="_top"&gt;&lt;span style="font-weight: 400; font-size: 10pt; color: blue ! important; font-family: Verdana; position: static;color:blue;" &gt;&lt;span class="kLink" style="font-weight: 400; font-size: 10pt; color: blue ! important; font-family: Verdana; position: relative;"&gt;internet&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;  page's output to be adjustable, but it is possible with a few lines of  JavaScript.&lt;/p&gt;&lt;p style="font-weight: bold;" class="SectionHeading"&gt;Event Types&lt;/p&gt; &lt;p class="MsoNormal"&gt;The whole resize logic (column width increase or decrease)  depends upon catching the co-ordinate where the user drags the column to be  resized. Mouse capturing will be set on initially when the page loads. Events to  be captured are the following:&lt;/p&gt; &lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;         &lt;/span&gt;&lt;/span&gt;Mouse Over&lt;/p&gt; &lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;         &lt;/span&gt;&lt;/span&gt;Mouse Down&lt;/p&gt; &lt;p class="MsoListBullet"&gt;&lt;span style="font-family: Symbol;"&gt;·&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;         &lt;/span&gt;&lt;/span&gt;Mouse Up&lt;/p&gt; &lt;p style="font-weight: bold;" class="SectionHeading"&gt;Style Settings&lt;/p&gt; &lt;p class="MsoNormal"&gt;Resizing can be done only on the column headers. Usually all  data controls, like DataGrid, GridView or DataList, will be set with some style  class for the header row. Here we take advantage of this style for tracking the  user's mouse over an event on the header row. This event will initiate the  trigger to start capturing the further events like mouse down and mouse up.  There is no special style setting to be done other than the user’s look and feel  styles. The JavaScript just requires a style name and that is it!&lt;/p&gt; &lt;p style="font-weight: bold;" class="SectionHeading"&gt;Mouse Capturing&lt;/p&gt; &lt;p class="MsoNormal"&gt;The user will be automatically seeing the difference in the  &lt;a class="kLink" oncontextmenu="return false;" id="KonaLink1" onmouseover="adlinkMouseOver(event,this,1);" style="position: static; text-decoration: underline ! important;" onclick="adlinkMouseClick(event,this,1);" onmouseout="adlinkMouseOut(event,this,1);" href="http://aspalliance.com/1654_Resizing_Data_Controls_in_ASPNET_Applications.all#" target="_top"&gt;&lt;span style="font-weight: 400; font-size: 10pt; color: blue ! important; font-family: Verdana; position: static;color:blue;" &gt;&lt;span class="kLink" style="font-weight: 400; font-size: 10pt; color: blue ! important; font-family: Verdana; position: relative;"&gt;cursor&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;  which will signal to them that the DataGrid/GridView is ready for resizing. This  will be done by the handler which we have set for document onmousemove. Whenever  the user reaches the header row, the first level job is over and mouse down  event will be ready to be raised for checking where the user clicks the mouse to  start dragging. At this moment the mouse move event will again take over. Now  the JavaScript will start handling mousedown and mousemove, which is equal to  mouse drag. On the mouse drag, the column size and the table size will increase  or decrease based on the mouse’s left or right movement respectively. Whenever  the user makes the mouse go up (stops dragging and releasing the mouse), the  resizing will get stopped and the current drag object will be destroyed.&lt;br /&gt;&lt;/p&gt;&lt;table class="articleViewer" style="top: -21px;"&gt;&lt;tbody&gt;&lt;tr style="font-weight: bold;"&gt; &lt;td class="subtitle" colspan="2"&gt;&lt;span id="intellitTxt"&gt;&lt;a class="pageTitle" id="#Page2"&gt;More Technical Information on Events&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td class="content" colspan="2"&gt; &lt;div class="backToTop"&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class="KonaBody" wnwra="true"&gt; &lt;p class="MsoNormal"&gt;There are some things to look into in the code for a clearer  understanding. The column resize can be pulled into the picture by just adding  the JavaScript file to the web page. Before that, define the header columns you  use in the web pages to the JavaScript file (headerStyle).&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 1&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;var isDraggable = false;&lt;br /&gt;var xX=0;anchorChild=0;anchorMain=0;&lt;br /&gt;var objOn=null;gridMain=null;&lt;br /&gt;var lastObj=undefined;&lt;br /&gt;var headerStyle="DataGrid-HeaderStyle";&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p style="font-weight: bold;" class="MsoNormal"&gt;Other common settings to be made are the following:&lt;/p&gt; &lt;p class="MsoNormal"&gt;isDraggable – This variable will be initially set to false to  denote that dragging logic should not be called; this will become true whenever  the mouse hovers over the datagrid’s header column’s border.&lt;/p&gt; &lt;p class="MsoNormal"&gt;xX, anchorChild, anchorMain – These three variables will hold  0 initially on every mouse down event when the user starts dragging. xX will  hold the x-axis position of the mouse, anchorChild will hold the width of the  Current Resizing cell, and anchorMain will hold the width of the entire DataGrid  or control.&lt;/p&gt; &lt;p class="MsoNormal"&gt;objOn – This will hold the current object which is under  dragging.&lt;/p&gt; &lt;p class="MsoNormal"&gt;lastObj – This temp object loads the objOn object. This will  be captured on mousedown and loaded to objOn during MouseMove.&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;a class="kLink" oncontextmenu="return false;" id="KonaLink2" onmouseover="adlinkMouseOver(event,this,2);" style="position: static; text-decoration: underline ! important;" onclick="adlinkMouseClick(event,this,2);" onmouseout="adlinkMouseOut(event,this,2);" href="http://aspalliance.com/1654_Resizing_Data_Controls_in_ASPNET_Applications.all#" target="_top"&gt;&lt;span style="font-weight: 400; font-size: 10pt; color: blue ! important; font-family: Verdana; position: static;color:blue;" &gt;&lt;span class="kLink" style="font-weight: 400; font-size: 10pt; color: blue ! important; font-family: Verdana; position: relative;"&gt;Firefox&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;  – DOM Expressions differ from browser to browser, so we have a common variable  which will be checked in every event. When the script is initialized, we  initialize the FireFox by finding whether the current browser is Firefox or  other.&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 2&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;var firefox = document.getElementById&amp;amp;&amp;amp;!document.all; &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p style="font-weight: bold;" class="SectionHeading"&gt;Mouse Events&lt;/p&gt; &lt;p class="MsoNormal"&gt;OnMouseMove – This event is used to capture the current place  in which the mouse is hovered and also to change the width of the cell and  DataGrid while they drag. So first we will capture the object on which we hover  the mouse.&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 3&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;objOn=(!firefox)?e.srcElement:e.target; &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;The line below will be used to load the last mouse over the  object for reference.&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 4&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;if(lastObj!=undefined)objOn=lastObj; &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;Then we have to change the cursor to resizable if the mouse  is hovered on the DataGrid header column’s borders.&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 5&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;document.body.style.cursor &lt;span style="font-weight: normal; font-size: 11px; color: red; font-family: Courier New; background-color: transparent;"&gt;=&lt;/span&gt;(objOn.offsetWidth-e.offsetX &lt; 10 &amp;amp;&amp;amp;&lt;br /&gt;objOn.parentElement.className == headerStyle)?'e-resize':'&lt;span style="font-weight: normal; font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"&gt;default&lt;/span&gt;'; &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;Now, we decide whether we should start dragging or not. It  depends on whether the user has clicked the mouse for dragging which would have  made the boolean isDraggable true.&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 6&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;if(isDraggable)&lt;br /&gt;{ document.body.style.cursor='e-resize';&lt;br /&gt;//Current_MouseX_Position - MouseX_DragStart + Cell_Width&lt;br /&gt;ic=e.clientX-xX+anchorChild;&lt;br /&gt;//Current_MouseX_Position - MouseX_DragStart + Table_Width&lt;br /&gt;it=e.clientX-xX+anchorMain;&lt;br /&gt;if(ic&gt;0)&lt;br /&gt;{&lt;br /&gt;gridMain.style.width = it + "px"; //Increase Table Width&lt;br /&gt;objOn.style.width = ic + "px"; //Increase Cell Width&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;The above piece of code will increase or decrease the size of  the DataGrid based on the mouse movement.&lt;/p&gt; &lt;p class="MsoNormal"&gt;OnMouseDown – This event is used to capture the point or  pixel where the user has started to drag (if the user has the mouse pointer over  the DataGrid header’s border). Here we will find the Cell’s Offset Position and  Table’s Offset position which will give the current X-Axis width of the cell and  the table respectively.&lt;/p&gt; &lt;p class="MsoNormal"&gt;First we will capture the object over which we hover the  mouse.&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 7&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;objOn=(!firefox)?e.srcElement:e.target; &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;Then we have to check whether the mouse is hovered on the  DataGrid header column’s borders. If it is true, the following steps will be  carried out.&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 8&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;if(objOn.parentElement.className == headerStyle &amp;amp;&amp;amp;&lt;br /&gt;document.body.style.cursor=='e-resize')&lt;br /&gt;{ &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;Set the Boolean Flag isDraggable to denote that we are in  draggable mode.&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 9&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;isDraggable = true; &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;Set the gridMain object with the DataGrid or GridView  object.&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 10&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;gridMain = objOn.parentElement.parentElement.parentElement; &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;Get the object of main table which corresponds to current  column's width variation. &lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 11&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;xX = e.clientX; &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;Get the current Mouse X Position.&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 12&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;anchorChild = objOn.offsetWidth; &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;Getting the current Cell/Column Width&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 13&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;anchorMain = gridMain.offsetWidth; &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;Get the current Table Width.&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 14&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;lastObj = objOn; &lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;This will be the else part of the Current IF Statement. If  the mouse is clicked outside the header scope, the lastObj variable is set to  undefined.&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 15&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;lastObj = undefined;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;OnMouseUp – This event is used to stop the dragging. There is  no specific code to stop the drag; the drag event will be fired based on  mouseover and mousedown events. When the mouse click is up, lastObj object used  in those events will be undefined and isDraggable boolean flag will be set to  false to say that the drag has been stopped by the user.&lt;/p&gt; &lt;p class="MsoNormal"&gt;Dragging Stop and Forget LastObj&lt;/p&gt; &lt;p style="font-weight: bold;" class="CodeListingHeading"&gt;Listing 16&lt;/p&gt; &lt;div class="MsoNormal"&gt;&lt;pre&gt;&lt;span style="font-weight: normal; font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"&gt;isDraggable = false;&lt;br /&gt;lastObj=undefined;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-weight: bold;"&gt;Here is full JavaScript Code&lt;/span&gt;&lt;/p&gt;var firefox = document.getElementById&amp;amp;&amp;amp;!document.all; //Check whether the browser is FF;&lt;br /&gt;var isDraggable = true;&lt;br /&gt;var xX=0;anchorChild=0;anchorMain=0;&lt;br /&gt;var objOn=null;gridMain=null;&lt;br /&gt;var lastObj=undefined;&lt;br /&gt;var headerStyle="DataGrid-HeaderStyle";&lt;br /&gt;&lt;br /&gt;document.onmouseup=mouseUpCapture;&lt;br /&gt;&lt;br /&gt;document.onmousemove=mouseMoveCapture;&lt;br /&gt;&lt;br /&gt;document.onmousedown=mouseDownCapture;&lt;br /&gt;&lt;br /&gt;/*EventHandler to capture Mouse Up*/&lt;br /&gt;&lt;br /&gt;function mouseUpCapture(){isDraggable = false;lastObj=undefined;} //Dragging Stop and Forget LastObj;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;/*EventHandler to capture Mouse Down*/&lt;br /&gt;&lt;br /&gt;function mouseDownCapture(e){&lt;br /&gt;&lt;br /&gt;if(!firefox)e = event;objOn=(!firefox)?e.srcElement:e.target; //Check whether the browser is FF and set event object accordingly;&lt;br /&gt;&lt;br /&gt;//To Check whether the mouse hovers over the HeaderRow and cursor type is currently re-sizable;&lt;br /&gt;&lt;br /&gt;if(objOn.parentElement.className == headerStyle &amp;amp;&amp;amp; document.body.style.cursor=='e-resize')&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;isDraggable = true; //Start understanding that we can start dragging;&lt;br /&gt;gridMain = objOn.parentElement.parentElement.parentElement; //Getting the object of main table which corresponds to current column's width variation;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;xX = e.clientX; //Getting the current Mouse X Position;&lt;br /&gt;&lt;br /&gt;anchorChild = objOn.offsetWidth; //Getting the current Cell/Column Width;&lt;br /&gt;&lt;br /&gt;anchorMain = gridMain.offsetWidth; //Getting the current Table Width;&lt;br /&gt;&lt;br /&gt;lastObj = objOn; //Stores the current mouse hovering object for moving reference;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;else{lastObj = undefined;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/*EventHandler to capture Mouse Move*/&lt;br /&gt;&lt;br /&gt;function mouseMoveCapture(e){&lt;br /&gt;&lt;br /&gt;if(!firefox)e = event; //Check whether the browser is FF and set event object accordingly;&lt;br /&gt;objOn=(!firefox)?e.srcElement:e.target;&lt;br /&gt;&lt;br /&gt;if(lastObj!=undefined)objOn=lastObj; //Loads the mouse hovered object for moving reference;&lt;br /&gt;&lt;br /&gt;//Check whether the mouse hovers over the Headerrow's column borders and Make the cursor re-sizable;&lt;br /&gt;document.body.style.cursor =(objOn.offsetWidth-e.offsetX &lt; 10 &amp;amp;&amp;amp; objOn.parentElement.className == headerStyle)?'e-resize':'default';&lt;br /&gt;&lt;br /&gt;//Start Dragging&lt;br /&gt;if(isDraggable)&lt;br /&gt;{ document.body.style.cursor='e-resize'; //Maintaing the cursor as re-sizable&lt;br /&gt;ic=e.clientX-xX+anchorChild;&lt;br /&gt;&lt;br /&gt;//Current_MouseX_Position - MouseX_DragStart + Cell_Width;&lt;br /&gt;it=e.clientX-xX+anchorMain;&lt;br /&gt;&lt;br /&gt;//Current_MouseX_Position - MouseX_DragStart + Table_Width;&lt;br /&gt;&lt;br /&gt;if(ic&gt;0)&lt;br /&gt;{&lt;br /&gt;gridMain.style.width = it + "px"; //Increase Table Width;&lt;br /&gt;objOn.style.width = ic + "px"; //Increase Cell Width;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-2139997062916089484?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/2139997062916089484/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=2139997062916089484' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/2139997062916089484'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/2139997062916089484'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2009/06/resizing-data-controls-in-aspnet.html' title='Resizing Data Controls in ASP.NET Applications'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-6630060222259177343</id><published>2009-01-13T01:21:00.000-08:00</published><updated>2009-01-13T01:46:53.053-08:00</updated><title type='text'>The New LinkedList Class and Iterator Class in C#</title><content type='html'>we need a header field and a constructor method to instantiate the list.&lt;br /&gt;&lt;br /&gt;public class LinkedList()&lt;br /&gt;{&lt;br /&gt;private Node header;&lt;br /&gt;public LinkedList()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;header = new Node("header");&lt;br /&gt;}&lt;br /&gt;public bool IsEmpty() {&lt;br /&gt;return (header.Link == null);&lt;br /&gt;}&lt;br /&gt;public Node GetFirst() {&lt;br /&gt;return header;&lt;br /&gt;}&lt;br /&gt;public void ShowList() {&lt;br /&gt;Node current = header.Link;&lt;br /&gt;while (!(current == null)) {&lt;br /&gt;Console.WriteLine(current.Element);&lt;br /&gt;current = current.Link;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;div align="center"&gt;&lt;br /&gt;&lt;strong&gt;Demonstrating the Iterator Class&lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;Using the Iterator class, it’s easy to write an interactive program to move through a linked list. This also gives us a chance to put all the code for both the Iterator class and the LinkedList class in one place.&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;using System;&lt;br /&gt;public class Node&lt;br /&gt;{&lt;br /&gt;public Object Element;&lt;br /&gt;public Node Link;&lt;br /&gt;public Node()&lt;br /&gt;{&lt;br /&gt;Element = null;&lt;br /&gt;Link = null;&lt;br /&gt;}&lt;br /&gt;public Node(Object theElement)&lt;br /&gt;{&lt;/div&gt;&lt;div align="left"&gt;Element = theElement;&lt;br /&gt;Link = null;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public class InsertBeforeHeaderException : System.&lt;br /&gt;ApplicationException&lt;br /&gt;{&lt;br /&gt;public InsertBeforeHeaderException(string message) :&lt;br /&gt;base(message)&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public class LinkedList &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;private Node header;&lt;br /&gt;public LinkedList() &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;header = new Node("header");&lt;br /&gt;}&lt;br /&gt;public bool IsEmpty() &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;return (header.Link == null);&lt;br /&gt;}&lt;br /&gt;public Node GetFirst() &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;return header;&lt;br /&gt;}&lt;br /&gt;public void ShowList() &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;Node current = header.Link;&lt;br /&gt;while (!(current == null)) &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;Console.WriteLine(current.Element);&lt;br /&gt;current = current.Link;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public class ListIter &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;private Node current;&lt;br /&gt;private Node previous;&lt;br /&gt;LinkedList theList;&lt;br /&gt;public ListIter(LinkedList list) &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;theList = list;&lt;br /&gt;current = theList.GetFirst();&lt;br /&gt;previous = null;&lt;br /&gt;}&lt;br /&gt;public void NextLink() &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;previous = current;&lt;br /&gt;current = current.Link;&lt;br /&gt;}&lt;br /&gt;public Node GetCurrent() &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;return current;&lt;br /&gt;}&lt;br /&gt;public void InsertBefore(Object theElement) &lt;/div&gt;&lt;div align="left"&gt;{&lt;/div&gt;&lt;div align="left"&gt;Node newNode = new Node(theElement);&lt;br /&gt;if (previous.Link == null)&lt;br /&gt;throw new InsertBeforeHeaderException&lt;br /&gt;("Can't insert here.");&lt;br /&gt;else {&lt;br /&gt;newNode.Link = previous.Link;&lt;br /&gt;previous.Link = newNode;&lt;br /&gt;current = newNode;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public void InsertAfter(Object theElement) &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;Node newNode = new Node(theElement);&lt;br /&gt;newNode.Link = current.Link;&lt;br /&gt;current.Link = newNode;&lt;br /&gt;NextLink();&lt;br /&gt;}&lt;br /&gt;public void Remove() &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;previous.Link = current.Link;&lt;br /&gt;}&lt;br /&gt;public void Reset() &lt;/div&gt;&lt;div align="left"&gt;{&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;current = theList.GetFirst();&lt;br /&gt;previous = null;&lt;br /&gt;}&lt;br /&gt;public bool AtEnd() {&lt;br /&gt;return (current.Link == null);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;class chapter&lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;static void Main() &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;LinkedList MyList = new LinkedList();&lt;br /&gt;ListIter iter = new ListIter(MyList);&lt;br /&gt;string choice, value;&lt;br /&gt;try&lt;br /&gt;{&lt;br /&gt;iter.InsertAfter("David");&lt;br /&gt;iter.InsertAfter("Mike");&lt;br /&gt;iter.InsertAfter("Raymond");&lt;br /&gt;iter.InsertAfter("Bernica");&lt;br /&gt;iter.InsertAfter("Jennifer");&lt;br /&gt;iter.InsertBefore("Donnie");&lt;br /&gt;iter.InsertAfter("Michael");&lt;br /&gt;iter.InsertBefore("Terrill");&lt;br /&gt;iter.InsertBefore("Mayo");&lt;br /&gt;iter.InsertBefore("Clayton");&lt;br /&gt;while (true)&lt;br /&gt;{&lt;br /&gt;Console.WriteLine("(n) Move to next node");&lt;br /&gt;Console.WriteLine("(g)Get value in current node");&lt;br /&gt;Console.WriteLine("(r) Reset iterator");&lt;br /&gt;Console.WriteLine("(s) Show complete list");&lt;br /&gt;Console.WriteLine("(a) Insert after");&lt;br /&gt;Console.WriteLine("(b) Insert before");&lt;br /&gt;Console.WriteLine("(c) Clear the screen");&lt;br /&gt;Console.WriteLine("(x) Exit");&lt;br /&gt;Console.WriteLine();&lt;br /&gt;Console.Write("Enter your choice: ");&lt;br /&gt;choice = Console.ReadLine();&lt;br /&gt;choice = choice.ToLower();&lt;br /&gt;char[] onechar = choice.ToCharArray();&lt;br /&gt;switch(onechar[0])&lt;br /&gt;{&lt;br /&gt;case 'n' :&lt;br /&gt;if (!(MyList.IsEmpty()) &amp;amp;&amp;amp;&lt;br /&gt;(!(iter.AtEnd())))&lt;br /&gt;iter.NextLink();&lt;br /&gt;else&lt;br /&gt;Console.WriteLine("Can' move to&lt;br /&gt;next link.");&lt;br /&gt;break;&lt;br /&gt;case 'g' :&lt;br /&gt;if (!(MyList.IsEmpty()))&lt;br /&gt;Console.WriteLine("Element: " +&lt;br /&gt;iter.GetCurrent().Element);&lt;br /&gt;else&lt;br /&gt;Console.WriteLine ("List is empty.");&lt;br /&gt;break;&lt;br /&gt;case 'r' :&lt;br /&gt;iter.Reset();&lt;br /&gt;break;&lt;br /&gt;case 's' :&lt;br /&gt;if (!(MyList.IsEmpty()))&lt;br /&gt;MyList.ShowList();&lt;br /&gt;else&lt;br /&gt;Console.WriteLine("List is empty.");&lt;br /&gt;break;&lt;br /&gt;case 'a' :&lt;br /&gt;Console.WriteLine();&lt;br /&gt;Console.Write("Enter value to insert:");&lt;br /&gt;value = Console.ReadLine();&lt;br /&gt;iter.InsertAfter(value);&lt;br /&gt;break;&lt;br /&gt;case 'b' :&lt;br /&gt;Console.WriteLine();&lt;br /&gt;Console.Write("Enter value to insert:");&lt;br /&gt;value = Console.ReadLine();&lt;br /&gt;iter.InsertBefore(value);&lt;br /&gt;break;&lt;br /&gt;case 'c' :&lt;br /&gt;// clear the screen&lt;br /&gt;break;&lt;br /&gt;case 'x' :&lt;br /&gt;// end of program&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;catch (InsertBeforeHeaderException e)&lt;br /&gt;{&lt;br /&gt;Console.WriteLine(e.Message);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/div&gt;&lt;div align="center"&gt;&lt;br /&gt;&lt;strong&gt;GENERIC LINKED LIST CLASS AND THE GENERIC NODE CLASS&lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;The System.Collections.Generic namespace provides two generic classes for building linked lists: the LinkedList class and the LinkedListNode class. The Node class provides two data fields for storing a value and a link, whereas the LinkedList class implements a doubly linked list with methods for inserting before a node as well as inserting after a node. The class also provides method for removing nodes, finding the first and last nodes in the linked list, as well as other useful methods.&lt;/div&gt;&lt;div align="center"&gt;&lt;br /&gt;&lt;strong&gt;Generic Linked List Example&lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;LinkedListNode&lt;string&gt; node1 = new LinkedListNode&lt;string&gt;_(“Raymond");&lt;br /&gt;LinkedList&lt;string&gt; names = new LinkedList&lt;string&gt;();&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;From here, it’s just a matter of using the classes to build and use a linked list. A simple example demonstrates how easy it is to use these classes:&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Text;&lt;br /&gt;class Program &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;static void Main(string[] args) &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;LinkedListNode&lt;string&gt; node = new&lt;br /&gt;LinkedListNode&lt;string&gt;("Mike");&lt;br /&gt;LinkedList&lt;string&gt; names = new LinkedList&lt;string&gt;();&lt;br /&gt;names.AddFirst(node);&lt;br /&gt;LinkedListNode&lt;string&gt; node1 = new&lt;br /&gt;LinkedListNode&lt;string&gt; ("David");&lt;br /&gt;names.AddAfter(node, node1);&lt;br /&gt;LinkedListNode&lt;string&gt; node2 = new&lt;br /&gt;LinkedListNode&lt;string&gt; ("Raymond");&lt;br /&gt;names.AddAfter(node1, node2);&lt;br /&gt;LinkedListNode&lt;string&gt; node3 = new LinkedListNode &lt;string&gt;(null);&lt;br /&gt;LinkedListNode&lt;string&gt; aNode = names.First;&lt;br /&gt;while(aNode != null) &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;Console.WriteLine(aNode.Value);&lt;br /&gt;aNode = aNode.Next;&lt;br /&gt;}&lt;br /&gt;aNode = names.Find("David");&lt;br /&gt;if (aNode != null) aNode = names.First;&lt;br /&gt;while (aNode != null) &lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;Console.WriteLine(aNode.Value);&lt;br /&gt;aNode = aNode.Next;&lt;br /&gt;}&lt;br /&gt;Console.Read()&lt;br /&gt;}&lt;br /&gt;}&lt;/div&gt;&lt;div align="left"&gt;&lt;br /&gt;The linked list in this example does not use a header node because&lt;br /&gt;we can easily find the first node in the linked list with the First property.&lt;br /&gt;Although it wasn’t used in this example, there is also a Last property&lt;br /&gt;that could be used in the previous While loop to check for the end of the&lt;br /&gt;list:&lt;br /&gt;while (aNode != names.Last) {&lt;br /&gt;Console.WriteLine(aNode.Value);&lt;br /&gt;aNode = aNode.Next;&lt;br /&gt;}&lt;br /&gt;There are two other methods, not shown here, that could prove useful in a linked list implementation: AddFirst and AddLast. These methods can help you implement a linked list without having to provide header and tail nodes in your list.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-6630060222259177343?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/6630060222259177343/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=6630060222259177343' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/6630060222259177343'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/6630060222259177343'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2009/01/new-linkedlist-class-and-iterator-class.html' title='The New LinkedList Class and Iterator Class in C#'/><author><name>Ankur Sharma</name><uri>http://www.blogger.com/profile/12373031815995005939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_x_e5Xjb8ARI/SOkBIfJ4krI/AAAAAAAAA0I/E6Wdbft0I1A/S220/DSC03622.JPG'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-4192236190173986640</id><published>2009-01-13T00:59:00.000-08:00</published><updated>2009-01-13T01:20:26.547-08:00</updated><title type='text'>USING AN ITERATOR CLASS in C#</title><content type='html'>One problem the LinkedList class has is that you can’t refer to two positions in the linked list at the same time. We can refer to any one position in the list (the current node, the previous node, etc.), but if we want to specify two or more positions, such as if we want to remove a range of nodes from the list, we’ll need some other mechanism. This mechanism is an iterator class.&lt;br /&gt;         The iterator class consists of three data fields: a field that stores the linked list, a field that stores the current node, and a field that stores the current node. The constructor method is passed a linked list object, and the method sets the current field to the header node of the list passed into the method. Let’s look at our definition of the class so far:&lt;br /&gt;&lt;br /&gt;public class ListIter&lt;br /&gt;{&lt;br /&gt;private Node current;&lt;br /&gt;private Node previous;&lt;br /&gt;LinkedList theList;&lt;br /&gt;public ListIter(LinkedList list)&lt;br /&gt;{&lt;br /&gt;theList = list;&lt;br /&gt;current = theList.getFirst();&lt;br /&gt;previous = null;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The first thing we want an Iterator class to do is allow us to move from node to node through the list. The method nextLink does this:&lt;br /&gt;&lt;br /&gt;public void NextLink()&lt;br /&gt;{&lt;br /&gt;previous = current;&lt;br /&gt;current = current.link;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Notice that in addition to establishing a new current position, the previous node is also set to the node that is current before the method has finished executing. Keeping track of the previous node in addition to the current node makes insertion and removal easier to perform.&lt;br /&gt;The getCurrent method returns the node pointed to by the iterator:&lt;br /&gt;public Node GetCurrent()&lt;br /&gt;{&lt;br /&gt;return current;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Two insertion methods are built in the Iterator class: InsertBefore and InsertAfter. InsertBefore inserts a new node before the current node; InsertAfter inserts a new node after the current node. Let’s look at the Insert-Before method first.&lt;br /&gt;&lt;br /&gt;The first thing we have to do when inserting a new node before the current object is check to see if we are at the beginning of the list. If we are, then we can’t insert a node before the header node, so we throw an exception. This exception is defined below. Otherwise, we set the new node’s Link field to the Link field of the previous node, set the previous node’s Link field to the new node, and reset the current position to the new node. Here’s the code:&lt;br /&gt;&lt;br /&gt;public void InsertBefore(Object theElement)&lt;br /&gt;{&lt;br /&gt;Node newNode = new Node(theElement);&lt;br /&gt;if (current == header)&lt;br /&gt;throw new InsertBeforeHeaderException();&lt;br /&gt;else&lt;br /&gt;{&lt;br /&gt;newNode.Link = previous.Link;&lt;br /&gt;previous.Link = newNode;&lt;br /&gt;current = newNode;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The InsertBeforeHeader Exception class definition is:&lt;br /&gt;&lt;br /&gt;public class InsertBeforeHeaderException&lt;br /&gt;{&lt;br /&gt;public InsertBeforeHeaderException()&lt;br /&gt;{&lt;br /&gt;base("Can't insert before the header node.");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The InsertAfter method in the Iterator class is much simpler than the method we wrote in the LinkedList class. Since we already know the position of the current node, the method just needs to set the proper links and set the current node to the next node.&lt;br /&gt;&lt;br /&gt;public void InsertAfter(Object theElement)&lt;br /&gt;{&lt;br /&gt;Node newnode = new Node(theElement);&lt;br /&gt;newNode.Link = current.Link;&lt;br /&gt;current.Link = newnode;&lt;br /&gt;NextLink();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Removing a node from a linked list is extremely easy using an Iterator class. The method simply sets the Link field of the previous node to the node pointed to by the current node’s Link field:&lt;br /&gt;&lt;br /&gt;public void Remove()&lt;br /&gt;{&lt;br /&gt;prevous.Link = current.Link;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Other methods we need in an Iterator class include methods to reset the iterator to the header node (and the previous node to null) and a method to test if we’re at the end of the list. These methods are shown as follows.&lt;br /&gt;&lt;br /&gt;public void Reset()&lt;br /&gt;current = theList.getFirst();&lt;br /&gt;previous = null;&lt;br /&gt;}&lt;br /&gt;public bool AtEnd()&lt;br /&gt;{&lt;br /&gt;return (current.Link == null);&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-4192236190173986640?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/4192236190173986640/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=4192236190173986640' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/4192236190173986640'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/4192236190173986640'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2009/01/using-iterator-class-in-c.html' title='USING AN ITERATOR CLASS in C#'/><author><name>Ankur Sharma</name><uri>http://www.blogger.com/profile/12373031815995005939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_x_e5Xjb8ARI/SOkBIfJ4krI/AAAAAAAAA0I/E6Wdbft0I1A/S220/DSC03622.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-508191800845920937</id><published>2009-01-12T23:33:00.000-08:00</published><updated>2009-01-13T00:55:41.727-08:00</updated><title type='text'>Circular Link List Implementation in C#</title><content type='html'>&lt;div align="center"&gt;&lt;strong&gt;Circularly Linked List&lt;/strong&gt;&lt;/div&gt;&lt;a href="http://2.bp.blogspot.com/_x_e5Xjb8ARI/SWxUd5v4S4I/AAAAAAAAA5I/pRQLzWAwmtA/s1600-h/untitled2.PNG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5290696534948072322" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 75px; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_x_e5Xjb8ARI/SWxUd5v4S4I/AAAAAAAAA5I/pRQLzWAwmtA/s320/untitled2.PNG" border="0" /&gt;&lt;/a&gt; A circularly linked list is a list where the last node points back to the first node (which may be a header node).&lt;br /&gt;&lt;br /&gt;public class Node&lt;br /&gt;{&lt;br /&gt;public Object Element;&lt;br /&gt;public Node Flink;&lt;br /&gt;public Node Blink;&lt;br /&gt;public Node()&lt;br /&gt;{&lt;br /&gt;Element = null;&lt;br /&gt;Flink = null;&lt;br /&gt;Blink = null;&lt;br /&gt;}&lt;br /&gt;public Node(Object theElement)&lt;br /&gt;{&lt;br /&gt;Element = theElement;&lt;br /&gt;Flink = null;&lt;br /&gt;Blink = null;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public class LinkedList&lt;br /&gt;{&lt;br /&gt;protected Node current;&lt;br /&gt;&lt;br /&gt;protected Node header;&lt;br /&gt;private int count;&lt;br /&gt;public LinkedList() {&lt;br /&gt;count = 0;&lt;br /&gt;header = new Node("header");&lt;br /&gt;header.Link = header;&lt;br /&gt;}&lt;br /&gt;public bool IsEmpty() {&lt;br /&gt;return (header.Link == null);&lt;br /&gt;}&lt;br /&gt;public void MakeEmpty() {&lt;br /&gt;header.Link = null;&lt;br /&gt;}&lt;br /&gt;public void PrintList() {&lt;br /&gt;Node current = new Node();&lt;br /&gt;current = header;&lt;br /&gt;while (!(current.Link.Element = "header")) {&lt;br /&gt;Console.WriteLine(current.Link.Element);&lt;br /&gt;current = current.Link;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;private Node FindPrevious(Object n)&lt;br /&gt;{&lt;br /&gt;Node current = header;&lt;br /&gt;while (!(current.Link == null) &amp;amp;&amp;amp; current.Link.&lt;br /&gt;Element != n)&lt;br /&gt;current = current.Link;&lt;br /&gt;return current;&lt;br /&gt;}&lt;br /&gt;private Node Find(Object n)&lt;br /&gt;{&lt;br /&gt;Node current = new Node();&lt;br /&gt;current = header.Link;&lt;br /&gt;while (current.Element != n)&lt;br /&gt;current = current.Link;&lt;br /&gt;return current;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public void Remove(Object n)&lt;br /&gt;{&lt;br /&gt;Node p = FindPrevious(n);&lt;br /&gt;if (!(p.Link == null)&lt;br /&gt;p.Link = p.Link.Link;&lt;br /&gt;count--;&lt;br /&gt;}&lt;br /&gt;public void Insert(Object n1, n2)&lt;br /&gt;{&lt;br /&gt;Node current = new Node();&lt;br /&gt;Node newnode = new Node(n1);&lt;br /&gt;current = Find(n2);&lt;br /&gt;newnode.Link = current.Link;&lt;br /&gt;current.Link = newnode;&lt;br /&gt;count++;&lt;br /&gt;}&lt;br /&gt;public void InsertFirst(Object n)&lt;br /&gt;{&lt;br /&gt;Node current = new Node(n);&lt;br /&gt;current.Link = header;&lt;br /&gt;header.Link = current;&lt;br /&gt;count++;&lt;br /&gt;}&lt;br /&gt;public Node Move(int n)&lt;br /&gt;{&lt;br /&gt;Node current = header.Link;&lt;br /&gt;Node temp;&lt;br /&gt;for(int i = 0, i &lt;= n; i++)&lt;br /&gt;current = current.Link;&lt;br /&gt;if (current.Element = "header")&lt;br /&gt;current = current.Link;&lt;br /&gt;temp = current;&lt;br /&gt;return temp;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;In the .NET Framework Library, the ArrayList data structure is implemented using a circularly linked list. There are also many problems that can be solved using a circularly linked list.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-508191800845920937?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/508191800845920937/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=508191800845920937' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/508191800845920937'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/508191800845920937'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2009/01/circular-link-list-implementation-in-c.html' title='Circular Link List Implementation in C#'/><author><name>Ankur Sharma</name><uri>http://www.blogger.com/profile/12373031815995005939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_x_e5Xjb8ARI/SOkBIfJ4krI/AAAAAAAAA0I/E6Wdbft0I1A/S220/DSC03622.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_x_e5Xjb8ARI/SWxUd5v4S4I/AAAAAAAAA5I/pRQLzWAwmtA/s72-c/untitled2.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-1638571256144794605</id><published>2009-01-12T23:18:00.000-08:00</published><updated>2009-01-12T23:32:19.811-08:00</updated><title type='text'>Doubly Link List Implementation in C#</title><content type='html'>&lt;a href="http://4.bp.blogspot.com/_x_e5Xjb8ARI/SWxBF3zmVII/AAAAAAAAA44/BN2XnuzuRtk/s1600-h/untitled2.PNG"&gt;&lt;img id="BLOGGER_PHOTO_ID_5290675231389013122" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 48px; TEXT-ALIGN: center" alt="" src="http://4.bp.blogspot.com/_x_e5Xjb8ARI/SWxBF3zmVII/AAAAAAAAA44/BN2XnuzuRtk/s320/untitled2.PNG" border="0" /&gt;&lt;/a&gt; We first need to modify the Node class to add an extra link to the class. To distinguish between the two links, we’ll call the link to the next node the FLink, and the link to the previous node the BLink. These fields are set to Nothing when a Node is instantiated. Here’s the code:&lt;br /&gt;public class Node&lt;br /&gt;{&lt;br /&gt;public Object Element;&lt;br /&gt;public Node Flink;&lt;br /&gt;public Node Blink;&lt;br /&gt;public Node()&lt;br /&gt;{&lt;br /&gt;Element = null;&lt;br /&gt;Flink = null;&lt;br /&gt;Blink = null;&lt;br /&gt;}&lt;br /&gt;public Node(Object theElement)&lt;br /&gt;{&lt;br /&gt;Element = theElement;&lt;br /&gt;Flink = null;&lt;br /&gt;Blink = null;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;div align="center"&gt;&lt;strong&gt;Insertion method&lt;/strong&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="left"&gt;public void Insert(Object newItem, Object after)&lt;/div&gt;&lt;div align="left"&gt;{&lt;br /&gt;Node current = new Node();&lt;br /&gt;Node newNode = new Node(newItem);&lt;br /&gt;current = Find(after);&lt;br /&gt;newNode.Flink = current.Link;&lt;br /&gt;newNode.Blink = current;&lt;br /&gt;current.Flink = newNode;&lt;br /&gt;}&lt;/div&gt;&lt;div align="center"&gt;&lt;strong&gt;Remove method&lt;/strong&gt;&lt;/div&gt;&lt;div align="left"&gt;We first need to find the node in the list; then we set the node’s back link property to point to the node pointed to in the deleted node’s forward link. Then we need to redirect the back link of the link the deleted node points to and point it to the node before the deleted node.&lt;/div&gt;&lt;br /&gt;&lt;div align="left"&gt;&lt;img id="BLOGGER_PHOTO_ID_5290676418540754562" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 80px; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_x_e5Xjb8ARI/SWxCK-SoVoI/AAAAAAAAA5A/ZlD9ZzcJ6nA/s320/untitled2.PNG" border="0" /&gt;&lt;/div&gt;&lt;p&gt;public void Remove(Object n) &lt;/p&gt;&lt;p&gt;{&lt;br /&gt;Node p = Find(n);&lt;br /&gt;if (!(p.Flink == null)) &lt;/p&gt;&lt;p&gt;{&lt;br /&gt;p.Blink.Flink = p.Flink;&lt;br /&gt;p.Flink.Blink = p.Blink;&lt;br /&gt;p.Flink = null;&lt;br /&gt;p.Blink = null;&lt;br /&gt;}&lt;br /&gt;}&lt;/p&gt;&lt;p align="center"&gt;&lt;br /&gt;&lt;strong&gt;Printing the elements of a linked list in reverse order&lt;/strong&gt;&lt;/p&gt;&lt;p align="left"&gt;First, we need a method that finds the last node in the list. This is just a matter of following each node’s forward link until we reach a link that points to null. This method, called FindLast, is defined as follows:&lt;br /&gt;private Node FindLast() &lt;/p&gt;&lt;p align="left"&gt;{&lt;br /&gt;Node current = new Node();&lt;br /&gt;current = header;&lt;br /&gt;while(!(current.Flink == null))&lt;br /&gt;current = current.Flink;&lt;br /&gt;return current;&lt;br /&gt;}&lt;/p&gt;&lt;p align="left"&gt;Once we find the last node in the list, to print the list in reverse order we just follow the backward link until we get to a link that points to null, which  indicates we’re at the header node. Here’s the code:&lt;br /&gt;public void PrintReverse() &lt;/p&gt;&lt;p align="left"&gt;{&lt;br /&gt;Node current = new Node();&lt;br /&gt;current = FindLast();&lt;br /&gt;while (!(current.Blink == null)) &lt;/p&gt;&lt;p align="left"&gt;{&lt;br /&gt;Console.WriteLine(current.Element);&lt;br /&gt;current = current.Blink;&lt;br /&gt;}&lt;br /&gt;}&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-1638571256144794605?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/1638571256144794605/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=1638571256144794605' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/1638571256144794605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/1638571256144794605'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2009/01/doubly-link-list-implementation-in-c.html' title='Doubly Link List Implementation in C#'/><author><name>Ankur Sharma</name><uri>http://www.blogger.com/profile/12373031815995005939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_x_e5Xjb8ARI/SOkBIfJ4krI/AAAAAAAAA0I/E6Wdbft0I1A/S220/DSC03622.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_x_e5Xjb8ARI/SWxBF3zmVII/AAAAAAAAA44/BN2XnuzuRtk/s72-c/untitled2.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-4230523657521655510</id><published>2009-01-11T23:31:00.000-08:00</published><updated>2009-01-11T23:34:23.401-08:00</updated><title type='text'>How to write to an event log by using Visual C#</title><content type='html'>&lt;h3 id="tocHeadRef"&gt;&lt;span&gt;&lt;/span&gt;Requirements&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'summary');       &lt;/script&gt; The following list describes the recommended hardware, software, network  infrastructure, and service packs that you will need:  &lt;ul&gt;&lt;li&gt;Microsoft Windows 2000 Professional, Windows 2000 Server, Windows 2000  Advanced Server, or Windows NT 4.0 Server &lt;/li&gt;&lt;li&gt;Microsoft Visual Studio C#&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;h3 id="tocHeadRef"&gt;&lt;span&gt;&lt;/span&gt;Write to an event log&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'summary');       &lt;/script&gt; Event logging provides a standard, centralized way for your applications to  record important software and hardware events. Windows supplies a standard user  interface for viewing the logs, the Event Viewer. By using the common language's  run-time &lt;b&gt;EventLog&lt;/b&gt; component, you can connect to existing event logs  easily, on both local and remote computers, and write entries to these logs. You  can also read entries from existing logs and create your own custom event logs.  In its simplest form, writing to an event log involves only a few steps to  create a sample application. To do this, follow these steps:  &lt;ol&gt;&lt;li&gt;Open Visual Studio C#. &lt;/li&gt;&lt;li&gt;Create a new Console application in Visual C#. The Console application  creates a public class and an empty &lt;b&gt;Main&lt;/b&gt; method for you. &lt;/li&gt;&lt;li&gt;Verify that the project references at least the System.dll file. &lt;/li&gt;&lt;li&gt;Use the &lt;b&gt;using&lt;/b&gt; directive on the &lt;b&gt;System&lt;/b&gt; and  &lt;b&gt;System.Diagnostics&lt;/b&gt; namespaces so that you do not have to qualify  declarations from these namespaces later in your code. You must use these  statements before any other declarations.  &lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre style="color: rgb(204, 102, 0);" class="code"&gt;using System;&lt;br /&gt;using System.Diagnostics;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class="kb_codebody"&gt;&lt;div class="kb_codecontent"&gt;&lt;pre class="code"&gt;To write to an event log, you must have several pieces of information: Your&lt;br /&gt;message, the name of the log you to which you want to write (which will be&lt;br /&gt;created if it does not already exist), and a string that represents the source&lt;br /&gt;of the event. You can register a particular source with only a single event log;&lt;br /&gt;if you want to write messages to more than one log, you must define multiple&lt;br /&gt;sources.&lt;br /&gt;&lt;/pre&gt;&lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre style="color: rgb(204, 102, 0);" class="code"&gt;string sSource;&lt;br /&gt;string sLog;&lt;br /&gt;string sEvent;&lt;br /&gt;&lt;br /&gt;sSource = "dotNET Sample App";&lt;br /&gt;sLog = "Application";&lt;br /&gt;sEvent = "Sample Event";&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class="kb_codebody"&gt;&lt;div class="kb_codecontent"&gt;&lt;div class="kb_codebody"&gt;&lt;div class="kb_codecontent"&gt;&lt;pre class="code"&gt;Use two static methods of the &lt;b&gt;EventLog&lt;/b&gt; class to check whether your source&lt;br /&gt;exists, and then, if the source does not exist, to create this source that is&lt;br /&gt;associated with a particular event log. If the log name that you specify does&lt;br /&gt;not exist, the name is created automatically when you write your first entry to&lt;br /&gt;the log. By default, if you do not supply a log name to the&lt;br /&gt;&lt;b&gt;CreateEventSource&lt;/b&gt; method, the log file is named "Application Log."&lt;br /&gt;&lt;/pre&gt;&lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre style="color: rgb(204, 102, 0);" class="code"&gt;if (!EventLog.SourceExists(sSource))&lt;br /&gt; EventLog.CreateEventSource(sSource,sLog);&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class="kb_codebody"&gt;&lt;div class="kb_codecontent"&gt;&lt;div class="kb_codebody"&gt;&lt;div class="kb_codecontent"&gt;&lt;div class="kb_codebody"&gt;&lt;div class="kb_codecontent"&gt;&lt;ol&gt;&lt;li&gt;To write a message to an event log, you can use the  &lt;b&gt;EventLog.WriteEntry&lt;/b&gt; static method. This method has several different  overloaded versions. The following sample code shows the simplest method, which  takes a source string and your message, and one of the more complex methods,  which supports specifying the event ID and event type: &lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;EventLog.WriteEntry(sSource,sEvent);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Warning,  234);&lt;/span&gt;&lt;br /&gt;     &lt;/pre&gt;&lt;/div&gt;&lt;/div&gt; &lt;/li&gt;&lt;li&gt;Save your application. Run your application, and then check the Application  log in the Event Viewer to see your new events.&lt;/li&gt;&lt;/ol&gt;&lt;span style="font-weight: bold;"&gt;Complete code listing&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class="kb_codebody"&gt;&lt;div class="kb_codecontent"&gt;&lt;div class="kb_codebody"&gt;&lt;div class="kb_codecontent"&gt;&lt;div class="kb_codebody"&gt;&lt;div class="kb_codecontent"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;pre class="code"&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;using System;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;using System.Diagnostics;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;namespace WriteToAnEventLog_csharp&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt; /// Summary description for Class1.&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt; class Class1&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;  static void Main(string[] args)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;  {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;   string sSource;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;   string sLog;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;   string sEvent;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;   sSource = "dotNET Sample App";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;   sLog = "Application";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;   sEvent = "Sample Event";&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;   if (!EventLog.SourceExists(sSource))&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;    EventLog.CreateEventSource(sSource,sLog);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;   EventLog.WriteEntry(sSource,sEvent);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;   EventLog.WriteEntry(sSource, sEvent,&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;    EventLogEntryType.Warning, 234);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;  }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt; }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;    &lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="code"&gt;&lt;br /&gt;   &lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="code"&gt;&lt;br /&gt;   &lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-4230523657521655510?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/4230523657521655510/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=4230523657521655510' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/4230523657521655510'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/4230523657521655510'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2009/01/how-to-write-to-event-log-by-using.html' title='How to write to an event log by using Visual C#'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-1282886459785269591</id><published>2009-01-11T23:22:00.000-08:00</published><updated>2009-01-11T23:24:00.673-08:00</updated><title type='text'>Web Farming with the  Network Load Balancing Service  in Windows Server 2003</title><content type='html'>Goto this link&lt;br /&gt;&lt;br /&gt;http://www.west-wind.com/presentations/loadbalancing/networkloadbalancingwindows2003.asp&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-1282886459785269591?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/1282886459785269591/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=1282886459785269591' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/1282886459785269591'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/1282886459785269591'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2009/01/web-farming-with-network-load-balancing.html' title='Web Farming with the  Network Load Balancing Service  in Windows Server 2003'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-8459065863097340956</id><published>2009-01-11T23:15:00.000-08:00</published><updated>2009-01-11T23:18:15.212-08:00</updated><title type='text'>How to turn on remote debugging for Visual Studio 2005 in Windows XP with Service Pack 2</title><content type='html'>The Windows Firewall feature in Windows XP SP2 includes significant enhancements  over the earlier the Internet Connection Firewall (ICF) feature. These  enhancements help protect the computer from attack by malicious users or by  malicious software such as viruses. By default, Windows Firewall is turned on  for all network connections including connections to the Internet.   &lt;h3 id="tocHeadRef"&gt;Turn on remote debugging&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'summary');       &lt;/script&gt; To turn on remote debugging in Windows XP with SP2, you must configure Windows  Firewall as follows:  &lt;ul&gt;&lt;li&gt;If Windows Firewall is in "shielded" mode, you must perform the appropriate  actions so that Windows Firewall is no longer in "shielded" mode. &lt;/li&gt;&lt;li&gt;If Windows Firewall is on, you must open some ports. You must also grant  some permissions to Microsoft Visual Studio 2005 and to other executable  programs that are used in remote debugging. &lt;/li&gt;&lt;li&gt;If Windows Firewall is off, you may not have to configure a firewall. &lt;/li&gt;&lt;li&gt;Additionally, if the user who runs Microsoft Visual Studio 2005 does not  have Administrator user rights on the remote computer, you must configure the  DCOM settings on the computer that is running Visual Studio 2005.&lt;/li&gt;&lt;/ul&gt;To  turn on remote debugging, you must have Administrator user rights on the  computer that is running Visual Studio 2005. These instructions are only for  Internet Protocol version 4 (IPV4) based network settings.  &lt;div class="topOfPage"&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=3068650074752359005&amp;amp;postID=8459065863097340956#top"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt; &lt;h3 id="tocHeadRef"&gt;Configure DCOM on the computer that is running Visual Studio  2005&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'summary');       &lt;/script&gt; &lt;b&gt;Note&lt;/b&gt; After you make changes by using the DCOM Configuration tool  (Dcomcnfg.exe), you must restart the computer for the changes to take effect.  &lt;ol&gt;&lt;li&gt;At a command prompt, type &lt;span class="userInput"&gt;dcomcnfg&lt;/span&gt;, and then  press ENTER. Component Services opens. &lt;/li&gt;&lt;li&gt;In Component Services, expand &lt;strong class="uiterm"&gt;Component  Services&lt;/strong&gt;, expand &lt;strong class="uiterm"&gt;Computers&lt;/strong&gt;, and then  expand &lt;strong class="uiterm"&gt;My Computer&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;On the toolbar, click &lt;strong class="uiterm"&gt;Configure My Computer&lt;/strong&gt;.  The &lt;strong class="uiterm"&gt;My Computer&lt;/strong&gt; dialog box  appears.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; If you cannot click &lt;strong class="uiterm"&gt;Configure  My Computer&lt;/strong&gt;, go to the "&lt;span&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=3068650074752359005&amp;amp;postID=8459065863097340956#a"&gt;Remove and then re-install  the MSDTC service&lt;/a&gt;&lt;/span&gt;" section. &lt;/li&gt;&lt;li&gt;&lt;span&gt;&lt;/span&gt;In the &lt;strong class="uiterm"&gt;My Computer&lt;/strong&gt;  dialog box, click the &lt;strong class="uiterm"&gt;COM Security&lt;/strong&gt; tab. &lt;/li&gt;&lt;li&gt;Under &lt;strong class="uiterm"&gt;Access Permission&lt;/strong&gt;, click &lt;strong class="uiterm"&gt;Edit Limits&lt;/strong&gt;. The &lt;strong class="uiterm"&gt;Access  Permission&lt;/strong&gt; dialog box appears. &lt;/li&gt;&lt;li&gt;Under &lt;strong class="uiterm"&gt;Group or user names&lt;/strong&gt;, click &lt;strong class="uiterm"&gt;ANONYMOUS LOGON&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;Under &lt;strong class="uiterm"&gt;Permissions for ANONYMOUS LOGON&lt;/strong&gt;, click  to select the &lt;strong class="uiterm"&gt;Remote Access&lt;/strong&gt; check box, and then  click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;.&lt;/li&gt;&lt;/ol&gt; &lt;h4 id="tocHeadRef"&gt;&lt;span&gt;&lt;/span&gt;Remove and then re-install the MSDTC  service&lt;/h4&gt; &lt;script type="text/javascript"&gt;       loadTOCNode(3, 'summary');     &lt;/script&gt; If you cannot click &lt;strong class="uiterm"&gt;Configure My Computer&lt;/strong&gt; that is  described in step 3 in the "Configure DCOM on the computer that is running  Visual Studio 2005" section, follow these steps.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Important&lt;/b&gt; This  section, method, or task contains steps that tell you how to modify the  registry. However, serious problems might occur if you modify the registry  incorrectly. Therefore, make sure that you follow these steps carefully. For  added protection, back up the registry before you modify it. Then, you can  restore the registry if a problem occurs. For more information about how to back  up and restore the registry, click the following article number to view the  article in the Microsoft Knowledge Base:  &lt;div class="indent"&gt;&lt;a class="KBlink" href="http://www.blogger.com/kb/322756/"&gt;322756&lt;/a&gt;  &lt;span class="pLink"&gt;(http://support.microsoft.com/kb/322756/ ) &lt;/span&gt;How to back up and  restore the registry in Windows&lt;/div&gt; &lt;ol&gt;&lt;li&gt;Remove the Microsoft Distributed Transaction Service (MSDTC):  &lt;ol&gt;&lt;li type="a"&gt;Click &lt;strong class="uiterm"&gt;Start&lt;/strong&gt;, click &lt;strong class="uiterm"&gt;Run&lt;/strong&gt;, type &lt;span class="userInput"&gt;cmd&lt;/span&gt;, and then click  &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. &lt;/li&gt;&lt;li type="a"&gt;At the command prompt, run the following command to stop the MSDTC  service:  &lt;div class="indent"&gt;&lt;b&gt;Net stop msdtc&lt;/b&gt;&lt;/div&gt; &lt;/li&gt;&lt;li type="a"&gt;At the command prompt, run the following command to remove the MSDTC  service:  &lt;div class="indent"&gt;&lt;b&gt;Msdtc –uninstall&lt;/b&gt;&lt;/div&gt;The command prompt will return  without a message.&lt;/li&gt;&lt;/ol&gt; &lt;/li&gt;&lt;li&gt;In Registry Editor, delete the HKEY_LOCAL_MACHINE\Software\Microsoft\MSDTC  subkey. &lt;/li&gt;&lt;li&gt;Re-install and then start the MSDTC service:  &lt;ol&gt;&lt;li type="a"&gt;At the command prompt, run the following command to re-install the  MSDTC service:  &lt;div class="indent"&gt;&lt;b&gt;Msdtc –install&lt;/b&gt;&lt;/div&gt; &lt;/li&gt;&lt;li type="a"&gt;At the command prompt, run the following command to start the MSDTC  service:  &lt;div class="indent"&gt;&lt;b&gt;Net start msdtc&lt;/b&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt; &lt;/li&gt;&lt;li&gt;Go to &lt;span&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=3068650074752359005&amp;amp;postID=8459065863097340956#b"&gt;step 4&lt;/a&gt;&lt;/span&gt; in the "Configure DCOM on the  computer that is running Visual Studio 2005" section.&lt;/li&gt;&lt;/ol&gt;  &lt;h3 id="tocHeadRef"&gt;&lt;span&gt;&lt;/span&gt;Configure the computer that is  running Visual Studio 2005&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'summary');       &lt;/script&gt;  &lt;h4 id="tocHeadRef"&gt;Open Windows Firewall&lt;/h4&gt; &lt;script type="text/javascript"&gt;       loadTOCNode(3, 'summary');     &lt;/script&gt; To open Windows Firewall, click &lt;strong class="uiterm"&gt;Start&lt;/strong&gt;, click  &lt;strong class="uiterm"&gt;Run&lt;/strong&gt;, type &lt;span class="userInput"&gt;firewall.cpl&lt;/span&gt;, and then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;.  &lt;h4 id="tocHeadRef"&gt;Open TCP port 135&lt;/h4&gt; &lt;script type="text/javascript"&gt;       loadTOCNode(3, 'summary');     &lt;/script&gt; DCOM remote procedure call (RPC) uses Transfer Control Protocol (TCP) port 135.  If the application uses DCOM to communicate with remote computers, port 135 must  be open.&lt;br /&gt;&lt;br /&gt;To open TCP port 135, follow these steps:  &lt;ol&gt;&lt;li&gt;In Windows Firewall, click &lt;strong class="uiterm"&gt;Add Port&lt;/strong&gt; on the  &lt;strong class="uiterm"&gt;Exceptions&lt;/strong&gt; tab. The &lt;strong class="uiterm"&gt;Add a  Port&lt;/strong&gt; dialog box appears. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Name&lt;/strong&gt; box, type &lt;span class="userInput"&gt;TCP port 135&lt;/span&gt;. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Port Number&lt;/strong&gt; box, type &lt;span class="userInput"&gt;135&lt;/span&gt;. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Protocol&lt;/strong&gt; area, click &lt;strong class="uiterm"&gt;TCP&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;Click &lt;strong class="uiterm"&gt;Change scope&lt;/strong&gt; to open &lt;strong class="uiterm"&gt;Change Scope&lt;/strong&gt; dialog box, click &lt;strong class="uiterm"&gt;My  network (subnet) only&lt;/strong&gt;, and then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;.  (This step is optional.) &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Add a Port&lt;/strong&gt; dialog box, click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;.&lt;/li&gt;&lt;/ol&gt; &lt;h4 id="tocHeadRef"&gt;Open UDP port 4500&lt;/h4&gt; &lt;script type="text/javascript"&gt;       loadTOCNode(3, 'summary');     &lt;/script&gt; User Datagram Protocol (UDP) port 4500 is used for Internet Protocol security  (IPsec). If your domain policy requires that all network communication be  completed through IPsec, this port must be open for any network operation. If  your domain policy does not require IPsec, go to the "&lt;span&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=3068650074752359005&amp;amp;postID=8459065863097340956#3"&gt;Turn on  file and print sharing&lt;/a&gt;&lt;/span&gt;" section.&lt;br /&gt;&lt;br /&gt;To open UDP port 4500, follow  these steps:  &lt;ol&gt;&lt;li&gt;In Windows Firewall, click &lt;strong class="uiterm"&gt;Add Port&lt;/strong&gt; on the  &lt;strong class="uiterm"&gt;Exceptions&lt;/strong&gt; tab. The &lt;strong class="uiterm"&gt;Add a  Port&lt;/strong&gt; dialog box appears. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Name&lt;/strong&gt; box, type &lt;span class="userInput"&gt;UDP port 4500&lt;/span&gt;. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Port Number&lt;/strong&gt; box, type &lt;span class="userInput"&gt;4500&lt;/span&gt;. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Protocol&lt;/strong&gt; area, click &lt;strong class="uiterm"&gt;UDP&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;Click &lt;strong class="uiterm"&gt;Change scope&lt;/strong&gt;. The &lt;strong class="uiterm"&gt;Change Scope&lt;/strong&gt; dialog box appears. Click &lt;strong class="uiterm"&gt;My network (subnet) only&lt;/strong&gt;, and then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. (This step is optional.) &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Add a Port&lt;/strong&gt; dialog box, click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;.&lt;/li&gt;&lt;/ol&gt; &lt;h4 id="tocHeadRef"&gt;&lt;span&gt;&lt;/span&gt;Open UDP port 500&lt;/h4&gt; &lt;script type="text/javascript"&gt;       loadTOCNode(3, 'summary');     &lt;/script&gt; UDP port 500 is used for IPsec. If your domain policy requires that all network  communication be completed through IPsec, this port must be open for any network  operation. If your domain policy does not require IPsec, go to the "&lt;span&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=3068650074752359005&amp;amp;postID=8459065863097340956#3"&gt;Turn on file and print sharing&lt;/a&gt;&lt;/span&gt;" section.&lt;br /&gt;&lt;br /&gt;To open UDP  port 500, follow these steps:  &lt;ol&gt;&lt;li&gt;In Windows Firewall, click &lt;strong class="uiterm"&gt;Add Port&lt;/strong&gt; on the  &lt;strong class="uiterm"&gt;Exceptions&lt;/strong&gt; tab. The &lt;strong class="uiterm"&gt;Add a  Port&lt;/strong&gt; dialog box appears. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Name&lt;/strong&gt; box, type &lt;span class="userInput"&gt;UDP port 500&lt;/span&gt;. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Port Number&lt;/strong&gt; box, type &lt;span class="userInput"&gt;500&lt;/span&gt;. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Protocol&lt;/strong&gt; area, click &lt;strong class="uiterm"&gt;UDP&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;Click &lt;strong class="uiterm"&gt;Change scope&lt;/strong&gt;. The &lt;strong class="uiterm"&gt;Change Scope&lt;/strong&gt; dialog box appears. Click &lt;strong class="uiterm"&gt;My network (subnet) only&lt;/strong&gt;, and then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. (This step is optional.) &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Add a Port&lt;/strong&gt; dialog box, click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;.&lt;/li&gt;&lt;/ol&gt; &lt;h4 id="tocHeadRef"&gt;&lt;span&gt;&lt;/span&gt;Turn on file and print sharing&lt;/h4&gt; &lt;script type="text/javascript"&gt;       loadTOCNode(3, 'summary');     &lt;/script&gt;  &lt;ol&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Programs and Services&lt;/strong&gt; area of the  &lt;strong class="uiterm"&gt;Exceptions&lt;/strong&gt; tab, click &lt;strong class="uiterm"&gt;File  and Print Sharing&lt;/strong&gt;, and then click &lt;strong class="uiterm"&gt;Edit&lt;/strong&gt;.  The &lt;strong class="uiterm"&gt;Edit a Service&lt;/strong&gt; dialog box appears. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Edit a Service&lt;/strong&gt; dialog box, click to  select the following check boxes:  &lt;ul&gt;&lt;li&gt;TCP 139 &lt;/li&gt;&lt;li&gt;TCP 445 &lt;/li&gt;&lt;li&gt;UDP 137 &lt;/li&gt;&lt;li&gt;UDP 138&lt;/li&gt;&lt;/ul&gt; &lt;/li&gt;&lt;li&gt;Click &lt;strong class="uiterm"&gt;Change scope&lt;/strong&gt;. The &lt;strong class="uiterm"&gt;Change Scope&lt;/strong&gt; dialog box appears. Click &lt;strong class="uiterm"&gt;My network (subnet) only&lt;/strong&gt;, and then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. (This step is optional.) &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Change Scope&lt;/strong&gt; dialog box, click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt; to save your settings. &lt;/li&gt;&lt;li&gt;Click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt; to close the &lt;strong class="uiterm"&gt;Edit a Service&lt;/strong&gt; dialog box.&lt;/li&gt;&lt;/ol&gt; &lt;h4 id="tocHeadRef"&gt;Add Devenv.exe to the application exceptions list&lt;/h4&gt; &lt;script type="text/javascript"&gt;       loadTOCNode(3, 'summary');     &lt;/script&gt; To enable applications that cannot run correctly unless the required ports are  opened dynamically at runtime, you must add the applications to the application  exceptions list.&lt;br /&gt;&lt;br /&gt;To add the Visual Studio 2005 Development Environment  (Devenv.exe) to the application exceptions list, follow these steps:  &lt;ol&gt;&lt;li&gt;In Windows Firewall, click &lt;strong class="uiterm"&gt;Add Program&lt;/strong&gt; on the  &lt;strong class="uiterm"&gt;Exceptions&lt;/strong&gt; tab. The &lt;strong class="uiterm"&gt;Add a  Program&lt;/strong&gt; dialog box appears. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Add a Program&lt;/strong&gt; dialog box, click &lt;strong class="uiterm"&gt;Browse&lt;/strong&gt;. Locate &lt;strong class="uiterm"&gt;Devenv.exe&lt;/strong&gt;,  and then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; The  Devenv.exe file is typically located in the following folder:  &lt;div class="indent"&gt;C:\Program Files\Microsoft Visual Studio  8\Common7\IDE&lt;/div&gt;&lt;strong class="uiterm"&gt;Microsoft Visual Studio 2005&lt;/strong&gt;  appears in the &lt;strong class="uiterm"&gt;Add a Program&lt;/strong&gt; dialog box. &lt;/li&gt;&lt;li&gt;Click &lt;strong class="uiterm"&gt;Change scope&lt;/strong&gt;. The &lt;strong class="uiterm"&gt;Change Scope&lt;/strong&gt; dialog box appears. Click &lt;strong class="uiterm"&gt;My network (subnet) only&lt;/strong&gt;, and then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. (This step is optional.) &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Add a Program&lt;/strong&gt; dialog box, click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;In Windows Firewall, click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt; to save your  settings.&lt;/li&gt;&lt;/ol&gt;  &lt;h3 id="tocHeadRef"&gt;Configure the remote computer&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'summary');       &lt;/script&gt; All the ports that you have opened on the debugger computer must also be open on  the remote computer. To open the TCP 135 port, the UDP 4500 port, and the UDP  500 port, and to turn on file and print sharing, follow the steps in the ""  section.&lt;br /&gt;&lt;br /&gt;You must also add the Msvsmon.exe file to the application  exceptions list.  &lt;h4 id="tocHeadRef"&gt;Add MSVSMon.exe to the application exceptions list&lt;/h4&gt; &lt;script type="text/javascript"&gt;       loadTOCNode(3, 'summary');     &lt;/script&gt;  &lt;ol&gt;&lt;li&gt;In Windows Firewall, click &lt;strong class="uiterm"&gt;Add Program&lt;/strong&gt; on the  &lt;strong class="uiterm"&gt;Exceptions&lt;/strong&gt; tab. The &lt;strong class="uiterm"&gt;Add a  Program&lt;/strong&gt; dialog box appears. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Add a Program&lt;/strong&gt; dialog box, click &lt;strong class="uiterm"&gt;Browse&lt;/strong&gt;. Locate &lt;strong class="uiterm"&gt;Msvsmon.exe&lt;/strong&gt;,  and then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; Depending on  the computer architecture, the Msvsmon.exe file may be located in any one of the  following folders:  &lt;ul&gt;&lt;li&gt;&lt;var&gt;Drive&lt;/var&gt;:\Program Files\Microsoft Visual Studio 8\Common7\IDE\Remote  Debugger\x86 &lt;/li&gt;&lt;li&gt;&lt;var&gt;Drive&lt;/var&gt;:\Program Files\Microsoft Visual Studio 8\Common7\IDE\Remote  Debugger\x64 &lt;/li&gt;&lt;li&gt;&lt;var&gt;Drive&lt;/var&gt;:\Program Files\Microsoft Visual Studio 8\Common7\IDE\Remote  Debugger\ia64&lt;/li&gt;&lt;/ul&gt;&lt;strong class="uiterm"&gt;Visual Studio 2005 Remote  Debugger&lt;/strong&gt; appears in the &lt;strong class="uiterm"&gt;Add a Program&lt;/strong&gt;  dialog box.  &lt;/li&gt;&lt;li&gt;Click &lt;strong class="uiterm"&gt;Change scope&lt;/strong&gt;. The &lt;strong class="uiterm"&gt;Change Scope&lt;/strong&gt; dialog box appears. Click &lt;strong class="uiterm"&gt;My network (subnet) only&lt;/strong&gt;, and then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. (This step is optional.) &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Add a Program&lt;/strong&gt; dialog box, click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;In Windows Firewall, click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt; to save your  settings.&lt;/li&gt;&lt;/ol&gt; &lt;h4 id="tocHeadRef"&gt;Enable Web server debugging&lt;/h4&gt; &lt;script type="text/javascript"&gt;       loadTOCNode(3, 'summary');     &lt;/script&gt; HTTP uses TCP port 80. To do Web-based debugging, you must open TCP port 80.  This is true for Microsoft ASP.NET debugging, for classic ASP debugging, and for  ATL Server debugging.&lt;br /&gt;&lt;br /&gt;To open TCP port 80, follow these steps:  &lt;ol&gt;&lt;li&gt;In Windows Firewall, click &lt;strong class="uiterm"&gt;Add Port&lt;/strong&gt; on the  &lt;strong class="uiterm"&gt;Exceptions&lt;/strong&gt; tab. The &lt;strong class="uiterm"&gt;Add a  Port&lt;/strong&gt; dialog box appears. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Name&lt;/strong&gt; box, type &lt;span class="userInput"&gt;TCP port 80&lt;/span&gt;. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Port Number&lt;/strong&gt; box, type &lt;span class="userInput"&gt;80&lt;/span&gt;. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Protocol&lt;/strong&gt; area, click &lt;strong class="uiterm"&gt;TCP&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;Click &lt;strong class="uiterm"&gt;Change scope&lt;/strong&gt;. The &lt;strong class="uiterm"&gt;Change Scope&lt;/strong&gt; dialog box appears. Click &lt;strong class="uiterm"&gt;My network (subnet) only&lt;/strong&gt;, and then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. (This step is optional.) &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Add a Port&lt;/strong&gt; dialog box, click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;In Windows Firewall, click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt; to save your  settings.&lt;/li&gt;&lt;/ol&gt; &lt;h4 id="tocHeadRef"&gt;Enable script debugging&lt;/h4&gt; &lt;script type="text/javascript"&gt;       loadTOCNode(3, 'summary');     &lt;/script&gt; To debug script code that runs on a remote computer, you must add the process  that hosts the script code to the application exceptions list. Typically, in  classic ASP debugging, the &lt;b&gt;Dllhost.exe&lt;/b&gt; process or the &lt;b&gt;Inetinfo.exe&lt;/b&gt;  process hosts the script code. However, for a script that runs in Microsoft  Internet Explorer, the &lt;b&gt;Iexplore.exe&lt;/b&gt; process or in the &lt;b&gt;Explorer.exe&lt;/b&gt;  process generally hosts the script code.&lt;br /&gt;&lt;br /&gt;To add the process that hosts  the script code to the application exceptions list, follow these steps:  &lt;ol&gt;&lt;li&gt;Click &lt;strong class="uiterm"&gt;Start&lt;/strong&gt;, click &lt;strong class="uiterm"&gt;Run&lt;/strong&gt;, type &lt;span class="userInput"&gt;firewall.cpl&lt;/span&gt;, and  then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;In Windows Firewall, click &lt;strong class="uiterm"&gt;Add Program&lt;/strong&gt; on the  &lt;strong class="uiterm"&gt;Exceptions&lt;/strong&gt; tab. The &lt;strong class="uiterm"&gt;Add a  Program&lt;/strong&gt; dialog box appears. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Add a Program&lt;/strong&gt; dialog box, click &lt;strong class="uiterm"&gt;Browse&lt;/strong&gt;. Locate the process that hosts the script code, and  then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. The application of the process that  hosts the script code appears in the &lt;strong class="uiterm"&gt;Add a Program&lt;/strong&gt;  dialog box.&lt;br /&gt;&lt;br /&gt;For example, if you locate the &lt;strong class="uiterm"&gt;iexplore.exe&lt;/strong&gt; process in this step, &lt;strong class="uiterm"&gt;Internet Explorer&lt;/strong&gt; appears in the &lt;strong class="uiterm"&gt;Add  a Program&lt;/strong&gt; dialog box. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Scope&lt;/strong&gt; area, click &lt;strong class="uiterm"&gt;My network (subnet) only&lt;/strong&gt;. (This step is optional.) &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Add a Program&lt;/strong&gt; dialog box, click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;In Windows Firewall, click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt; to save your  settings.&lt;/li&gt;&lt;/ol&gt; &lt;h4 id="tocHeadRef"&gt;Run the debugger as a typical user&lt;/h4&gt; &lt;script type="text/javascript"&gt;       loadTOCNode(3, 'summary');     &lt;/script&gt; If you want to run the debugger as a typical user, you must have full user  rights to the folder where the executable files are located. Additionally, if  you do not have Administrator user rights on the remote computer, you must have  access permissions and start permissions to run the debugger as a typical user.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; A typical user is a user who does not have Administrator  user rights.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; After you make changes by using the DCOM  Configuration tool (Dcomcnfg.exe), you must restart the computer for the changes  to take effect.&lt;br /&gt;&lt;br /&gt;To grant access permissions and start permissions, you  must have Administrator user rights. First, obtain Administrator user rights.  Then, follow these steps:  &lt;ol&gt;&lt;li&gt;At a command prompt, type &lt;span class="userInput"&gt;dcomcnfg&lt;/span&gt;, and then  press ENTER. Component Services opens. &lt;/li&gt;&lt;li&gt;In Component Services, expand &lt;strong class="uiterm"&gt;Component  Services&lt;/strong&gt;, expand &lt;strong class="uiterm"&gt;Computers&lt;/strong&gt;, and then  expand &lt;strong class="uiterm"&gt;My Computer&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;On the toolbar, click &lt;strong class="uiterm"&gt;Configure My Computer&lt;/strong&gt;.  The &lt;strong class="uiterm"&gt;My Computer&lt;/strong&gt; dialog box  appears.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; If you cannot click &lt;strong class="uiterm"&gt;Configure  My Computer&lt;/strong&gt;, go to the "&lt;span&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=3068650074752359005&amp;amp;postID=8459065863097340956#c"&gt;Remove and then re-install  the MSDTC service&lt;/a&gt;&lt;/span&gt;" section. &lt;/li&gt;&lt;li&gt;&lt;span&gt;&lt;/span&gt;In the &lt;strong class="uiterm"&gt;My Computer&lt;/strong&gt;  dialog box, click the &lt;strong class="uiterm"&gt;COM Security&lt;/strong&gt; tab. &lt;/li&gt;&lt;li&gt;Under &lt;strong class="uiterm"&gt;Launch and Activate Permissions&lt;/strong&gt;, click  &lt;strong class="uiterm"&gt;Edit Limits&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;If your group or user name does not appear in the &lt;strong class="uiterm"&gt;Groups or user names&lt;/strong&gt; list in the &lt;strong class="uiterm"&gt;Launch Permission&lt;/strong&gt; dialog box, follow these steps:  &lt;ol&gt;&lt;li type="a"&gt;In the &lt;strong class="uiterm"&gt;Launch Permission&lt;/strong&gt; dialog box,  click &lt;strong class="uiterm"&gt;Add&lt;/strong&gt;. &lt;/li&gt;&lt;li type="a"&gt;In the &lt;strong class="uiterm"&gt;Select Users or Groups&lt;/strong&gt; dialog  box, enter your user name and your group in the &lt;strong class="uiterm"&gt;Enter the  object names to select&lt;/strong&gt; box, and then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;.&lt;/li&gt;&lt;/ol&gt; &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Launch Permission&lt;/strong&gt; dialog box, select  your user name and your group in the &lt;strong class="uiterm"&gt;Group or user  names&lt;/strong&gt; box. &lt;/li&gt;&lt;li&gt;In the &lt;strong class="uiterm"&gt;Allow&lt;/strong&gt; column under &lt;strong class="uiterm"&gt;Permissions for &lt;var&gt;User&lt;/var&gt;&lt;/strong&gt;, select &lt;strong class="uiterm"&gt;Remote Activation&lt;/strong&gt;, and then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note &lt;/b&gt;&lt;var&gt;User&lt;/var&gt; is a placeholder  for the user name or the group that is selected in the &lt;strong class="uiterm"&gt;Group or user names&lt;/strong&gt; box. Repeat steps 7 and 8 for all the  users and groups for which you want to grant permissions.&lt;/li&gt;&lt;/ol&gt; &lt;h4 id="tocHeadRef"&gt;&lt;span&gt;&lt;/span&gt;Remove and then re-install the MSDTC  service&lt;/h4&gt; &lt;script type="text/javascript"&gt;       loadTOCNode(3, 'summary');     &lt;/script&gt; If you cannot click &lt;strong class="uiterm"&gt;Configure My Computer&lt;/strong&gt; that is  described in step 3 in the "Run the debugger as a typical user" section, follow  these steps.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Important&lt;/b&gt; This section, method, or task contains  steps that tell you how to modify the registry. However, serious problems might  occur if you modify the registry incorrectly. Therefore, make sure that you  follow these steps carefully. For added protection, back up the registry before  you modify it. Then, you can restore the registry if a problem occurs. For more  information about how to back up and restore the registry, click the following  article number to view the article in the Microsoft Knowledge Base:  &lt;div class="indent"&gt;&lt;a class="KBlink" href="http://www.blogger.com/kb/322756/"&gt;322756&lt;/a&gt;  &lt;span class="pLink"&gt;(http://support.microsoft.com/kb/322756/ ) &lt;/span&gt;How to back up and  restore the registry in Windows&lt;/div&gt; &lt;ol&gt;&lt;li&gt;Remove the MSDTC service:  &lt;ol&gt;&lt;li type="a"&gt;Click &lt;strong class="uiterm"&gt;Start&lt;/strong&gt;, click &lt;strong class="uiterm"&gt;Run&lt;/strong&gt;, type &lt;span class="userInput"&gt;cmd&lt;/span&gt;, and then click  &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. &lt;/li&gt;&lt;li type="a"&gt;At the command prompt, run the following command to stop the MSDTC  service:  &lt;div class="indent"&gt;&lt;b&gt;Net stop msdtc&lt;/b&gt;&lt;/div&gt; &lt;/li&gt;&lt;li type="a"&gt;At the command prompt, run the following command to remove the MSDTC  service:  &lt;div class="indent"&gt;&lt;b&gt;Msdtc –uninstall&lt;/b&gt;&lt;/div&gt;The command prompt will return  without a message.&lt;/li&gt;&lt;/ol&gt; &lt;/li&gt;&lt;li&gt;In Registry Editor, delete the HKEY_LOCAL_MACHINE\Software\Microsoft\MSDTC  subkey. &lt;/li&gt;&lt;li&gt;Re-install and then start the MSDTC service:  &lt;ol&gt;&lt;li type="a"&gt;At the command prompt, run the following command to re-install the  MSDTC service:  &lt;div class="indent"&gt;&lt;b&gt;Msdtc –install&lt;/b&gt;&lt;/div&gt; &lt;/li&gt;&lt;li type="a"&gt;At the command prompt, run the following command to start the MSDTC  service:  &lt;div class="indent"&gt;&lt;b&gt;Net start msdtc&lt;/b&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt; &lt;/li&gt;&lt;li&gt;Go to &lt;span&gt;&lt;a href="http://www.blogger.com/post-edit.g?blogID=3068650074752359005&amp;amp;postID=8459065863097340956#d"&gt;step 4&lt;/a&gt;&lt;/span&gt; in the "Run the debugger as a  typical user" section.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;MORE INFORMATION&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;For more information about Windows Firewall, click the following article number  to view the article in the Microsoft Knowledge Base:  &lt;div class="indent"&gt;&lt;a class="KBlink" href="http://www.blogger.com/kb/843090/"&gt;843090&lt;/a&gt;  &lt;span class="pLink"&gt;(http://support.microsoft.com/kb/843090/ ) &lt;/span&gt;Description of the  Windows Firewall feature in Windows XP Service Pack 2 &lt;/div&gt;For more information  about Windows XP SP2, visit the following Microsoft Developer Network (MSDN) Web  site: &lt;div class="indent"&gt;&lt;a href="http://msdn2.microsoft.com/en-us/security/aa570371.aspx"&gt;http://msdn2.microsoft.com/en-us/security/aa570371.aspx&lt;/a&gt;&lt;span class="pLink"&gt; (http://msdn2.microsoft.com/en-us/security/aa570371.aspx)  &lt;/span&gt;&lt;/div&gt;For more information about remote debugging, click the following  article number to view the article in the Microsoft Knowledge Base:  &lt;div class="indent"&gt;&lt;a class="KBlink" href="http://www.blogger.com/kb/833977/"&gt;833977&lt;/a&gt;  &lt;span class="pLink"&gt;(http://support.microsoft.com/kb/833977/ ) &lt;/span&gt;How to turn on  remote debugging in Windows XP with Service Pack 2 &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-8459065863097340956?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/8459065863097340956/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=8459065863097340956' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/8459065863097340956'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/8459065863097340956'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2009/01/how-to-turn-on-remote-debugging-for.html' title='How to turn on remote debugging for Visual Studio 2005 in Windows XP with Service Pack 2'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-324286669068239041</id><published>2009-01-11T23:09:00.000-08:00</published><updated>2009-01-11T23:13:29.942-08:00</updated><title type='text'>How To Create an ASP.NET HTTP Handler by Using Visual C# .NET</title><content type='html'>&lt;h3 id="tocHeadRef"&gt;&lt;span&gt;&lt;/span&gt;Implement the Handler&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'moreinformation');       &lt;/script&gt;  &lt;ol&gt;&lt;li&gt;Open Microsoft Visual Studio .NET. In Visual C# .NET, create a new Class  Library project named MyHandler. &lt;/li&gt;&lt;li&gt;Set a reference to the &lt;b&gt;System.Web.dll&lt;/b&gt; assembly. &lt;/li&gt;&lt;li&gt;Add the following directive to the class.&lt;/li&gt;&lt;/ol&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;using System.Web;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;4. Rename the class SyncHandler.cs, and then change the class definition to  reflect this.&lt;br /&gt;5.Implement the &lt;b&gt;IHttpHandler&lt;/b&gt; interface. Your class definition should  appear as follows:&lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;public class SyncHandler : IHttpHandler&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;6. Implement the &lt;b&gt;IsReusable&lt;/b&gt; property and the &lt;b&gt;ProcessRequest&lt;/b&gt; method of  the &lt;b&gt;IHttpHandler&lt;/b&gt; interface. Because this is a synchronous handler, return  &lt;b&gt;False&lt;/b&gt; for the &lt;b&gt;IsReusable&lt;/b&gt; property so that the handler is not  pooled.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;public bool IsReusable &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt; get&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt; {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;return false;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;} &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;}  &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;public void ProcessRequest(HttpContext context)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt; { &lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;   context.Response.Write("Hello from custom handler.");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt; }  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;7. Compile the project.&lt;br /&gt;&lt;br /&gt;&lt;h3 id="tocHeadRef"&gt;&lt;span&gt;&lt;/span&gt;Deploy the Handler&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'moreinformation');       &lt;/script&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Create a new directory named Handler under the C:\Inetpub\Wwwroot directory. &lt;/li&gt;&lt;li&gt;Create a subdirectory named Bin in the newly created Handler directory. The  resultant path is C:\Inetpub\Wwwroot\Handler\Bin. &lt;/li&gt;&lt;li&gt;Copy MyHandler.dll from your project's Bin\Debug directory to the  C:\Inetpub\Wwwroot\Handler\Bin directory. &lt;/li&gt;&lt;li&gt;Follow these steps to mark the new Handler directory as a Web application: &lt;ol&gt;&lt;li type="a"&gt;Open Internet Services Manager. &lt;/li&gt;&lt;li type="a"&gt;Right-click the Handler directory, and then click &lt;b&gt;Properties&lt;/b&gt;. &lt;/li&gt;&lt;li type="a"&gt;On the &lt;b&gt;Directory&lt;/b&gt; tab, click &lt;b&gt;Create&lt;/b&gt;.&lt;/li&gt;&lt;/ol&gt; &lt;/li&gt;&lt;li&gt;Follow these steps to create an application mapping for the handler. For  this handler, create a mapping to the Aspnet_isapi.dll file for the *.sync  extension. Whenever a .sync file is requested, the request is routed to ASP.NET,  and ASP.NET executes the code in the handler. &lt;ol&gt;&lt;li type="a"&gt;Right-click on the Handler Web application, and then click  &lt;b&gt;Properties&lt;/b&gt;. &lt;/li&gt;&lt;li type="a"&gt;On the &lt;b&gt;Directory&lt;/b&gt; tab, click &lt;b&gt;Configuration&lt;/b&gt;. &lt;/li&gt;&lt;li type="a"&gt;Click &lt;b&gt;Add&lt;/b&gt; to add a new mapping. &lt;/li&gt;&lt;li type="a"&gt;In the &lt;b&gt;Executable&lt;/b&gt; text box, type the following path: Microsoft  Windows 2000:  &lt;div class="indent"&gt;C:\WINNT\Microsoft.NET\Framework\&lt;version#&gt;\Aspnet_isapi.dll  &lt;/div&gt;Microsoft Windows XP:  &lt;div class="indent"&gt;C:\WINDOWS\Microsoft.NET\Framework\&lt;version#&gt;\Aspnet_isapi.dll  &lt;/div&gt; &lt;/li&gt;&lt;li type="a"&gt;In the &lt;b&gt;Extension&lt;/b&gt; text box, type &lt;span class="userInput"&gt;.sync&lt;/span&gt;. &lt;/li&gt;&lt;li type="a"&gt;Make sure that the &lt;strong class="uiterm"&gt;Check that file  exists&lt;/strong&gt; check box is cleared, and then click &lt;b&gt;OK&lt;/b&gt; to close the  &lt;b&gt;Add/Edit Application Extension Mapping&lt;/b&gt; dialog box. &lt;/li&gt;&lt;li type="a"&gt;Click &lt;b&gt;OK&lt;/b&gt; to close the &lt;b&gt;Application Configuration&lt;/b&gt; and the  &lt;b&gt;Handler Properties&lt;/b&gt; dialog boxes.&lt;/li&gt;&lt;/ol&gt; &lt;/li&gt;&lt;li&gt;Close Internet Services Manager.&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;h3 id="tocHeadRef"&gt;&lt;span&gt;&lt;/span&gt;Configure the System&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'moreinformation');       &lt;/script&gt; &lt;ol&gt;&lt;li&gt;In the C:\Inetpub\Wwwroot\Handler directory, create a new file named  Web.config. &lt;/li&gt;&lt;li&gt;Add the following code to Web.config: &lt;/li&gt;&lt;/ol&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;&lt;configuration&gt;    &lt;system.web&gt;       &lt;httphandlers&gt;          &lt;add verb="*" path="*.sync" type="MyHandler.SyncHandler, MyHandler"&gt;       &lt;/httphandlers&gt;    &lt;/system.web&gt; &lt;/configuration&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the &lt;b&gt;verb="*"&lt;/b&gt; attribute, we instruct the handler to process a request  that uses any verb (for example, POST, HEAD, GET, and so on). If you want this  handler to process only the POST request, change this to  &lt;b&gt;verb="POST"&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;In the &lt;b&gt;path="*.sync"&lt;/b&gt; attribute, we instruct  the handler to process any incoming requests for files with the .sync  extension.&lt;br /&gt;&lt;br /&gt;In the &lt;b&gt;type="MyHandler.SyncHandler, MyHandler"&lt;/b&gt;  attribute, we instruct the handler that processes the request to implement in  the &lt;b&gt;MyHandler.SyncHandler&lt;/b&gt; namespace, and this class resides in the  &lt;b&gt;MyHandler&lt;/b&gt; assembly.&lt;br /&gt;&lt;br /&gt;&lt;h3 id="tocHeadRef"&gt;&lt;span&gt;&lt;/span&gt;Test the Module&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'moreinformation');       &lt;/script&gt; To test a handler, a page does not need to exist in the file system. For  example, request the Default.sync file in the Handler Web application  (http://&lt;computername&gt;/Handler/Default.sync). You should receive the  following results:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 102, 0);"&gt;Hello from custom handler.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-324286669068239041?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/324286669068239041/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=324286669068239041' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/324286669068239041'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/324286669068239041'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2009/01/how-to-create-aspnet-http-handler-by.html' title='How To Create an ASP.NET HTTP Handler by Using Visual C# .NET'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-3267312919980845704</id><published>2009-01-11T22:53:00.000-08:00</published><updated>2009-01-11T23:03:12.641-08:00</updated><title type='text'>How to use the Debug and the Trace classes</title><content type='html'>This article describes how to use the &lt;b&gt;Debug&lt;/b&gt; and the &lt;b&gt;Trace&lt;/b&gt; classes.  These classes are available in the Microsoft .NET Framework. You can use these  classes to provide information about the performance of an application either  during application development, or after deployment to production. These classes  are only one part of the instrumentation features that are available in the .NET  Framework.&lt;br /&gt;&lt;br /&gt;&lt;h3 id="tocHeadRef"&gt;&lt;span&gt;&lt;/span&gt;Requirements&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'summary');       &lt;/script&gt; The following list outlines the recommended hardware, software, network  infrastructure, and service packs that you need:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Microsoft Windows 2000 or Microsoft Windows XP or Microsoft Windows Server  2003 &lt;/li&gt;&lt;li&gt;Microsoft Visual C#&lt;/li&gt;&lt;/ul&gt;This article also assumes that you are familiar  with program debugging.&lt;br /&gt;&lt;br /&gt;&lt;h3 id="tocHeadRef"&gt;Description Of Technique&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'summary');       &lt;/script&gt;&lt;br /&gt;The steps in the &lt;span&gt;&lt;a href="#5"&gt;Create a Sample with the Debug Class  &lt;/a&gt;&lt;/span&gt;section demonstrate how to create a console application that uses the  &lt;b&gt;Debug&lt;/b&gt; class to provide information about the program execution. &lt;br /&gt;&lt;br /&gt;When the program is run, you can use methods of the &lt;b&gt;Debug&lt;/b&gt; class  to produce messages that help you to monitor the program execution sequence, to  detect malfunctions, or to provide performance measurement information. By  default, the messages that the &lt;b&gt;Debug&lt;/b&gt; class produces appear in the Output  window of the Visual Studio Integrated Development Environment (IDE). &lt;br /&gt;&lt;br /&gt;The sample code uses the &lt;b&gt;WriteLine&lt;/b&gt; method to produce a message  that is followed by a line terminator. When you use this method to produce a  message, each message appears on a separate line in the Output window. &lt;br /&gt;&lt;br /&gt;When you use the &lt;b&gt;Assert&lt;/b&gt; method of the &lt;b&gt;Debug&lt;/b&gt; class, the  Output window displays a message only if a specified condition evaluates to  false. The message also appears in a modal dialog box to the user. The dialog  box includes the message, the project name, and the &lt;b&gt;Debug.Assert&lt;/b&gt;  statement number. The dialog box also includes the following three command  buttons:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;strong class="uiterm"&gt;Abort: &lt;/strong&gt;The application stops running.  &lt;/li&gt;&lt;li&gt;&lt;strong class="uiterm"&gt;Retry: &lt;/strong&gt;The application enters debug mode.  &lt;/li&gt;&lt;li&gt;&lt;strong class="uiterm"&gt;Ignore: &lt;/strong&gt;The application proceeds.&lt;/li&gt;&lt;/ul&gt;The  user must click one of these buttons before the application can continue. &lt;br /&gt;&lt;br /&gt;You can also direct output from the &lt;b&gt;Debug&lt;/b&gt; class to destinations  other than the Output window. The &lt;b&gt;Debug&lt;/b&gt; class has a collection named  &lt;b&gt;Listeners&lt;/b&gt; that includes &lt;b&gt;Listener&lt;/b&gt; objects.&lt;br /&gt;&lt;br /&gt;Each  &lt;b&gt;Listener&lt;/b&gt; object monitors &lt;b&gt;Debug&lt;/b&gt; output and directs the output to a  specified target.&lt;br /&gt;&lt;br /&gt;Each &lt;b&gt;Listener&lt;/b&gt; in the &lt;b&gt;Listener&lt;/b&gt; collection  receives any output that the &lt;b&gt;Debug&lt;/b&gt; class generates. Use the  &lt;b&gt;TextWriterTraceListener&lt;/b&gt; class to define &lt;b&gt;Listener&lt;/b&gt; objects. You can  specify the target for a &lt;b&gt;TextWriterTraceListener&lt;/b&gt; class through its  constructor.&lt;br /&gt;&lt;br /&gt;Some possible output targets include the following:  &lt;ul&gt;&lt;li&gt;The Console window by using the &lt;b&gt;System.Console.Out&lt;/b&gt; property. &lt;/li&gt;&lt;li&gt;A text (.txt) file by using the  &lt;b&gt;System.IO.File.CreateText("FileName.txt")&lt;/b&gt; statement. &lt;/li&gt;&lt;/ul&gt;After you  create a &lt;b&gt;TextWriterTraceListener&lt;/b&gt; object, you must add the object to the  &lt;b&gt;Debug.Listeners&lt;/b&gt; collection to receive Debug output&lt;br /&gt;&lt;br /&gt;&lt;h3 id="tocHeadRef"&gt;Create a Sample with the Debug Class&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'summary');       &lt;/script&gt;  &lt;ol&gt;&lt;li&gt;Start Visual Studio or Visual C# Express Edition.  &lt;/li&gt;&lt;li&gt;Create a new Visual C# Console Application project named &lt;span class="userInput"&gt;conInfo&lt;/span&gt;. Class1 is created in Visual Studio .NET.  Program.cs is created in Visual Studio 2005. &lt;/li&gt;&lt;li&gt;Add the following namespace at top in Class1 or Program.cs.&lt;/li&gt;&lt;/ol&gt;using System.Diagnostics;&lt;br /&gt;&lt;br /&gt;4.To initialize variables to contain information about a product, add the  following declaration statements to &lt;b&gt;Main&lt;/b&gt; method: &lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;string sProdName = "Widget";&lt;br /&gt;int iUnitQty = 100;&lt;br /&gt;double dUnitCost = 1.03;&lt;br /&gt;&lt;br /&gt;5.Specify the message that the class produces as the first input parameter of the&lt;br /&gt;&lt;b&gt;WriteLine&lt;/b&gt; method. Press the CTRL+ALT+O key combination to make sure that&lt;br /&gt;the Output window is visible.&lt;br /&gt;&lt;br /&gt;Debug.WriteLine("Debug Information-Product Starting ");&lt;br /&gt;&lt;br /&gt;6.For readability, use the &lt;b&gt;Indent&lt;/b&gt; method to indent subsequent messages in&lt;br /&gt;the Output window:&lt;br /&gt;&lt;/pre&gt;&lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;Debug.Indent();&lt;br /&gt;&lt;br /&gt;7.To display the content of selected variables, use the &lt;b&gt;WriteLine&lt;/b&gt; method as&lt;br /&gt;follows:&lt;br /&gt;&lt;/pre&gt;&lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;Debug.WriteLine("The product name is " + sProdName);&lt;br /&gt;Debug.WriteLine("The available units on hand are" + iUnitQty.ToString());&lt;br /&gt;&lt;br /&gt;8.You can also use the &lt;b&gt;WriteLine&lt;/b&gt; method to display the namespace and the&lt;br /&gt;class name for an existent object. For example, the following code displays the&lt;br /&gt;&lt;b&gt;System.Xml.XmlDocument&lt;/b&gt; namespace in the Output window:&lt;br /&gt;&lt;/pre&gt;&lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;System.Xml.XmlDocument oxml = new System.Xml.XmlDocument();&lt;br /&gt;&lt;br /&gt;9.To organize the output, you can include a category as an optional, second input&lt;br /&gt;parameter of the &lt;b&gt;WriteLine&lt;/b&gt; method. If you specify a category, the format&lt;br /&gt;of the Output window message is "category: message." For example, the first line&lt;br /&gt;of the following code displays "Field: The product name is Widget" in the Output&lt;br /&gt;window:&lt;br /&gt;&lt;/pre&gt;&lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;Debug.WriteLine("The product name is " + sProdName,"Field");&lt;br /&gt;Debug.WriteLine("The units on hand are" + iUnitQty,"Field");&lt;br /&gt;Debug.WriteLine("The per unit cost is" + dUnitCost.ToString(),"Field");&lt;br /&gt;Debug.WriteLine("Total Cost is  " + (iUnitQty * dUnitCost),"Calc");&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="code"&gt;&lt;br /&gt;Debug.WriteLine(oxml);&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="code"&gt;&lt;br /&gt;Debug.WriteLine("The per unit cost is " + dUnitCost.ToString());&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="code"&gt;10.The Output window can display messages only if a designated condition evaluates&lt;br /&gt;to true by using the &lt;b&gt;WriteLineIf&lt;/b&gt; method of the &lt;b&gt;Debug&lt;/b&gt; class. The&lt;br /&gt;condition to be evaluated is the first input parameter of the &lt;b&gt;WriteLineIf&lt;/b&gt;&lt;br /&gt;method. The second parameter of &lt;b&gt;WriteLineIf&lt;/b&gt; is the message that appears&lt;br /&gt;only if the condition in the first parameter evaluates to true.&lt;br /&gt;&lt;/pre&gt;&lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;Debug.WriteLineIf(iUnitQty &gt; 50, "This message WILL appear");&lt;br /&gt;&lt;br /&gt;11.&lt;br /&gt;&lt;/pre&gt;&lt;ol&gt;&lt;li&gt;Use the &lt;b&gt;Assert&lt;/b&gt; method of the &lt;b&gt;Debug&lt;/b&gt; class so that the Output  window displays the message only if a specified condition evaluates to false: &lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;Debug.Assert(dUnitCost &gt; 1, "Message will NOT appear");&lt;br /&gt;Debug.Assert(dUnitCost &lt; 1, "Message will appear since dUnitcost &lt; 1 is false");&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;pre class="code"&gt;Debug.WriteLineIf(iUnitQty &lt; 50, "This message will NOT appear");&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;12. Create the &lt;b&gt;TextWriterTraceListener&lt;/b&gt; objects for the Console window (tr1)  and for a text file named Output.txt (tr2), and then add each object to the  &lt;b&gt;Debug Listeners&lt;/b&gt; collection: &lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;TextWriterTraceListener tr1 = new TextWriterTraceListener(System.Console.Out);&lt;br /&gt;Debug.Listeners.Add(tr1);&lt;br /&gt;      &lt;br /&gt;TextWriterTraceListener tr2 = new TextWriterTraceListener(System.IO.File.CreateText("Output.txt"));&lt;br /&gt;&lt;br /&gt;13.For readability, use the &lt;b&gt;Unindent&lt;/b&gt; method to remove the indentation for&lt;br /&gt;subsequent messages that the &lt;b&gt;Debug&lt;/b&gt; class generates. When you use the&lt;br /&gt;&lt;b&gt;Indent&lt;/b&gt; and the &lt;b&gt;Unindent&lt;/b&gt; methods together, the reader can&lt;br /&gt;distinguish the output as group.&lt;br /&gt;&lt;/pre&gt;&lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;Debug.Unindent();&lt;br /&gt;Debug.WriteLine("Debug Information-Product Ending");&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="code"&gt;&lt;br /&gt;Debug.Listeners.Add(tr2);&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;14. To make sure that each &lt;b&gt;Listener&lt;/b&gt; object receives all its output, call the  &lt;b&gt;Flush&lt;/b&gt; method for the &lt;b&gt;Debug&lt;/b&gt; class buffers: &lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;Debug.Flush();&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;h3 id="tocHeadRef"&gt;Using the Trace Class &lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'summary');       &lt;/script&gt; You can also use the &lt;b&gt;Trace&lt;/b&gt; class to produce messages that monitor the  execution of an application. The &lt;b&gt;Trace&lt;/b&gt; and &lt;b&gt;Debug&lt;/b&gt; classes share  most of the same methods to produce output, including the following:  &lt;ul&gt;&lt;li&gt;&lt;strong class="uiterm"&gt;WriteLine&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong class="uiterm"&gt;WriteLineIf &lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong class="uiterm"&gt;Indent&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong class="uiterm"&gt;Unindent&lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong class="uiterm"&gt;Assert &lt;/strong&gt; &lt;/li&gt;&lt;li&gt;&lt;strong class="uiterm"&gt;Flush&lt;/strong&gt;&lt;/li&gt;&lt;/ul&gt;You can use the &lt;b&gt;Trace&lt;/b&gt;  and the &lt;b&gt;Debug&lt;/b&gt; classes separately or together in the same application. In  a Debug Solution Configuration project, both &lt;b&gt;Trace&lt;/b&gt; and &lt;b&gt;Debug&lt;/b&gt;  output are active. The project generates output from both of these classes to  all &lt;b&gt;Listener&lt;/b&gt; objects. However, a Release Solution Configuration project  only generates output from a &lt;b&gt;Trace&lt;/b&gt; class. The Release Solution  Configuration project ignores any &lt;b&gt;Debug&lt;/b&gt; class method invocations. &lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;Trace.WriteLine("Trace Information-Product Starting ");&lt;br /&gt;Trace.Indent();&lt;br /&gt;&lt;br /&gt;Trace.WriteLine("The product name is "+sProdName);&lt;br /&gt;Trace.WriteLine("The product name is"+sProdName,"Field" );&lt;br /&gt;Trace.WriteLineIf(iUnitQty &gt; 50, "This message WILL appear");&lt;br /&gt;Trace.Assert(dUnitCost &gt; 1, "Message will NOT appear");&lt;br /&gt;      &lt;br /&gt;Trace.Unindent();&lt;br /&gt;Trace.WriteLine("Trace Information-Product Ending");&lt;br /&gt;&lt;br /&gt;Trace.Flush();&lt;br /&gt;&lt;br /&gt;Console.ReadLine();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;h3 id="tocHeadRef"&gt;Verify That It Works&lt;/h3&gt; &lt;script type="text/javascript"&gt;         loadTOCNode(2, 'summary');       &lt;/script&gt;  &lt;ol&gt;&lt;li&gt;Make sure that &lt;b&gt;Debug&lt;/b&gt; is the current solution configuration.  &lt;/li&gt;&lt;li&gt;If the&lt;strong class="uiterm"&gt; Solution Explorer&lt;/strong&gt; window is not  visible, press the CTRL+ALT+L key combination to display this window. &lt;/li&gt;&lt;li&gt;Right-click &lt;strong class="uiterm"&gt;conInfo&lt;/strong&gt;, and then click &lt;strong class="uiterm"&gt;Properties&lt;/strong&gt;.  &lt;/li&gt;&lt;li&gt;In the left pane of the conInfo property page, under the &lt;strong class="uiterm"&gt;Configuration&lt;/strong&gt; folder, make sure that the arrow points to  &lt;strong class="uiterm"&gt;Debugging&lt;/strong&gt;.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; In Visual C# 2005  and in Visual C# 2005 Express Edition, click &lt;strong class="uiterm"&gt;Debug&lt;/strong&gt;  in the &lt;strong class="uiterm"&gt;conInfo&lt;/strong&gt; page. &lt;/li&gt;&lt;li&gt;Above the &lt;strong class="uiterm"&gt;Configuration&lt;/strong&gt; folder, in the &lt;strong class="uiterm"&gt;Configuration&lt;/strong&gt; drop-down list box, click &lt;strong class="uiterm"&gt;Active (Debug)&lt;/strong&gt; or &lt;strong class="uiterm"&gt;Debug&lt;/strong&gt;, and  then click &lt;strong class="uiterm"&gt;OK&lt;/strong&gt;. In Visual C# 2005 and in Visual C#  2005 Express Edition, click &lt;strong class="uiterm"&gt;Active (Debug)&lt;/strong&gt; or  &lt;strong class="uiterm"&gt;Debug&lt;/strong&gt; in the &lt;strong class="uiterm"&gt;Configuration&lt;/strong&gt; drop-down list box in the &lt;strong class="uiterm"&gt;Debug&lt;/strong&gt; page, and then click &lt;strong class="uiterm"&gt;Save&lt;/strong&gt; on the &lt;strong class="uiterm"&gt;File&lt;/strong&gt; menu. &lt;/li&gt;&lt;li&gt;Press CTRL+ALT+O to display the Output window. &lt;/li&gt;&lt;li&gt;Press the F5 key to run the code. When the &lt;strong class="uiterm"&gt;Assertion  Failed&lt;/strong&gt; dialog box appears, click &lt;strong class="uiterm"&gt;Ignore&lt;/strong&gt;. &lt;/li&gt;&lt;li&gt;In the Console window, press ENTER. The program should finish, and the  Output window should display the output that resembles the following &lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;    Debug Information-Product Starting&lt;br /&gt;   The product name is Widget&lt;br /&gt;   The available units on hand are100&lt;br /&gt;   The per unit cost is 1.03&lt;br /&gt;   System.Xml.XmlDocument&lt;br /&gt;   Field: The product name is Widget&lt;br /&gt;   Field: The units on hand are100&lt;br /&gt;   Field: The per unit cost is1.03&lt;br /&gt;   Calc: Total Cost is  103&lt;br /&gt;   This message WILL appear&lt;br /&gt;   ---- DEBUG ASSERTION FAILED ----&lt;br /&gt;---- Assert Short Message ----&lt;br /&gt;Message will appear since dUnitcost  &lt; 1 is false&lt;br /&gt;---- Assert Long Message ----&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;   at Class1.Main(String[] args)  &lt;%Path%&gt;\class1.cs(34)&lt;br /&gt;&lt;br /&gt;   The product name is Widget&lt;br /&gt;   The available units on hand are100&lt;br /&gt;   The per unit cost is 1.03&lt;br /&gt;Debug Information-Product Ending&lt;br /&gt;Trace Information-Product Starting&lt;br /&gt;   The product name is Widget&lt;br /&gt;   Field: The product name isWidget&lt;br /&gt;   This message WILL appear&lt;br /&gt;Trace Information-Product Ending&lt;br /&gt;                  &lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt; &lt;/li&gt;&lt;li&gt;The Console window and the Output.txt file should display the following  output: &lt;div class="kb_codebody"&gt; &lt;div class="kb_codecontent"&gt;&lt;code&gt;&lt;/code&gt;&lt;pre class="code"&gt;The product name is Widget&lt;br /&gt;   The available units on hand are 100&lt;br /&gt;   The per unit cost is 1.03&lt;br /&gt;Debug Information-Product Ending&lt;br /&gt;Trace Information-Product Starting&lt;br /&gt;   The product name is Widget&lt;br /&gt;   Field: The product name is Widget&lt;br /&gt;   This message WILL appear&lt;br /&gt;Trace Information-Product Ending   &lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;b&gt;Note&lt;/b&gt; The Output.txt file is located in  the same directory as the conInfo executable (conInfo.exe). Typically, this is  the \bin folder where the project source is stored. By default, this is  C:\Documents and Settings\&lt;var&gt;User login&lt;/var&gt;\My Documents\Visual Studio  Projects\conInfo\bin. In Visual C# 2005 and in Visual C# 2005 Express Edition,  the Output.txt file is located in the following folder: &lt;div class="indent"&gt;C:\Documents and Settings\&lt;var&gt;User login&lt;/var&gt;\My  Documents\Visual Studio 2005\Projects\conInfo\conInfo\bin\Debug&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Complete Code Listing&lt;/span&gt;&lt;br /&gt;using System;   &lt;br /&gt;using System.Diagnostics;&lt;br /&gt;&lt;br /&gt;class Class1   &lt;br /&gt;{&lt;br /&gt; [STAThread]&lt;br /&gt; static void Main(string[] args)      &lt;br /&gt;{&lt;br /&gt;string sProdName = "Widget";         &lt;br /&gt;int iUnitQty = 100;         &lt;br /&gt;double  dUnitCost = 1.03;&lt;br /&gt; Debug.WriteLine("Debug Information-Product Starting ");&lt;br /&gt; Debug.Indent();         &lt;br /&gt;Debug.WriteLine("The product name is "+sProdName);&lt;br /&gt; Debug.WriteLine("The available units on hand are"+iUnitQty.ToString());          Debug.WriteLine("The per unit cost is "+ dUnitCost.ToString());          &lt;br /&gt;&lt;br /&gt;System.Xml.XmlDocument oxml = new System.Xml.XmlDocument();         &lt;br /&gt;Debug.WriteLine(oxml);          &lt;br /&gt;Debug.WriteLine("The product name is "+sProdName,"Field");&lt;br /&gt; Debug.WriteLine("The units on hand are"+iUnitQty,"Field");&lt;br /&gt; Debug.WriteLine("The per unit cost is"+dUnitCost.ToString(),"Field");&lt;br /&gt; Debug.WriteLine("Total Cost is  "+(iUnitQty * dUnitCost),"Calc");          &lt;br /&gt;Debug.WriteLineIf(iUnitQty &gt; 50, "This message WILL appear");         &lt;br /&gt;Debug.WriteLineIf(iUnitQty &lt; 50, "This message will NOT appear");          &lt;br /&gt;Debug.Assert(dUnitCost &gt; 1, "Message will NOT appear");         &lt;br /&gt;Debug.Assert(dUnitCost &lt; 1, "Message will appear since dUnitcost  &lt; 1 is false");          &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;TextWriterTraceListener tr1 = new TextWriterTraceListener(System.Console.Out);          Debug.Listeners.Add(tr1);                  &lt;br /&gt;TextWriterTraceListener tr2 = new TextWriterTraceListener(System.IO.File.CreateText("Output.txt"));          Debug.Listeners.Add(tr2);                     &lt;br /&gt;Debug.WriteLine("The product name is "+sProdName);&lt;br /&gt; Debug.WriteLine("The available units on hand are"+iUnitQty);&lt;br /&gt; Debug.WriteLine("The per unit cost is "+dUnitCost);         &lt;br /&gt;Debug.Unindent();&lt;br /&gt; Debug.WriteLine("Debug Information-Product Ending");&lt;br /&gt; Debug.Flush();                   &lt;br /&gt;Trace.WriteLine("Trace Information-Product Starting ");&lt;br /&gt; Trace.Indent();          &lt;br /&gt;Trace.WriteLine("The product name is "+sProdName);&lt;br /&gt;&lt;br /&gt;        Trace.WriteLine("The product name is"+sProdName,"Field" );         &lt;br /&gt;Trace.WriteLineIf(iUnitQty &gt; 50, "This message WILL appear");         &lt;br /&gt;Trace.Assert(dUnitCost &gt; 1, "Message will NOT appear");                   &lt;br /&gt;Trace.Unindent();         &lt;br /&gt;Trace.WriteLine("Trace Information-Product Ending");          &lt;br /&gt;Trace.Flush();           Console.ReadLine();      &lt;br /&gt;}&lt;br /&gt; }&lt;br /&gt;&lt;/div&gt;&lt;pre class="code"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre class="code"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-3267312919980845704?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/3267312919980845704/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=3267312919980845704' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/3267312919980845704'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/3267312919980845704'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2009/01/how-to-use-debug-and-trace-classes.html' title='How to use the Debug and the Trace classes'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-2887550171968562340</id><published>2008-12-22T03:23:00.000-08:00</published><updated>2009-01-12T22:35:09.199-08:00</updated><title type='text'>Link List (How to develop with C#)</title><content type='html'>&lt;div style="TEXT-ALIGN: center"&gt;&lt;span style="font-family:verdana;font-size:130%;"&gt;&lt;span style="FONT-WEIGHT: bold"&gt;AN OBJECT-ORIENTED LINKED LIST DESIGN&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;div style="TEXT-ALIGN: left"&gt;Our design of a linked list will involve at least two classes.We’ll create a Node class and instantiate a Node object each time we add a node to the list. The nodes in the list are connected via references to other nodes. These references are set using methods created in a separate LinkedList class.Let’s start by looking at the design of the Node class.&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold;font-size:130%;" &gt;The Node Class&lt;/span&gt;&lt;br /&gt;&lt;div style="TEXT-ALIGN: left"&gt;A node is made up of two data members: Element, which stores the node’s data; and Link, which stores a reference to the next node in the list.We’ll use Object for the data type of Element, just so we don’t have to worry about what kind of data we store in the list. The data type for Link is Node, which seems strange but actually makes perfect sense. Since we want the link to point to the next node, and we use a reference to make the link, we have to assign a Node type to the link member.&lt;br /&gt;To finish up the definition of the Node class, we need at least two constructor methods. We definitely want a default constructor that creates an empty Node, with both the Element and Link members set to null. We also need a parametrized constructor that assigns data to the Element member and sets the Link member to null.&lt;br /&gt;Here’s the code for the Node class:&lt;br /&gt;&lt;div style="TEXT-ALIGN: left"&gt;&lt;br /&gt;public class Node&lt;br /&gt;{&lt;br /&gt;&lt;/div&gt;&lt;div style="TEXT-ALIGN: left"&gt;public Object Element;&lt;br /&gt;public Node Link;&lt;br /&gt;public Node()&lt;br /&gt;{&lt;br /&gt;Element = null;&lt;br /&gt;Link = null;&lt;br /&gt;}&lt;br /&gt;public Node(Object theElement)&lt;br /&gt;{&lt;br /&gt;Element = theElement;&lt;br /&gt;Link = null;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;div style="TEXT-ALIGN: left"&gt;&lt;span style="font-size:130%;"&gt;&lt;span style="FONT-WEIGHT: bold"&gt;The LinkedList Class&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;The LinkedList class is used to create the linkage for the nodes of our linked list. The class includes several methods for adding nodes to the list, removing nodes from the list, traversing the list, and finding a node in the list. We also need a constructor method that instantiates a list. The only data member in the class is the header node.&lt;br /&gt;&lt;br /&gt;public class LinkedList&lt;br /&gt;{&lt;br /&gt;protected Node header;&lt;br /&gt;public LinkedList()&lt;br /&gt;{&lt;br /&gt;header = new Node("header");&lt;br /&gt;}&lt;br /&gt;. . .&lt;br /&gt;} &lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;The header node starts out with its Link field set to null. When we add the first node to the list, the header node’s Link field is assigned a reference to the new node, and the new node’s Link field is assigned the null value.&lt;/p&gt;&lt;p align="center"&gt;&lt;strong&gt;To insert a new node after an existing node&lt;/strong&gt;&lt;/p&gt;&lt;p align="left"&gt;To do this, we create a Private method, Find, that searches through the Element field of each node until a match is found.&lt;/p&gt;&lt;p align="left"&gt;private Node Find(Object item)&lt;/p&gt;&lt;p align="left"&gt; {&lt;br /&gt;Node current = new Node();&lt;br /&gt;current = header;&lt;br /&gt;while(current.header != item)&lt;br /&gt;current = current.Link;&lt;br /&gt;return current;&lt;br /&gt;}&lt;/p&gt;&lt;p align="left"&gt;Once we’ve found the “after” node, the next step is to set the new node’s Link field to the Link field of the “after” node, and then set the “after” node’s Link field to a reference to the new node. Here’s how it’s done:&lt;/p&gt;&lt;p align="left"&gt;public void Insert(Object newItem, Object after) &lt;/p&gt;&lt;p align="left"&gt;{&lt;br /&gt;Node current = new Node();&lt;br /&gt;Node newNode = new Node(newItem);&lt;br /&gt;current = Find(after);&lt;/p&gt;&lt;p align="left"&gt;newNode.Link = current.Link;&lt;br /&gt;current.Link = newNode;&lt;br /&gt;}&lt;/p&gt;&lt;p align="center"&gt;&lt;br /&gt;&lt;strong&gt;Remove a node from a linked list&lt;/strong&gt;&lt;/p&gt;&lt;p align="left"&gt;we simply have to change the link of the node that points to the removed node to point to the node after the removed node.&lt;/p&gt;&lt;p align="left"&gt;private Node FindPrevious(Object n)&lt;/p&gt;&lt;p align="left"&gt;{&lt;br /&gt;Node current = header;&lt;br /&gt;while(!(current.Link == null) &amp;amp;&amp;amp; (current.Link.&lt;br /&gt;Element != n))&lt;br /&gt;current = current.Link;&lt;br /&gt;return current;&lt;br /&gt;}&lt;/p&gt;&lt;p align="left"&gt;Now we’re ready to see how the code for the Remove method looks:&lt;/p&gt;&lt;p align="left"&gt;public void Remove(Object n)&lt;/p&gt;&lt;p align="left"&gt;{&lt;br /&gt;Node p = FindPrevious(n);&lt;br /&gt;if (!(p.Link == null))&lt;br /&gt;p.Link = p.Link.Link;&lt;br /&gt;}&lt;/p&gt;&lt;p align="left"&gt;&lt;strong&gt;PrintList&lt;/strong&gt;&lt;/p&gt;&lt;p align="left"&gt;public void PrintList() &lt;/p&gt;&lt;p align="left"&gt;{&lt;br /&gt;Node current = new Node();&lt;br /&gt;current = header;&lt;br /&gt;while (!(current.Link == null)) &lt;/p&gt;&lt;p align="left"&gt;{&lt;br /&gt;Console.WriteLine(current.Link.Element);&lt;br /&gt;current = current.Link;&lt;br /&gt;}&lt;br /&gt;}&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-2887550171968562340?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/2887550171968562340/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=2887550171968562340' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/2887550171968562340'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/2887550171968562340'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/12/link-list-how-to-develop-with-c.html' title='Link List (How to develop with C#)'/><author><name>Ankur Sharma</name><uri>http://www.blogger.com/profile/12373031815995005939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_x_e5Xjb8ARI/SOkBIfJ4krI/AAAAAAAAA0I/E6Wdbft0I1A/S220/DSC03622.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-1410311824397298526</id><published>2008-12-22T02:11:00.000-08:00</published><updated>2008-12-22T03:21:57.701-08:00</updated><title type='text'>Link List (Howz it works)</title><content type='html'>A linked list is a collection of class objects called nodes. Each node is linked to its successor node in the list using a reference to the successor node. A node is made up of a field for storing data and the field for the node reference. The reference to another node is called a link. An example linked list is:&lt;br /&gt;&lt;div style="text-align: justify;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_x_e5Xjb8ARI/SU9xDDVjHTI/AAAAAAAAA4Y/Hd6q1MKcK7E/s1600-h/Link_List.PNG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 38px;" src="http://1.bp.blogspot.com/_x_e5Xjb8ARI/SU9xDDVjHTI/AAAAAAAAA4Y/Hd6q1MKcK7E/s320/Link_List.PNG" alt="" id="BLOGGER_PHOTO_ID_5282565185178115378" border="0" /&gt;&lt;/a&gt;A major difference between an array and a linked list is that whereas the elements in an array are referenced by position (the index), the elements of a linked list are referenced by their relationship to the other elements of the array. From above example we can say that “Bread” follows “Milk”, not that “Bread” is in the second position. Moving through a linked list involves following the links from the beginning node to the ending node.&lt;br /&gt;Another thing to notice that we mark the end of a linked list by pointing to the value null. Since we are working with class objects in memory, we use the null object to denote the end of the list.&lt;br /&gt;Marking the beginning of a list can be a problem in some cases. It is common in many linked list implementations to include a special node, called the “header”, to denote the beginning of a linked list. The linked list in underlying figure is redesigned with a header node:&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_x_e5Xjb8ARI/SU9zmY5NxfI/AAAAAAAAA4g/PxdmcDTFzQA/s1600-h/Link_List.PNG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 30px;" src="http://4.bp.blogspot.com/_x_e5Xjb8ARI/SU9zmY5NxfI/AAAAAAAAA4g/PxdmcDTFzQA/s320/Link_List.PNG" alt="" id="BLOGGER_PHOTO_ID_5282567991283533298" border="0" /&gt;&lt;/a&gt;&lt;div style="text-align: center; font-weight: bold;"&gt;&lt;span style="font-size:130%;"&gt;Insertion and Removal of an Item from Link List&lt;br /&gt;&lt;/span&gt;&lt;div style="text-align: left;"&gt;&lt;div style="text-align: left;"&gt;&lt;span style="font-weight: normal;"&gt;Insertion becomes a very efficient task when using a linked list. All that&lt;/span&gt; &lt;span style="font-weight: normal;"&gt;is involved is changing  the link of the node previous to the inserted node to&lt;/span&gt; &lt;span style="font-weight: normal;"&gt;point to the inserted node, and setting the link of the new node to point to&lt;/span&gt; &lt;span style="font-weight: normal;"&gt;the node the previous node pointed to before the insertion. In Figure&lt;span style="font-size:100%;"&gt; (below)&lt;/span&gt;&lt;/span&gt; &lt;span style="font-weight: normal;"&gt;the item “Cookies” is added to the linked list after “Eggs”.&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: left;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_x_e5Xjb8ARI/SU91nzqd4zI/AAAAAAAAA4o/t3sVXcsFPvU/s1600-h/Link_List.PNG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 52px;" src="http://2.bp.blogspot.com/_x_e5Xjb8ARI/SU91nzqd4zI/AAAAAAAAA4o/t3sVXcsFPvU/s320/Link_List.PNG" alt="" id="BLOGGER_PHOTO_ID_5282570214672556850" border="0" /&gt;&lt;/a&gt;&lt;div style="text-align: left; font-weight: normal;"&gt;Removing an item from a linked list is just as easy. We simply redirect the link of the node before the deleted node to point to the node the deleted node points to and set the deleted node’s link to null. The diagram (below) we remove “Bacon” from the linked list.&lt;br /&gt;&lt;div style="text-align: center;"&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_x_e5Xjb8ARI/SU93j110T6I/AAAAAAAAA4w/D3LMz0_YHqs/s1600-h/Link_List.PNG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 35px;" src="http://1.bp.blogspot.com/_x_e5Xjb8ARI/SU93j110T6I/AAAAAAAAA4w/D3LMz0_YHqs/s320/Link_List.PNG" alt="" id="BLOGGER_PHOTO_ID_5282572345560813474" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-1410311824397298526?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/1410311824397298526/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=1410311824397298526' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/1410311824397298526'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/1410311824397298526'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/12/link-list-howz-it-works.html' title='Link List (Howz it works)'/><author><name>Ankur Sharma</name><uri>http://www.blogger.com/profile/12373031815995005939</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_x_e5Xjb8ARI/SOkBIfJ4krI/AAAAAAAAA0I/E6Wdbft0I1A/S220/DSC03622.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_x_e5Xjb8ARI/SU9xDDVjHTI/AAAAAAAAA4Y/Hd6q1MKcK7E/s72-c/Link_List.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-5229534489538659333</id><published>2008-12-22T01:45:00.000-08:00</published><updated>2008-12-22T01:59:02.536-08:00</updated><title type='text'>Pointers and unsafe code in c#</title><content type='html'>&lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:100%;"&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;We will see that C# allows  suspending the verification of code by the CLR to allow developers to directly  access memory using pointers. Hence with C#, you can complete, in a standard  way, certain optimizations which were only possible within unmanaged development  environments such as C++. These optimizations concern, for example, the  processing of large amounts of data in memory such as bitmaps.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:100%;"&gt;&lt;strong&gt;Pointers  and unsafe code&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;C++ does not know the  notion of code management. This is one of the advantages of C++ as it allows the  use of pointers and thus allows developers to write optimized code which is  closer to the target machine.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;This is also a  disadvantage of C++ since the use of pointers is cumbersome and potentially  dangerous, significantly increasing the development effort and maintenance  required.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Before the .NET platform,  100% of the code executed on the Windows operating system was unmanaged. This  means the executable contains the code directly in machine instructions which  are compatible with the type of processor (i.e. machine language code). The  introduction of the managed execution mode with the .NET platform is  revolutionary. The main sources of hard to track bugs are detected and resolved  by the CLR. Amongst these:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;ul&gt;&lt;span&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Array access overflows  (Now dynamically managed by the CLR).&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Memory leaks (Now mostly  managed by the garbage collector).&lt;/span&gt;  &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The use of an invalid  pointer. This problem is solved in a radical way as the manipulation of pointers  if forbidden in managed mode.&lt;/span&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The CLR knows how to  manipulate three kinds of pointers:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;ul&gt;&lt;span&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;em&gt;Managed  pointers&lt;/em&gt;. These pointers can point to data contained in the object heap  managed by the garbage collector. These pointers are not used explicitly by the  C# code. They are thus used implicitly by the C# compiler when it compiles  methods with &lt;strong&gt;out&lt;/strong&gt; and &lt;strong&gt;ref&lt;/strong&gt;  arguments.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;em&gt;Unmanaged function  pointers&lt;/em&gt;. The pointers are conceptually close to the notion of delegate. We  will discuss them at the end of this article.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;em&gt;Unmanaged  pointers&lt;/em&gt;. These pointers can point to any data contained in the user  addressing space of the process. The C# language allows to use this type of  pointers in zones of code considered unsafe. The IL code emitted by the C#  compiler corresponding to the zones of code which use these unmanaged pointers  make use of specialized IL instructions. Their effect on the memory of the  process cannot be verified by the JIT compiler of the CLR. Consequently, a  malicious user can take advantage of unsafe code regions to accomplish malicious  actions. To counter this weakness, the CLR will only allow the execution of this  code at run-time if the code has the &lt;em&gt;SkipVerification&lt;/em&gt; CAS  meta-permission.&lt;/span&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Since it allows to  directly manipulating the memory of a process through the use of an unmanaged  pointer, unsafe code is particularly useful to optimize certain processes on  large amounts of data stored in structures.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Compilation  options to allow unsafe code&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Unsafe code must be used  on purpose and you must also provide the /unsafe option to the csc.exe compiler  to tell it that you are aware that the code you wish to compile contains zones  which will be seen as unverifiable by the JIT compiler. Visual Studio offers the  Build Allow unsafe code project property to indicate that you wish to use this  compiler option.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Declaring unsafe  code in C#&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;In C#, the unsafe keyword  lets the compiler know when you will use unsafe code. It can be used in three  situations:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;ul&gt;&lt;span&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Before the declaration of  a class or structure. In this case, all the methods of the type can use  pointers.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Before the declaration of  a method. In this case, the pointers can be used within the body of this method  and in its signature.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt; &lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Within the body of a  method (static or not). In this case, pointers are only allowed within the  marked block of code. For example:&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:100%;color:#0000ff;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:100%;color:#0000ff;"&gt;&lt;span style="font-size:85%;"&gt;unsafe&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;{&lt;br /&gt;...&lt;br /&gt;}&lt;/span&gt;&lt;/p&gt;&lt;/li&gt;&lt;/span&gt;&lt;/ul&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Let us mention that  if a method accepts at least one pointer as an argument or as a return value,  the method (or its class) must be marked as unsafe, but also all regions of code  calling this method must also be marked as unsafe.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:100%;"&gt;&lt;strong&gt;Using  pointers in C#&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Each object, whether it is  a value or reference type instance, has a memory address at which it is  physically located in the process. This address is not necessarily constant  during the lifetime of the object as the garbage collector can physically move  objects store in the heap.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;.NET types that support  pointers&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;For certain types, there  is a dual type, the unmanaged pointer type which corresponds to the managed  type. A pointer variable is in fact the address of an instance of the concerned  type. The set of types which authorizes the use of pointers limits itself to all  value types, with the exception of structures with at least one reference type  field. Consequently, only instances of the following types can be used through  pointers: primitive types; enumerations; structures with no reference type  fields; pointers.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Declaring pointers&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;A pointer might point to  nothing. In this case, it is &lt;em&gt;extremely important&lt;/em&gt; that its value should  be set to null (0). In fact, the majority of bugs due to pointers come from  pointers which are not null but which point to invalid data. The declaration of  a pointer on the FooType is done as follows:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;FooType * pointeur;  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;For  example:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:100%;color:#0000ff;"&gt; &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:100%;color:#0000ff;"&gt;&lt;span style="font-size:85%;"&gt;long&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:85%;"&gt; * pAnInteger =  0;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/span&gt; &lt;/span&gt;&lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Note that the  declaration...&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:100%;color:#0000ff;"&gt; &lt;/span&gt;&lt;p&gt;&lt;span style="font-size:100%;color:#0000ff;"&gt;&lt;span style="font-size:85%;"&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-size:85%;"&gt; *  p1,p2;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/span&gt; &lt;/span&gt;&lt;p&gt;&lt;span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;... makes it so that p1 is  a pointer on an integer and p2 is a pointer.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Now let's see the first program&lt;/p&gt; &lt;h2&gt;Program 1&lt;/h2&gt;&lt;br /&gt;&lt;pre id="pre0" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; iData = &lt;span class="code-digit"&gt;10&lt;/span&gt;;&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt;* pData = &amp;iData;&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Data is "&lt;/span&gt; + iData);&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Address is "&lt;/span&gt; + (&lt;span class="code-keyword"&gt;int&lt;/span&gt;)pData );&lt;br /&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Here I use a pointer in this program. Now compile this program. The compiler  gives the error&lt;/p&gt;&lt;p&gt;Now let's change the program a little bit and add unsafe modifier with the  function.&lt;/p&gt;&lt;p&gt;Program 2&lt;/p&gt;&lt;pre id="pre2" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; iData = &lt;span class="code-digit"&gt;10&lt;/span&gt;;&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt;* pData = &amp;iData;&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Data is "&lt;/span&gt; + iData);&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Address is "&lt;/span&gt; + (&lt;span class="code-keyword"&gt;int&lt;/span&gt;)pData );&lt;br /&gt; }&lt;br /&gt;Data is &lt;span class="code-digit"&gt;10&lt;/span&gt;&lt;br /&gt;Address is &lt;span class="code-digit"&gt;1244316&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;It is not necessary that we define the &lt;code&gt;unsafe&lt;/code&gt; modifier with the  function. We can define a block of unsafe code. Let's change a program little  bit more.&lt;/p&gt;&lt;h2&gt;Program 3&lt;/h2&gt; &lt;div class="SmallText" id="premain4" style="width: 100%;"&gt;&lt;span id="precollapse4" style="margin-bottom: 0px; cursor: pointer;" preid="4"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre id="pre4" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  unsafe {&lt;br /&gt;   &lt;span class="code-keyword"&gt;int&lt;/span&gt; iData = &lt;span class="code-digit"&gt;10&lt;/span&gt;;&lt;br /&gt;   &lt;span class="code-keyword"&gt;int&lt;/span&gt;* pData = &amp;iData;&lt;br /&gt;   Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Data is "&lt;/span&gt; + iData);&lt;br /&gt;   Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Address is "&lt;/span&gt; + (&lt;span class="code-keyword"&gt;int&lt;/span&gt;)pData );&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;p&gt;In this program a block is defined with &lt;code&gt;unsafe&lt;/code&gt; modifier. So we  can use pointers in that code. The output of this program is the same as  previous one.&lt;/p&gt; &lt;p&gt;Now let's change the program a little bit to get a value from the pointer.&lt;/p&gt;&lt;h2&gt;Program 4&lt;/h2&gt; &lt;pre id="pre5" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  unsafe {&lt;br /&gt;   &lt;span class="code-keyword"&gt;int&lt;/span&gt; iData = &lt;span class="code-digit"&gt;10&lt;/span&gt;;&lt;br /&gt;   &lt;span class="code-keyword"&gt;int&lt;/span&gt;* pData = &amp;iData;&lt;br /&gt;   Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Data is "&lt;/span&gt; + iData);&lt;br /&gt;   Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Data is "&lt;/span&gt; + pData-&lt;span class="code-keyword"&gt;&gt;&lt;/span&gt;ToString() );&lt;br /&gt;   Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Address is "&lt;/span&gt; + (&lt;span class="code-keyword"&gt;int&lt;/span&gt;)pData );&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;Program 5&lt;br /&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  testFun();&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; testFun() {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; iData = &lt;span class="code-digit"&gt;10&lt;/span&gt;;&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt;* pData = &amp;iData;&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Data is "&lt;/span&gt; + iData);&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Address is "&lt;/span&gt; + (&lt;span class="code-keyword"&gt;int&lt;/span&gt;)pData );&lt;br /&gt; }&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;In this program a function with &lt;code&gt;unsafe&lt;/code&gt; modifier is called from a  normal function. This program shows that a managed code can call unmanaged  functions. The output of the program is the same as previous program.&lt;/p&gt; &lt;p&gt;Now change the program little bit and make an unsafe function in another  class.&lt;/p&gt; &lt;h2&gt;Program 6&lt;/h2&gt;&lt;br /&gt;&lt;pre id="pre7" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  TestClass Obj = &lt;span class="code-keyword"&gt;new&lt;/span&gt; TestClass();&lt;br /&gt;  Obj.testFun();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; TestClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; testFun() {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; iData = &lt;span class="code-digit"&gt;10&lt;/span&gt;;&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt;* pData = &amp;iData;&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Data is "&lt;/span&gt; + iData);&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Address is "&lt;/span&gt; + (&lt;span class="code-keyword"&gt;int&lt;/span&gt;)pData );&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;The output of the program is same as previous one.&lt;/p&gt; &lt;p&gt;Now try to pass pointer as a parameter. Let’s see this program.&lt;/p&gt; &lt;h2&gt;Program 7&lt;/h2&gt;&lt;br /&gt;&lt;pre id="pre8" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  TestClass Obj = &lt;span class="code-keyword"&gt;new&lt;/span&gt; TestClass();&lt;br /&gt;  Obj.testFun();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; TestClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; testFun() {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; x = &lt;span class="code-digit"&gt;10&lt;/span&gt;;&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; y = &lt;span class="code-digit"&gt;20&lt;/span&gt;;&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Before swap x = "&lt;/span&gt; + x + &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt; y= "&lt;/span&gt; + y);&lt;br /&gt;  swap(&amp;amp;x, &amp;amp;y);&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;After swap x = "&lt;/span&gt; + x + &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt; y= "&lt;/span&gt; + y);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; swap(&lt;span class="code-keyword"&gt;int&lt;/span&gt;* p_x, &lt;span class="code-keyword"&gt;int&lt;/span&gt; *p_y) {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; temp = *p_x;&lt;br /&gt;  *p_x = *p_y;&lt;br /&gt;  *p_y = temp;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;In this program the unsafe function &lt;code&gt;testFun()&lt;/code&gt; calls the classic  &lt;code&gt;swap()&lt;/code&gt; function to interchange the value of two variables passing  by reference. Now change the program a little bit.&lt;/p&gt; &lt;h2&gt;Program 8&lt;/h2&gt;&lt;br /&gt;&lt;pre id="pre9" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  TestClass Obj = &lt;span class="code-keyword"&gt;new&lt;/span&gt; TestClass();&lt;br /&gt;  unsafe {&lt;br /&gt;   &lt;span class="code-keyword"&gt;int&lt;/span&gt; x = &lt;span class="code-digit"&gt;10&lt;/span&gt;;&lt;br /&gt;   &lt;span class="code-keyword"&gt;int&lt;/span&gt; y = &lt;span class="code-digit"&gt;20&lt;/span&gt;;&lt;br /&gt;   Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Before swap x = "&lt;/span&gt; + x + &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt; y= "&lt;/span&gt; + y);&lt;br /&gt;   Obj.swap(&amp;amp;x, &amp;amp;y);&lt;br /&gt;   Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;After swap x = "&lt;/span&gt; + x + &lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt; y= "&lt;/span&gt; + y);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; TestClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; swap(&lt;span class="code-keyword"&gt;int&lt;/span&gt;* p_x, &lt;span class="code-keyword"&gt;int&lt;/span&gt;* p_y) {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; temp = *p_x;&lt;br /&gt;  *p_x = *p_y;&lt;br /&gt;  *p_y = temp;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;This program does the same job as previous one. But in this program we write  only one unsafe function and call this function from the unsafe block in  &lt;code&gt;Main&lt;/code&gt;.  &lt;/p&gt;&lt;p&gt;Now let's see another program which show the usage of array in C#&lt;/p&gt; &lt;h2&gt;Program 9&lt;/h2&gt;&lt;br /&gt;&lt;pre id="pre10" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  TestClass Obj = &lt;span class="code-keyword"&gt;new&lt;/span&gt; TestClass();&lt;br /&gt;  Obj.fun();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; TestClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; fun() {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; [] iArray = &lt;span class="code-keyword"&gt;new&lt;/span&gt; &lt;span class="code-keyword"&gt;int&lt;/span&gt;[&lt;span class="code-digit"&gt;10&lt;/span&gt;];&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; store value in array&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;for&lt;/span&gt; (&lt;span class="code-keyword"&gt;int&lt;/span&gt; iIndex = &lt;span class="code-digit"&gt;0&lt;/span&gt;; iIndex &lt;span class="code-keyword"&gt;&lt;&lt;/span&gt; &lt;span class="code-digit"&gt;10&lt;/span&gt;; iIndex++) {&lt;br /&gt;   iArray[iIndex] = iIndex * iIndex;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; get value from array&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;for&lt;/span&gt; (&lt;span class="code-keyword"&gt;int&lt;/span&gt; iIndex = &lt;span class="code-digit"&gt;0&lt;/span&gt;; iIndex &lt;span class="code-keyword"&gt;&lt;&lt;/span&gt; &lt;span class="code-digit"&gt;10&lt;/span&gt;; iIndex++) {&lt;br /&gt;   Console.WriteLine(iArray[iIndex]);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;This program display the square of numbers from zero to 9.&lt;/p&gt; &lt;p&gt;Let's change the program a little bit and pass the array as a parameter to a  function.&lt;/p&gt; &lt;h2&gt;Program 10&lt;/h2&gt;&lt;br /&gt;&lt;pre id="pre11" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  TestClass Obj = &lt;span class="code-keyword"&gt;new&lt;/span&gt; TestClass();&lt;br /&gt;  Obj.fun();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; TestClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; fun() {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; [] iArray = &lt;span class="code-keyword"&gt;new&lt;/span&gt; &lt;span class="code-keyword"&gt;int&lt;/span&gt;[&lt;span class="code-digit"&gt;10&lt;/span&gt;];&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; store value in array&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;for&lt;/span&gt; (&lt;span class="code-keyword"&gt;int&lt;/span&gt; iIndex = &lt;span class="code-digit"&gt;0&lt;/span&gt;; iIndex &lt;span class="code-keyword"&gt;&lt;&lt;/span&gt; &lt;span class="code-digit"&gt;10&lt;/span&gt;; iIndex++) {&lt;br /&gt;   iArray[iIndex] = iIndex * iIndex;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  testFun(iArray);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; testFun(&lt;span class="code-keyword"&gt;int&lt;/span&gt; [] p_iArray) {&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; get value from array&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;for&lt;/span&gt; (&lt;span class="code-keyword"&gt;int&lt;/span&gt; iIndex = &lt;span class="code-digit"&gt;0&lt;/span&gt;; iIndex &lt;span class="code-keyword"&gt;&lt;&lt;/span&gt; &lt;span class="code-digit"&gt;10&lt;/span&gt;; iIndex++) {&lt;br /&gt;   Console.WriteLine(p_iArray[iIndex]);&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;The output of the program is same as previous one.&lt;/p&gt; &lt;p&gt;Now let's change the program a little bit and try to get the value of the  array from a pointer rather than an index.&lt;/p&gt; &lt;h2&gt;Program 11&lt;/h2&gt;&lt;br /&gt;&lt;pre id="pre12" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  TestClass Obj = &lt;span class="code-keyword"&gt;new&lt;/span&gt; TestClass();&lt;br /&gt;  Obj.fun();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; TestClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; fun() {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; [] iArray = &lt;span class="code-keyword"&gt;new&lt;/span&gt; &lt;span class="code-keyword"&gt;int&lt;/span&gt;[&lt;span class="code-digit"&gt;10&lt;/span&gt;];&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; store value in array&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;for&lt;/span&gt; (&lt;span class="code-keyword"&gt;int&lt;/span&gt; iIndex = &lt;span class="code-digit"&gt;0&lt;/span&gt;; iIndex &lt;span class="code-keyword"&gt;&lt;&lt;/span&gt; &lt;span class="code-digit"&gt;10&lt;/span&gt;; iIndex++) {&lt;br /&gt;   iArray[iIndex] = iIndex * iIndex;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; get value from array&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;for&lt;/span&gt; (&lt;span class="code-keyword"&gt;int&lt;/span&gt; iIndex = &lt;span class="code-digit"&gt;0&lt;/span&gt;; iIndex &lt;span class="code-keyword"&gt;&lt;&lt;/span&gt; &lt;span class="code-digit"&gt;10&lt;/span&gt;; iIndex++) {&lt;br /&gt;   Console.WriteLine(*(iArray + iIndex) );&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Here in this program we try to access the value of the array from  &lt;code&gt;*(iArray + iIndex)&lt;/code&gt; rather than &lt;code&gt;iArray[iIndex]&lt;/code&gt;. But the  program gives the following error.&lt;/p&gt;&lt;pre id="pre13" style="margin-top: 0px;"&gt;Microsoft (R) Visual C# Compiler Version &lt;span class="code-digit"&gt;7&lt;/span&gt;.&lt;span class="code-digit"&gt;00&lt;/span&gt;.&lt;span class="code-digit"&gt;9030&lt;/span&gt; [CLR version &lt;span class="code-digit"&gt;1&lt;/span&gt;.&lt;span class="code-digit"&gt;00&lt;/span&gt;.&lt;span class="code-digit"&gt;2204&lt;/span&gt;.&lt;span class="code-digit"&gt;21&lt;/span&gt;]&lt;br /&gt;Copyright (C) Microsoft Corp &lt;span class="code-digit"&gt;2000&lt;/span&gt;. All rights reserved.&lt;br /&gt;&lt;br /&gt;um11.cs(&lt;span class="code-digit"&gt;21&lt;/span&gt;,&lt;span class="code-digit"&gt;24&lt;/span&gt;): error CS0019: Operator &lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;+'&lt;/span&gt; cannot be applied to operands of type &lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;int[]'&lt;/span&gt; and &lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;int'&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt;In C# &lt;code&gt;&lt;span class="code-keyword"&gt;int&lt;/span&gt;*&lt;/code&gt; and &lt;code&gt;&lt;span class="code-keyword"&gt;in&lt;/span&gt;[]&lt;/code&gt; are not treated the same. To understand it  more let's see one more program.&lt;/p&gt;&lt;pre id="pre14" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  TestClass Obj = &lt;span class="code-keyword"&gt;new&lt;/span&gt; TestClass();&lt;br /&gt;  Obj.fun();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; TestClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; fun() {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; [] iArray = &lt;span class="code-keyword"&gt;new&lt;/span&gt; &lt;span class="code-keyword"&gt;int&lt;/span&gt;[&lt;span class="code-digit"&gt;10&lt;/span&gt;];&lt;br /&gt;  iArray++;&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt;* iPointer = (&lt;span class="code-keyword"&gt;int&lt;/span&gt;*)&lt;span class="code-digit"&gt;0&lt;/span&gt;;&lt;br /&gt;  iPointer++;&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;There are two different types of variable in this program. First, the  variable &lt;code&gt;iArray&lt;/code&gt; is declared an array and the second variable  &lt;code&gt;iPointer&lt;/code&gt; is a pointer variable. Now I am going to increment both.  We can increment the pointer variable because it is not fixed in memory but we  can't increment the &lt;code&gt;iArray&lt;/code&gt;, because the starting address of the  array is stored in &lt;code&gt;iArray&lt;/code&gt; and if we are allowed to increment this  then we will lose starting address of array. &lt;/p&gt; &lt;p&gt;The output of the program is an error.&lt;/p&gt;&lt;pre id="pre15" style="margin-top: 0px;"&gt;Microsoft (R) Visual C# Compiler Version &lt;span class="code-digit"&gt;7&lt;/span&gt;.&lt;span class="code-digit"&gt;00&lt;/span&gt;.&lt;span class="code-digit"&gt;9030&lt;/span&gt; [CLR version &lt;span class="code-digit"&gt;1&lt;/span&gt;.&lt;span class="code-digit"&gt;00&lt;/span&gt;.&lt;span class="code-digit"&gt;2204&lt;/span&gt;.&lt;span class="code-digit"&gt;21&lt;/span&gt;]&lt;br /&gt;Copyright (C) Microsoft Corp &lt;span class="code-digit"&gt;2000&lt;/span&gt;. All rights reserved.&lt;br /&gt;&lt;br /&gt;um12.cs(&lt;span class="code-digit"&gt;13&lt;/span&gt;,&lt;span class="code-digit"&gt;3&lt;/span&gt;): error CS0187: No such &lt;span class="code-keyword"&gt;operator&lt;/span&gt; &lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;++'&lt;/span&gt; defined &lt;span class="code-keyword"&gt;for&lt;/span&gt; type &lt;span class="code-string"&gt;'&lt;/span&gt;&lt;span class="code-string"&gt;int[]'&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;To access the element of the array via a pointer we have to fix the pointer  so it can't be incremented. C# uses the &lt;code&gt;fixed&lt;/code&gt; reserve word to do  this.&lt;/p&gt; &lt;h2&gt;Program 13&lt;/h2&gt;&lt;br /&gt;&lt;pre id="pre16" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  TestClass Obj = &lt;span class="code-keyword"&gt;new&lt;/span&gt; TestClass();&lt;br /&gt;  Obj.fun();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; TestClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; fun() {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; [] iArray = &lt;span class="code-keyword"&gt;new&lt;/span&gt; &lt;span class="code-keyword"&gt;int&lt;/span&gt;[&lt;span class="code-digit"&gt;10&lt;/span&gt;];&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; store value in array&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;for&lt;/span&gt; (&lt;span class="code-keyword"&gt;int&lt;/span&gt; iIndex = &lt;span class="code-digit"&gt;0&lt;/span&gt;; iIndex &lt;span class="code-keyword"&gt;&lt;&lt;/span&gt; &lt;span class="code-digit"&gt;10&lt;/span&gt;; iIndex++) {&lt;br /&gt;   iArray[iIndex] = iIndex * iIndex;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; get value from array&lt;br /&gt;&lt;/span&gt;  fixed(&lt;span class="code-keyword"&gt;int&lt;/span&gt;* pInt = iArray)&lt;br /&gt;  &lt;span class="code-keyword"&gt;for&lt;/span&gt; (&lt;span class="code-keyword"&gt;int&lt;/span&gt; iIndex = &lt;span class="code-digit"&gt;0&lt;/span&gt;; iIndex &lt;span class="code-keyword"&gt;&lt;&lt;/span&gt; &lt;span class="code-digit"&gt;10&lt;/span&gt;; iIndex++) {&lt;br /&gt;   Console.WriteLine(*(pInt + iIndex) );&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;We can use the same technique to pass the array to a function which receives  the pointer as a parameter.&lt;/p&gt; &lt;h2&gt;Program 14&lt;/h2&gt;&lt;br /&gt;&lt;pre id="pre17" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  TestClass Obj = &lt;span class="code-keyword"&gt;new&lt;/span&gt; TestClass();&lt;br /&gt;  Obj.fun();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; TestClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; fun() {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; [] iArray = &lt;span class="code-keyword"&gt;new&lt;/span&gt; &lt;span class="code-keyword"&gt;int&lt;/span&gt;[&lt;span class="code-digit"&gt;10&lt;/span&gt;];&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; store value in array&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;for&lt;/span&gt; (&lt;span class="code-keyword"&gt;int&lt;/span&gt; iIndex = &lt;span class="code-digit"&gt;0&lt;/span&gt;; iIndex &lt;span class="code-keyword"&gt;&lt;&lt;/span&gt; &lt;span class="code-digit"&gt;10&lt;/span&gt;; iIndex++) {&lt;br /&gt;   iArray[iIndex] = iIndex * iIndex;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; get value from array&lt;br /&gt;&lt;/span&gt;  fixed(&lt;span class="code-keyword"&gt;int&lt;/span&gt;* pInt = iArray)&lt;br /&gt;  testFun(pInt);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; testFun(&lt;span class="code-keyword"&gt;int&lt;/span&gt;* p_pInt) {&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-keyword"&gt;for&lt;/span&gt; (&lt;span class="code-keyword"&gt;int&lt;/span&gt; iIndex = &lt;span class="code-digit"&gt;0&lt;/span&gt;; iIndex &lt;span class="code-keyword"&gt;&lt;&lt;/span&gt; &lt;span class="code-digit"&gt;10&lt;/span&gt;; iIndex++) {&lt;br /&gt;   Console.WriteLine(*(p_pInt + iIndex) );&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;/pre&gt; &lt;p&gt;The output of the program is the same as the previous one. If we try to  access beyond the array limit then it will print garbage.&lt;/p&gt;Program 15&lt;br /&gt;&lt;pre id="pre18" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;  TestClass Obj = &lt;span class="code-keyword"&gt;new&lt;/span&gt; TestClass();&lt;br /&gt;  Obj.fun();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; TestClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; fun() {&lt;br /&gt;  &lt;span class="code-keyword"&gt;int&lt;/span&gt; [] iArray = &lt;span class="code-keyword"&gt;new&lt;/span&gt; &lt;span class="code-keyword"&gt;int&lt;/span&gt;[&lt;span class="code-digit"&gt;10&lt;/span&gt;];&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; store value in array&lt;br /&gt;&lt;/span&gt;  &lt;span class="code-keyword"&gt;for&lt;/span&gt; (&lt;span class="code-keyword"&gt;int&lt;/span&gt; iIndex = &lt;span class="code-digit"&gt;0&lt;/span&gt;; iIndex &lt;span class="code-keyword"&gt;&lt;&lt;/span&gt; &lt;span class="code-digit"&gt;10&lt;/span&gt;; iIndex++) {&lt;br /&gt;   iArray[iIndex] = iIndex * iIndex;&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; get value from array&lt;br /&gt;&lt;/span&gt;  fixed(&lt;span class="code-keyword"&gt;int&lt;/span&gt;* pInt = iArray)&lt;br /&gt;  testFun(pInt);&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;void&lt;/span&gt; testFun(&lt;span class="code-keyword"&gt;int&lt;/span&gt;* p_pInt) {&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-keyword"&gt;for&lt;/span&gt; (&lt;span class="code-keyword"&gt;int&lt;/span&gt; iIndex = &lt;span class="code-digit"&gt;0&lt;/span&gt;; iIndex &amp;amp;lt &lt;span class="code-digit"&gt;20&lt;/span&gt;; iIndex++) {&lt;br /&gt;   Console.WriteLine(*(p_pInt + iIndex) );&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Here we try to read 20 elements from array but there are only 10 elements in  the array so it will print garbage after printing the elements of array.&lt;/p&gt; &lt;h2&gt;Program 16&lt;/h2&gt;&lt;br /&gt;&lt;pre id="pre19" style="margin-top: 0px;"&gt;&lt;span class="code-keyword"&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;struct&lt;/span&gt; Point {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;int&lt;/span&gt; iX;&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; &lt;span class="code-keyword"&gt;int&lt;/span&gt; iY;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class="code-keyword"&gt;class&lt;/span&gt; MyClass {&lt;br /&gt; &lt;span class="code-keyword"&gt;public&lt;/span&gt; unsafe &lt;span class="code-keyword"&gt;static&lt;/span&gt; &lt;span class="code-keyword"&gt;void&lt;/span&gt; Main() {&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; reference of point&lt;br /&gt;&lt;/span&gt;  Point refPoint = &lt;span class="code-keyword"&gt;new&lt;/span&gt; Point();&lt;br /&gt;  refPoint.iX = &lt;span class="code-digit"&gt;10&lt;/span&gt;;&lt;br /&gt;  refPoint.iY = &lt;span class="code-digit"&gt;20&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;  &lt;span class="code-comment"&gt;//&lt;/span&gt;&lt;span class="code-comment"&gt; Pointer of point&lt;br /&gt;&lt;/span&gt;  Point* pPoint = &amp;refPoint;&lt;br /&gt;&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;X = "&lt;/span&gt; + pPoint-&lt;span class="code-keyword"&gt;&gt;&lt;/span&gt;iX);&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Y = "&lt;/span&gt; + pPoint-&lt;span class="code-keyword"&gt;&gt;&lt;/span&gt;iY);&lt;br /&gt;&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;X = "&lt;/span&gt; + (*pPoint).iX);&lt;br /&gt;  Console.WriteLine(&lt;span class="code-string"&gt;"&lt;/span&gt;&lt;span class="code-string"&gt;Y = "&lt;/span&gt; + (*pPoint).iY);&lt;br /&gt;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;p&gt;Here &lt;code&gt;pPoint&lt;/code&gt; is the pointer of Point class instance. We can  access the element of it by using the &lt;code&gt;-&lt;span class="code-keyword"&gt;&gt;&lt;/span&gt;&lt;/code&gt; Operator.&lt;/p&gt; &lt;h2&gt;Change in Beta 2&lt;/h2&gt; &lt;p&gt;When you want to compile program using command line switch you type the  program name after the compiler name; for example if your program name is  prog1.cs then you will compile this:&lt;/p&gt;&lt;p&gt;scs prog1.cs&lt;/p&gt;&lt;p&gt;This works fine for unsafe code while you are programming in beta 1. In beta  2 Microsft added one more switch to command line compiler of C# for writing  unsafe code. Now if you want to write unsafe code then you have to specify the  &lt;code&gt;/unsafe&lt;/code&gt; command line switch with command line compiler otherwise  the compiler gives an error. In beta 2 if you want to write unsafe code in your  program then you compile your programas follows:&lt;/p&gt;&lt;pre id="pre21" style="margin-top: 0px;"&gt;csc /unsafe prog1.cs&lt;/pre&gt;&lt;pre id="pre19" style="margin-top: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre id="pre18" style="margin-top: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre id="pre14" style="margin-top: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre id="pre13" style="margin-top: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre id="pre12" style="margin-top: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre id="pre11" style="margin-top: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre id="pre10" style="margin-top: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre id="pre9" style="margin-top: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre id="pre8" style="margin-top: 0px;"&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-5229534489538659333?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/5229534489538659333/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=5229534489538659333' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/5229534489538659333'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/5229534489538659333'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/12/pointers-and-unsafe-code-in-c.html' title='Pointers and unsafe code in c#'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-8348017162958549201</id><published>2008-12-09T20:11:00.000-08:00</published><updated>2008-12-09T20:30:17.165-08:00</updated><title type='text'>Cryptography in .NET</title><content type='html'>This article gives a brief overview of Cryptography and the Cryptography support provided by the .NET Framework. I begin by introducing Cryptography and then proceed to examine the various types of it. In particular, I review and analyze the various cryptography algorithms and objects supported by .NET. I conclude after proposing and briefly discussing the algorithmic technique that would work best for you.&lt;br /&gt;&lt;strong&gt;Cryptography&lt;/strong&gt;&lt;br /&gt;I remember as kids, we would often play a game called 'jumble the word', where in we would replace an alphabet of a word with another. This way, A would be replaced with C; B with D and so on. Only someone who could understand this algorithm( in this case shift by 2), could decipher these messages and tell the word. Well in fact, this is 'Cryptography'. Surprisingly, we often use cryptography without consciously knowing it. For example, you may've tried to pass on a secret message to your friend using signals that only the two of you understood, or scribbled some text whose meaning was known only to you. We have all done that. Well....so we begin.&lt;br /&gt;Cryptography is the science of scrambling meaningful characters into non-meaningful characters so that people who do not have access to the data cannot read it. The science of cryptography has been around for many years, even long before computers. Cryptography, over the ages, has been an art practiced by many who have devised different techniques to meet some of the information security requirements. The last twenty years have been a period of transition as the discipline moved from an art to a science. With the advent of computers, however, the science was able to produce almost unbreakable codes.&lt;br /&gt;Well, Cryptography has been considered as one of the most complex aspect used by a developer. Using cryptographic algorithms and techniques is not considered a child's play, as it requires a high level of mathematical knowledge. Fortunately, with Microsoft .NET, newly created classes wrap up these sophisticated algorithms into fairly easy-to-use properties and methods. This article gives you an overview of the cryptography support that is provided by the .NET Framework.&lt;br /&gt;However lets first look into a few jargons to make you familiar with cryptography :&lt;br /&gt;1. Data that can be read and understood without any special measures is called 'plaintext' or 'cleartext'&lt;br /&gt;2.The method of disguising plaintext in such a way as to hide its meaning is called 'Encryption'.&lt;br /&gt;3.Encrypting plaintext results in unreadable chunks of data called 'Ciphertext'. You use encryption to make sure that information is hidden from anyone for whom it is not intended, even those who can see the encrypted data.&lt;br /&gt;4.The process of reverting ciphertext to its original plaintext is called 'Decryption'.&lt;br /&gt;5.And finally 'key' is a string of bits used for encrypting and decrypting information to be transmitted. It is a randomly generated set of numbers/ characters that is used to encrypt/decrypt information.&lt;br /&gt;&lt;strong&gt;Types of Cryptography&lt;/strong&gt;&lt;br /&gt;After getting familiar with the terminology, let's delve into the types of Cryptography. There are two types of cryptography: private-key encryption and public-key encryption&lt;br /&gt;&lt;strong&gt;Private key Encryption&lt;/strong&gt;&lt;br /&gt;Private Key encryption, also referred to as conventional or symmetric or single-key encryption was the only available option prior to the advent of Public Key encryption in 1976. This form of encryption was used by emperors like Julius Caesar and other military organizations to convey secret messages. This key requires all communicating parties, to share a common key. With private-key encryption, you encrypt a secret message using a key that only you know. To decrypt the message, you need to use the same key. Private-key cryptography is effective only if the key can be kept secret. Despite the potential weakness of private-key encryption, it is very easy to implement and computationally doesn't consume excessive resources.&lt;br /&gt;Lets see an example - Imagine Julius is trying to send a secret message to his army chief, using a private key. In order for his chief to decrypt the secret message, he must know the private key. So Julius needs to send the key to him. But if the secrecy of his key is known to his opponents somehow , the message remains no longer secure. Moreover, if the Chief tells his subordinate about the private key, he can then also decrypt the message.&lt;br /&gt;&lt;strong&gt;Public-key encryption&lt;/strong&gt;&lt;br /&gt;Public key encryption algorithms are based on the premise that each sender and recipient has a private key, known only to him/her and a public key, which can be known by anyone. Each encryption/decryption process requires at least one public key and one private key. Each is related to the other mathematically, such that messages encrypted with the public key can only be decrypted with the corresponding private key.&lt;br /&gt;Lets see an example - Before Julius sends a message to his chief, he needs to generate the key pair containing the private key and the public key. The chief then freely distributes the public key to his subordinates but keeps the private key to himself. When Julius wants to send a message to his chief, he uses his public key to encrypt the message and then send it to him. Upon receiving the encrypted message, the Chief proceeds to decrypt it with his private key. In this case, he's the only one who can decrypt the message, since the key pair works in such a way that only messages encrypted with the public key can be decrypted with the private key. Also, there's no need to exchange secret keys, thus eliminating the risk of compromising the secrecy of the key.The reverse can happen as well. Suppose the Chief sends a message encrypted with his private key to Julius. To decrypt the message, Julius need his public key. But what's the point of that? The public key isn't a secret-everyone knows it. However, using this method guarantees that the message hasn't been tampered with and is indeed from his chief and not his opponents. If the message had been modified, Julius wouldn't be able to decrypt it.&lt;br /&gt;I wish he was here to read all this!!!&lt;br /&gt;.&lt;strong&gt;NET and Cryptography&lt;br /&gt;&lt;/strong&gt;.NET provides a set of cryptographic objects, supporting well-known algorithms and common uses including hashing, encryption, and generating digital signatures. These objects are designed in a manner that facilitates the incorporation of these basic capabilities into more complex operations, such as signing and encrypting a document. Cryptographic objects are used by .NET to support internal services, but are also available to developers who need cryptographic support. The .NET Framework provides implementations of many such standard cryptographic algorithms and objects. Similar to the ready availability of simple authentication features within the .NET Framework, cryptographic primitives are also easily accessible to developers via stream-based managed code libraries for encryption, digital signatures, hashing, and random number generation. The System.Security.Cryptography namespace in the .NET Framework provides these cryptographic services. The Algorithm support includes:&lt;br /&gt;RSA and DSA public key (asymmetric) encryption - Asymmetric algorithms operate on fixed buffers. They use a public-key algorithm for encryption/decryption. An example for asymmetric algorithms is the RSA algorithm which is so named after its three inventors Rivest, Shamir, and Adleman. It is a popular public-key algorithm - the de facto standard - for digital signatures and can be used for encryption as well. The DSA_CSP is an implementation of the digital signature algorithm (DSA). This is a public-key algorithm. It can be used to create and verify a digital signature.&lt;br /&gt;DES, TripleDES, and RC2 private key (symmetric) encryption - Symmetric algorithms are used to modify variable length buffers and perform one operation for periodical data input. They use a single secret key to encrypt and decrypt data.The Data Encryption Standard (DES) is a world-wide standard for data encryption, which was published in the early 1970s. It is the most popular encryption algorithm. It is implemented by the DES_CSP class. This class represents a stream where you pour in data that is encrypted/decrypted using a single key. The Triple DES encryption algorithm operates on a block of data three times using one key. RC2 stands for Rivest Cipher or "Ron's Code", which is the name of its inventor. RC2 is a symmetric encryption algorithm and works with a variable key-size. it is a block cipher, like many other .NET cryptography algorithms, that operates on groups of bits in contrast to stream cipher algorithms.&lt;br /&gt;MD5 and SHA1 hashing - MD5 - Message Digest 5-is a one-way hash algorithm. Given variable length data as input it always produces a 128-bit hash value. The Secure Hash Algorithm (SHA) also is a one-way hash algorithm that produces a 160-bit hash value, which is longer than the MD5 produced hash value.&lt;br /&gt;(You must have observed the word CSP. Well CSP is a Cryptographic Service Provider. It is the entity that performs the cryptographic computations. The CSP classes are derived from the corresponding base classes and implement a solution for a specific algorithm. For example, the DESCryptoServiceProvider class is derived from the DES class and implements the digital encryption standard. You can use the provided classes or implement your own solution. )&lt;br /&gt;&lt;br /&gt;Here is a general guideline to help you decide when to use which method&lt;br /&gt;Symmetric, or secret key, algorithms are extremely fast and are well suited for encrypting large streams of data. These algorithms, both encrypt and decrypt data. While these are fairly secure, they do have the potential to be broken given enough time, as someone could do a search on every known key value combination. Since each of these algorithms uses a fixed key length or ASCII characters, it is feasible that a computer program could try every possible combination of keys and eventually stumble onto the right one. A common use of these types of algorithms is for storing and retrieving connection strings to databases.&lt;br /&gt;Asymmetric, or public key, algorithms are not as fast as symmetric, but are much harder codes to break. These algorithms rely on two keys, one is Private and the other is Public. The public key is used to encrypt a message. The Private key is the only one that can decrypt the message. The public and private keys are mathematically linked and thus both are needed for this cryptographic exchange to occur successfully. Asymmetric algorithms are not well suited to large amounts of data due to performance. One common use of asymmetric algorithms is to encrypt and transfer to another party a symmetric key and initialization vector. The symmetric algorithm is then used for all messages being sent back and forth.&lt;br /&gt;Hash values are used when you do not wish to ever recover the original value and you especially wish for no one else to discover the original value as well. Hashes will take any arbitrary string length and hash it to a fixed set of bytes. This operation is one-way, and thus is typically used for small amounts of data, like a password. If a user inputs a user password into a secure entry screen, the program can hash this value and store the hashed value into a database. Even if the database were compromised, no one would be able to read the password since it was hashed. When the user then logs into the system to gain entry, the password typed in is hashed using the same algorithm, and if the two hashed values match, then the system knows the input value was the same as the saved value from before.&lt;br /&gt;&lt;strong&gt;Everyone Loves an Example&lt;/strong&gt;&lt;br /&gt;Everyone needs and loves a good example. After having read about the various algorithms available, lets see an example of encrypting and decrypting files using the System.Security.Cryptography namespace. I have used the Rijndael Managed encryption method. The Rijndael Managed class accesses the managed version of the Rijndael algorithm. This class cannot be inherited. The Rijndael class represents the base class from which all implementations of the Rijndael symmetric encryption algorithm must inherit.&lt;br /&gt;&lt;strong&gt;The hierarchy is as follows&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;System.Object&lt;br /&gt;System.Security.Cryptography.SymmetricAlgorithm&lt;br /&gt;System.Security.Cryptography.Rijndael&lt;br /&gt;System.Security.Cryptography.RijndaelManaged&lt;br /&gt;// Encrypting and decrypting files using the Rijndael Managed encryption method.&lt;br /&gt;using System;&lt;br /&gt;using System.IO;&lt;br /&gt;using System.Security.Cryptography;&lt;br /&gt;class CryptoEx&lt;br /&gt;{&lt;br /&gt;public static void Main(string[] args)&lt;br /&gt;{&lt;br /&gt;if (args.Length!=1)&lt;br /&gt;{&lt;br /&gt;Console.WriteLine("FileName Not Entered. Specify a filename to encrypt.");&lt;br /&gt;return;&lt;br /&gt;}&lt;br /&gt;string file = args[0];&lt;br /&gt;string tempfile = Path.GetTempFileName(); // Open the file to read&lt;br /&gt;FileStream fsIn = File.Open(file,FileMode.Open,FileAccess.Read);&lt;br /&gt;FileStream fsOut = File.Open(tempfile, FileMode.Open,FileAccess.Write);&lt;br /&gt;SymmetricAlgorithm symm = new RijndaelManaged();&lt;br /&gt;//creating an instance&lt;br /&gt;ICryptoTransform transform = symm.CreateEncryptor();&lt;br /&gt;//and calling the CreateEncryptor method which&lt;br /&gt;//creates a symmetric encryptor object.&lt;br /&gt;CryptoStream cstream = new CryptoStream(fsOut,transform,CryptoStreamMode.Write); BinaryReader br = new BinaryReader(fsIn);&lt;br /&gt;cstream.Write(br.ReadBytes((int)fsIn.Length),0,(int)fsIn.Length);&lt;br /&gt;cstream.FlushFinalBlock();&lt;br /&gt;cstream.Close();&lt;br /&gt;fsIn.Close();&lt;br /&gt;fsOut.Close();&lt;br /&gt;Console.WriteLine("Created Encrypted File {0}", tempfile);&lt;br /&gt;fsIn = File.Open(tempfile,FileMode.Open,FileAccess.Read);&lt;br /&gt;transform = symm.CreateDecryptor();&lt;br /&gt;cstream = new CryptoStream(fsIn,transform,CryptoStreamMode.Read);&lt;br /&gt;StreamReader sr = new StreamReader(cstream);&lt;br /&gt;Console.WriteLine("Decrypted the File: " + sr.ReadToEnd());&lt;br /&gt;fsIn.Close();&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;strong&gt;Summary :&lt;/strong&gt;&lt;br /&gt;We saw that the .NET Framework supports encryption by means of cryptographic streaming objects based on the primitives. It also supports digital signatures, message authentication codes (MACs)/keyed hash, pseudo-random number generators (PRNGs), and authentication mechanisms. New or pre-standard primitives as SHA-256 or XMLDSIG are already supported. The ready availability of such libraries is hopefully going to drive more widespread reliance on Cryptography to fortify the security of everyday applications. Based on our own experiences, we can confidently state that well-implemented cryptography dramatically increases the security of many aspects of a given application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-8348017162958549201?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/8348017162958549201/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=8348017162958549201' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/8348017162958549201'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/8348017162958549201'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/12/cryptography-in-net.html' title='Cryptography in .NET'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-7530071452451589036</id><published>2008-11-23T07:38:00.000-08:00</published><updated>2008-11-23T08:25:12.517-08:00</updated><title type='text'>The HTML &lt;link&gt; tag</title><content type='html'>You must aware of HTML tags. There are several tags that define elements and linked resources of the web pages. Have you ever use the &lt;span style="font-weight: bold;"&gt;HTML link&lt;/span&gt; tag ? Its so stupid question but there is reason behind putting this question ,  The HTML link tag is very useful and amazing.&lt;br /&gt;&lt;br /&gt;It has three main attribute&lt;br /&gt;&lt;br /&gt;1. rel&lt;br /&gt;2. type&lt;br /&gt;3. href&lt;br /&gt;&lt;br /&gt;The rel attribute define the relationship between page and linked web resource that could be a stylesheet, bookmark, alternate url and so on.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The type attribute define MIME(Multipurpose Mail Extension) of the web resource.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The href attribute define url of the web resource to be linked with page.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Syntax:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;link rel="Relationship" type="MIME Type" href="URL" / &amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here is the list of possible values of the rel attribute:&lt;br /&gt;&lt;br /&gt;  * alternate - an alternate version of the document(print page, translated/mirror)&lt;br /&gt;  * stylesheet - an external style sheet for the document&lt;br /&gt;  * shortcut icon - the fevicon of the document&lt;br /&gt;  * start - the first document in a selection&lt;br /&gt;  * next - the next document in the current selection&lt;br /&gt;  * prev - the previous document in the current selection&lt;br /&gt;  * contents - a table of contents for the document&lt;br /&gt;  * index - an index for the document&lt;br /&gt;  * glossary - a glossary (explanation) of words used in the document&lt;br /&gt;  * copyright - a document containing copyright information&lt;br /&gt;  * chapter - a chapter of a selection of documents&lt;br /&gt;  * section - a section of a selection of documents&lt;br /&gt;  * subsection - a subsection of a selection of documents&lt;br /&gt;  * appendix - an appendix of a selection of documents&lt;br /&gt;  * help - a help document&lt;br /&gt;  * bookmark - a related document&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Note:&lt;/span&gt; Most browsers do not use this attribute in any way. However, search engines, and some browsers, may us this attribute to get more information about the link.&lt;br /&gt;&lt;br /&gt;Linking a stylesheet with the page is one of most commonly used purpose of the HTML link tag. Here I'm going to show you more interesting uses of this tag.&lt;br /&gt;&lt;br /&gt;Example 1:&lt;br /&gt;This example with show a small icon in the browser's address bar before the URL&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;link rel="shortcut icon" type="image/x-icon" href="fevicon.ico" / &amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Example 2:&lt;br /&gt;This example will show a RSS link in the browser's address bar after the URL&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;link rel="alternate" type="application/rss+xml" title="RSS" href="http://www.mysite.com/rss.xml"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Example 3:&lt;br /&gt;This example will show company's copyright information&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;link rel="copyright" href="/copyright.shtml" title="Copyright"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Example 4:&lt;br /&gt;This will link Author information with the page&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;link rel="author" href="/about/index.shtml" title="About"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Example 5:&lt;br /&gt;We can have link tag for many purposes&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;HEAD&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;TITLE&amp;gt;Document Tags&amp;lt;/TITLE&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;LINK REL=HOME TITLE="Home Page" HREF="http://www.mydomain.com"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;LINK REL=PREVIOUS TITLE="URLs" HREF="../urls/"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;LINK REL=NEXT TITLE="Lines and Paragraphs" HREF="../linepar/"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;LINK REV=MADE TITLE="Ravindra Patel" HREF="mailto:ravipatel.write@gmail.com"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;LINK REL=COPYRIGHT TITLE="copyright info" HREF="copyright.html"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;LINK REL=STYLESHEET TITLE="style sheet" HREF="stdstyles.css"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(255, 255, 0);"&gt;&amp;lt;/HEAD&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;There are much more on link tag. Post your comments if you want to know more about the HTML tags&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-7530071452451589036?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/7530071452451589036/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=7530071452451589036' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/7530071452451589036'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/7530071452451589036'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/11/html-tag.html' title='The HTML &amp;lt;link&amp;gt; tag'/><author><name>Ravindra Patel</name><uri>http://www.blogger.com/profile/01282844182571885522</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-7651601360800612133</id><published>2008-11-23T06:21:00.000-08:00</published><updated>2008-11-23T06:51:33.610-08:00</updated><title type='text'>ASP.NET From PHP Perspective</title><content type='html'>You Can also follow the URL:&lt;br /&gt;&lt;a href="http://in.youtube.com/watch?v=aEIwEGyK_Ns"&gt;http://in.youtube.com/watch?v=aEIwEGyK_Ns&lt;/a&gt;&lt;br /&gt;&lt;object width="320" height="266" class="BLOG_video_class" id="BLOG_video-e38fc29a486e3cd9" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="movie" value="http://www.youtube.com/get_player"&gt;&lt;param name="bgcolor" value="#FFFFFF"&gt;&lt;param name="allowfullscreen" value="true"&gt;&lt;param name="flashvars" value="flvurl=http://v19.nonxt1.googlevideo.com/videoplayback?id%3De38fc29a486e3cd9%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1329946506%26sparams%3Did,itag,ip,ipbits,expire%26signature%3DE2C4A23BA60DECF0C4584D4CA97583F935CDB19.5EF81D38C57F08903A6819C0F30BF99308F0CC85%26key%3Dck1&amp;amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3De38fc29a486e3cd9%26offsetms%3D5000%26itag%3Dw160%26sigh%3DdhpOcKzl4qzSV9nqsUjtvjPVcA0&amp;amp;autoplay=0&amp;amp;ps=blogger"&gt;&lt;embed src="http://www.youtube.com/get_player" type="application/x-shockwave-flash"width="320" height="266" bgcolor="#FFFFFF"flashvars="flvurl=http://v19.nonxt1.googlevideo.com/videoplayback?id%3De38fc29a486e3cd9%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1329946506%26sparams%3Did,itag,ip,ipbits,expire%26signature%3DE2C4A23BA60DECF0C4584D4CA97583F935CDB19.5EF81D38C57F08903A6819C0F30BF99308F0CC85%26key%3Dck1&amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3De38fc29a486e3cd9%26offsetms%3D5000%26itag%3Dw160%26sigh%3DdhpOcKzl4qzSV9nqsUjtvjPVcA0&amp;autoplay=0&amp;ps=blogger"allowFullScreen="true" /&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-7651601360800612133?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='enclosure' type='video/mp4' href='http://www.blogger.com/video-play.mp4?contentId=e38fc29a486e3cd9&amp;type=video%2Fmp4' length='0'/><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/7651601360800612133/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=7651601360800612133' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/7651601360800612133'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/7651601360800612133'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/11/aspnet-from-php-perspective.html' title='ASP.NET From PHP Perspective'/><author><name>Piyush Srivastava</name><uri>http://www.blogger.com/profile/07995834856320205913</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_278xsQcO1rU/TUlTVvyJ9II/AAAAAAAAABw/_lmK-mo5EEY/s220/Image0833.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-5621718687803188469</id><published>2008-11-23T02:09:00.000-08:00</published><updated>2008-11-23T03:05:31.075-08:00</updated><title type='text'>Using LINQ</title><content type='html'>&lt;p&gt;&lt;object width="320" height="266" class="BLOG_video_class" id="BLOG_video-573311121e498c68" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="movie" value="http://www.youtube.com/get_player"&gt;&lt;param name="bgcolor" value="#FFFFFF"&gt;&lt;param name="allowfullscreen" value="true"&gt;&lt;param name="flashvars" value="flvurl=http://v3.nonxt7.googlevideo.com/videoplayback?id%3D573311121e498c68%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1329946506%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D478046699B5E3751D134E7E63B526FE4E105BA95.5B6430B8C01BDD44330231E079533DFC0222D380%26key%3Dck1&amp;amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3D573311121e498c68%26offsetms%3D5000%26itag%3Dw160%26sigh%3DbqVV6J-Ls6XQ8unay-O_WgQ4jUc&amp;amp;autoplay=0&amp;amp;ps=blogger"&gt;&lt;embed src="http://www.youtube.com/get_player" type="application/x-shockwave-flash"width="320" height="266" bgcolor="#FFFFFF"flashvars="flvurl=http://v3.nonxt7.googlevideo.com/videoplayback?id%3D573311121e498c68%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1329946506%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D478046699B5E3751D134E7E63B526FE4E105BA95.5B6430B8C01BDD44330231E079533DFC0222D380%26key%3Dck1&amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3D573311121e498c68%26offsetms%3D5000%26itag%3Dw160%26sigh%3DbqVV6J-Ls6XQ8unay-O_WgQ4jUc&amp;autoplay=0&amp;ps=blogger"allowFullScreen="true" /&gt;&lt;/object&gt;&lt;/p&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;a href="http://in.youtube.com/watch?v=B0gD0NqbGHk"&gt;http://in.youtube.com/watch?v=B0gD0NqbGHk&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-5621718687803188469?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='enclosure' type='video/mp4' href='http://www.blogger.com/video-play.mp4?contentId=573311121e498c68&amp;type=video%2Fmp4' length='0'/><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/5621718687803188469/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=5621718687803188469' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/5621718687803188469'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/5621718687803188469'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/11/using-linq.html' title='Using LINQ'/><author><name>Piyush Srivastava</name><uri>http://www.blogger.com/profile/07995834856320205913</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_278xsQcO1rU/TUlTVvyJ9II/AAAAAAAAABw/_lmK-mo5EEY/s220/Image0833.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-5915492679024505324</id><published>2008-11-23T01:27:00.000-08:00</published><updated>2008-11-23T01:51:52.258-08:00</updated><title type='text'>An Introduction to Microsoft Silverlight</title><content type='html'>You can also follow the URLs&lt;br /&gt;&lt;a href="http://in.youtube.com/watch?v=Carpbkwxem0"&gt;http://in.youtube.com/watch?v=Carpbkwxem0&lt;/a&gt;&lt;br /&gt;&lt;a href="http://in.youtube.com/watch?v=m47xvHbdzLY&amp;amp;feature=related"&gt;http://in.youtube.com/watch?v=m47xvHbdzLY&amp;amp;feature=related&lt;/a&gt;&lt;br /&gt;&lt;a href="http://in.youtube.com/watch?v=dUWIOBMNhbI&amp;amp;feature=related"&gt;http://in.youtube.com/watch?v=dUWIOBMNhbI&amp;amp;feature=related&lt;/a&gt;&lt;br /&gt;&lt;object width="320" height="266" class="BLOG_video_class" id="BLOG_video-1b85c3c0420f9cd7" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="movie" value="http://www.youtube.com/get_player"&gt;&lt;param name="bgcolor" value="#FFFFFF"&gt;&lt;param name="allowfullscreen" value="true"&gt;&lt;param name="flashvars" value="flvurl=http://v1.nonxt2.googlevideo.com/videoplayback?id%3D1b85c3c0420f9cd7%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1329946506%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D54F6A8CAFD90798E61F1FB2F3AB4B950F7AA8640.3F1071BC230865FE09450210E493479E0D81DA9F%26key%3Dck1&amp;amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3D1b85c3c0420f9cd7%26offsetms%3D5000%26itag%3Dw160%26sigh%3DjDlXztUO4bSWqdkynlbN-hm1FiY&amp;amp;autoplay=0&amp;amp;ps=blogger"&gt;&lt;embed src="http://www.youtube.com/get_player" type="application/x-shockwave-flash"width="320" height="266" bgcolor="#FFFFFF"flashvars="flvurl=http://v1.nonxt2.googlevideo.com/videoplayback?id%3D1b85c3c0420f9cd7%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1329946506%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D54F6A8CAFD90798E61F1FB2F3AB4B950F7AA8640.3F1071BC230865FE09450210E493479E0D81DA9F%26key%3Dck1&amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3D1b85c3c0420f9cd7%26offsetms%3D5000%26itag%3Dw160%26sigh%3DjDlXztUO4bSWqdkynlbN-hm1FiY&amp;autoplay=0&amp;ps=blogger"allowFullScreen="true" /&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-5915492679024505324?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='enclosure' type='video/mp4' href='http://www.blogger.com/video-play.mp4?contentId=1b85c3c0420f9cd7&amp;type=video%2Fmp4' length='0'/><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/5915492679024505324/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=5915492679024505324' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/5915492679024505324'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/5915492679024505324'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/11/introduction-to-microsoft-silverlight.html' title='An Introduction to Microsoft Silverlight'/><author><name>Piyush Srivastava</name><uri>http://www.blogger.com/profile/07995834856320205913</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_278xsQcO1rU/TUlTVvyJ9II/AAAAAAAAABw/_lmK-mo5EEY/s220/Image0833.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-665322988986956891</id><published>2008-11-13T08:21:00.000-08:00</published><updated>2008-11-13T08:57:51.383-08:00</updated><title type='text'>Basics of Jquery</title><content type='html'>You can also use the following link for the video&lt;br /&gt;http://in.youtube.com/watch?v=CNw2wVDWYaU&amp;amp;feature=related&lt;br /&gt;&lt;object width="320" height="266" class="BLOG_video_class" id="BLOG_video-75c341fe26b3f382" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="movie" value="http://www.youtube.com/get_player"&gt;&lt;param name="bgcolor" value="#FFFFFF"&gt;&lt;param name="allowfullscreen" value="true"&gt;&lt;param name="flashvars" value="flvurl=http://v6.nonxt5.googlevideo.com/videoplayback?id%3D75c341fe26b3f382%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1329946506%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D717A8C59E02634247B707E6B8325CA5E988B0EC0.9DE1E79AA7AE9E3039014FBFB06B067C721EE6D%26key%3Dck1&amp;amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3D75c341fe26b3f382%26offsetms%3D5000%26itag%3Dw160%26sigh%3DtIz-EgP4lOIwK-NgQvgE80623As&amp;amp;autoplay=0&amp;amp;ps=blogger"&gt;&lt;embed src="http://www.youtube.com/get_player" type="application/x-shockwave-flash"width="320" height="266" bgcolor="#FFFFFF"flashvars="flvurl=http://v6.nonxt5.googlevideo.com/videoplayback?id%3D75c341fe26b3f382%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1329946506%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D717A8C59E02634247B707E6B8325CA5E988B0EC0.9DE1E79AA7AE9E3039014FBFB06B067C721EE6D%26key%3Dck1&amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3D75c341fe26b3f382%26offsetms%3D5000%26itag%3Dw160%26sigh%3DtIz-EgP4lOIwK-NgQvgE80623As&amp;autoplay=0&amp;ps=blogger"allowFullScreen="true" /&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-665322988986956891?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='enclosure' type='video/mp4' href='http://www.blogger.com/video-play.mp4?contentId=75c341fe26b3f382&amp;type=video%2Fmp4' length='0'/><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/665322988986956891/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=665322988986956891' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/665322988986956891'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/665322988986956891'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/11/basics-of-jquery.html' title='Basics of Jquery'/><author><name>Piyush Srivastava</name><uri>http://www.blogger.com/profile/07995834856320205913</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_278xsQcO1rU/TUlTVvyJ9II/AAAAAAAAABw/_lmK-mo5EEY/s220/Image0833.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-3028130974278024171</id><published>2008-11-13T07:54:00.000-08:00</published><updated>2008-11-13T08:18:17.346-08:00</updated><title type='text'>Asp.Net 2.0 Membership I   LoginStatus LoginName</title><content type='html'>&lt;object width="320" height="266" class="BLOG_video_class" id="BLOG_video-a1e1fe35490472eb" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"&gt;&lt;param name="movie" value="http://www.youtube.com/get_player"&gt;&lt;param name="bgcolor" value="#FFFFFF"&gt;&lt;param name="allowfullscreen" value="true"&gt;&lt;param name="flashvars" value="flvurl=http://v15.nonxt6.googlevideo.com/videoplayback?id%3Da1e1fe35490472eb%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1329946506%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D1BA2A22051483751A7CF0143A8343330893FD20F.71AA702A3BB2C4F22749B43ADC02FD50234E6282%26key%3Dck1&amp;amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3Da1e1fe35490472eb%26offsetms%3D5000%26itag%3Dw160%26sigh%3D2tTsENi0ALLhYwqrTIGtEtzDuew&amp;amp;autoplay=0&amp;amp;ps=blogger"&gt;&lt;embed src="http://www.youtube.com/get_player" type="application/x-shockwave-flash"width="320" height="266" bgcolor="#FFFFFF"flashvars="flvurl=http://v15.nonxt6.googlevideo.com/videoplayback?id%3Da1e1fe35490472eb%26itag%3D5%26app%3Dblogger%26ip%3D0.0.0.0%26ipbits%3D0%26expire%3D1329946506%26sparams%3Did,itag,ip,ipbits,expire%26signature%3D1BA2A22051483751A7CF0143A8343330893FD20F.71AA702A3BB2C4F22749B43ADC02FD50234E6282%26key%3Dck1&amp;iurl=http://video.google.com/ThumbnailServer2?app%3Dblogger%26contentid%3Da1e1fe35490472eb%26offsetms%3D5000%26itag%3Dw160%26sigh%3D2tTsENi0ALLhYwqrTIGtEtzDuew&amp;autoplay=0&amp;ps=blogger"allowFullScreen="true" /&gt;&lt;/object&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-3028130974278024171?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='enclosure' type='video/mp4' href='http://www.blogger.com/video-play.mp4?contentId=a1e1fe35490472eb&amp;type=video%2Fmp4' length='0'/><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/3028130974278024171/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=3028130974278024171' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/3028130974278024171'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/3028130974278024171'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/11/aspnet-20-membership-i-loginstatus.html' title='Asp.Net 2.0 Membership I   LoginStatus LoginName'/><author><name>Piyush Srivastava</name><uri>http://www.blogger.com/profile/07995834856320205913</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_278xsQcO1rU/TUlTVvyJ9II/AAAAAAAAABw/_lmK-mo5EEY/s220/Image0833.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-3699806526470064086</id><published>2008-11-13T07:08:00.000-08:00</published><updated>2008-11-13T07:21:30.717-08:00</updated><title type='text'>How to: Create an ASP.NET Login Page</title><content type='html'>&lt;div class="introduction"&gt;&lt;p&gt;                     You can create a login page by using the ASP.NET login &lt;span&gt;&lt;/span&gt; control. The control consists of text boxes, a check box and a button control. The text boxes collect username and password information from the user. The check box is used to remember the user's credentials and the button is used to submit the information the user provides. The login control simplifies creating login pages for form authentication. This login control takes a user name and password and uses ASP.NET membership and forms authentication to verify the user's credentials and create an authentication ticket. For information about how to configure ASP.NET membership and forms authentication&lt;span&gt;&lt;/span&gt;. If a user selects the &lt;span class="ui"&gt;Remember me next time &lt;/span&gt;check box, the control creates a persistent cookie that remembers the user's credentials.                 &lt;/p&gt;&lt;br /&gt;&lt;p&gt; The login control functions as expected when you create an ASP.NET Web site with membership, configure membership, and create a membership user. &lt;/p&gt;&lt;h3 class="procedureSubHeading"&gt;To create a login page&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;                     Create an ASP.NET Web application that uses ASP.NET membership. &lt;/p&gt;&lt;/li&gt;&lt;li&gt;                     Create an ASP.NET Web page named &lt;span class="input"&gt;Login.aspx&lt;/span&gt; in your application.(      By default, ASP.NET forms authentication is configured to use a page named                   &lt;span class="input"&gt;Login.aspx&lt;/span&gt;. You can change the default login page name in the &lt;span&gt;&lt;span class="input"&gt;Web.config&lt;/span&gt;&lt;/span&gt; file for your application using the Login Url &lt;span&gt;&lt;/span&gt; property.)&lt;/li&gt;&lt;li&gt;                     Add a Login &lt;span&gt;&lt;/span&gt;control to the page.&lt;/li&gt;&lt;li&gt;                     Set the control's &lt;span&gt;&lt;/span&gt;Designation page Url property to the name of the page that the user will be redirected to after they log in. For example, you can set the DestinationPageUrl property to &lt;span class="code"&gt;DestinationPageUrl="~/Membership/MembersHome.aspx"&lt;/span&gt;, a members only page. If you do not specify a value for the &lt;span style="text-decoration: underline;"&gt;Designation Page Url &lt;/span&gt;property, the user will be redirected to the original page the user requested after successfully logging in.&lt;/li&gt;&lt;li&gt;                     The following example shows the markup for a &lt;span&gt;&lt;/span&gt; Login control:&lt;/li&gt;&lt;/ol&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_278xsQcO1rU/SRxFm-Gd1AI/AAAAAAAAABI/JIIKpT-BruI/s1600-h/1.JPG"&gt;&lt;img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 322px; height: 212px;" src="http://3.bp.blogspot.com/_278xsQcO1rU/SRxFm-Gd1AI/AAAAAAAAABI/JIIKpT-BruI/s320/1.JPG" alt="" id="BLOGGER_PHOTO_ID_5268162199924102146" border="0" /&gt;&lt;/a&gt;&lt;p&gt;                 &lt;/p&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-3699806526470064086?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/3699806526470064086/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=3699806526470064086' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/3699806526470064086'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/3699806526470064086'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/11/how-to-create-aspnet-login-page.html' title='How to: Create an ASP.NET Login Page'/><author><name>Piyush Srivastava</name><uri>http://www.blogger.com/profile/07995834856320205913</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_278xsQcO1rU/TUlTVvyJ9II/AAAAAAAAABw/_lmK-mo5EEY/s220/Image0833.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_278xsQcO1rU/SRxFm-Gd1AI/AAAAAAAAABI/JIIKpT-BruI/s72-c/1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-1948199897461219959</id><published>2008-11-04T23:10:00.000-08:00</published><updated>2008-11-07T20:11:46.038-08:00</updated><title type='text'>About IIS(Internet Information Servicces)</title><content type='html'>&lt;strong&gt;Overview &lt;/strong&gt;&lt;br /&gt;Over the years, it has become simple for advanced Web users to create their own Web site.  Once an end-user has registered their domain name, there are various types of hosters to choose from.  Web hosters are available throughout the world to meet the demands of end customers. But regardless of which hoster is chosen, the scenario of signing up and creating a web site is similar in all cases.&lt;br /&gt;Initially, a new user account needs to be established for the user.  Once the account has been set up, the end user decides what features and options the site should incorporate: for instance, how much disk space, FTP capability, creation of virtual directories, whether or not databases are needed, etc.  Hosters build control panels or dashboard applications that allow end users to create and manage these features.&lt;br /&gt;There are a number of ways that these capabilities can be implemented into the control panel. In this section, we look at implementing the provisioning aspect of these features through managed code.  An outline of the features is as follows:&lt;br /&gt;&lt;a class="" href="http://learn.iis.net/page.aspx/285/#Provision" mce_href="/page.aspx/285/#Provision"&gt;&lt;span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;Provision new user account&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;a class="" href="http://learn.iis.net/page.aspx/285/#CreateContent" mce_href="/page.aspx/285/#CreateContent"&gt;&lt;span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;Create content storage&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;a class="" href="http://learn.iis.net/page.aspx/285/#CreateApp" mce_href="/page.aspx/285/#CreateApp"&gt;&lt;span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;Create Application Pool&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;a class="" href="http://learn.iis.net/page.aspx/285/#CreateSite" mce_href="/page.aspx/285/#CreateSite"&gt;&lt;span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;Create Web site&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;a class="" href="http://learn.iis.net/page.aspx/285/#CreateBinding" mce_href="/page.aspx/285/#CreateBinding"&gt;&lt;span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;Create binding&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;a class="" href="http://learn.iis.net/page.aspx/285/#CreateRoot" mce_href="/page.aspx/285/#CreateRoot"&gt;&lt;span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;Create root application&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;a class="" href="http://learn.iis.net/page.aspx/285/#CreateVirtual" mce_href="/page.aspx/285/#CreateVirtual"&gt;&lt;span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;Create Virtual directory&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;a class="" href="http://learn.iis.net/page.aspx/285/#CreateFTP" mce_href="/page.aspx/285/#CreateFTP"&gt;&lt;span&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 255, 255);"&gt;Create FTP site&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;strong&gt;Provision New User Account&lt;/strong&gt;&lt;br /&gt;A user account is needed for the site owner who manages and maintains the site.  The account can either be an Active Directory Account, or a local user account.  To simplify the scenario, we only illustrate creating a local user account.&lt;br /&gt;The following code fragments demonstrate the creation of a local account. &lt;br /&gt;The System.DirectoryServices namespace must be specified.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;public static bool CreateLocalUserAccount(string userName, string password)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;{   &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;try  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; {      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;if (string.IsNullOrEmpty(userName))       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;      throw new ArgumentNullException("userName", "Invalid User Name.");     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; if (string.IsNullOrEmpty(password))       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;     throw new ArgumentNullException("password", "Invalid Password.");     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; DirectoryEntry directoryEntry = new DirectoryEntry("WinNT://" +      Environment.MachineName + ",computer");     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; bool userFound = false;     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; try      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;{         &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;if (directoryEntry.Children.Find(userName, "user") != null)           &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;userFound = true;     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; }    &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  catch     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; {       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  userFound = false;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  }   &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;   if (!userFound)   &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;   {       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  DirectoryEntry newUser = directoryEntry.Children.Add(userName, "user");         newUser.Invoke("SetPassword", new object[] { password });      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;   newUser.Invoke("Put", new object[] { "Description", "Application Pool User Account" });         newUser.CommitChanges();      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;   newUser.Close();     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; }   &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;}   &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;catch (Exception ex)  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; {       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; throw new Exception(ex.Message, ex);  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; }   return true;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;Create Content Storage&lt;/strong&gt;&lt;br /&gt;The content storage requires specific permissions configured for users to manage their own contents. The following code fragment demonstrates how to set directory permissions using managed code in C#:&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;InheritanceFlags inheritanceFlags, PropagationFlags propagationFlags, AccessControlType controlType)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;{  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; try  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; {       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;// Create a new DirectoryInfo object.       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;DirectoryInfo dInfo = new DirectoryInfo(directoryPath);       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;// Get a DirectorySecurity object that represents the      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  // current security settings.      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; DirectorySecurity dSecurity = dInfo.GetAccessControl();      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; // Add the FileSystemAccessRule to the security settings.       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; dSecurity.AddAccessRule(new FileSystemAccessRule(userAccount, rights, inheritanceFlags, propagationFlags, controlType));      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; // Set the new access settings.      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; dInfo.SetAccessControl(dSecurity); &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  }  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; catch (Exception ex)  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; {       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;throw new Exception(ex.Message, ex);  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; }  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; return true;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;}&lt;/span&gt;&lt;br /&gt;Furthermore, if disk quota is restricted, the following code fragment demonstrates how to set disk quota using managed code. To use the disk quota management, you must add reference to Windows Disk Quota management component; it resides under window\system32\dskquota.dll.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;public static bool AddUserDiskQuota(string userName, double quota, double quotaThreshold, string diskVolume)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;{  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; try   &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;{      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;DiskQuotaControlClass diskQuotaCtrl = GetDiskQuotaControl(diskVolume);      diskQuotaCtrl.UserNameResolution = UserNameResolutionConstants.dqResolveNone;      DIDiskQuotaUser diskUser = diskQuotaCtrl.AddUser(userName);      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;diskUser.QuotaLimit = quota;     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; diskUser.QuotaThreshold = quotaThreshold;    &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;}    &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;catch (Exception ex)  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  {      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;throw new Exception(ex.Message, ex);   &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; }   &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; return true;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;strong&gt;Create Application Pool&lt;/strong&gt;&lt;br /&gt;An application pool defines the settings for a worker process that hosts one or more IIS 7.0 applications, carrying out their request processing. The application pool is a unit of process isolation, since all request processing for an application runs within its application pool's worker processes.&lt;br /&gt;It is also a unit of isolation from a security perspective, since the application pool can run with a different identity, and ACL all needed resources exclusively for itself to prevent applications in other application pools from being able to access its resources.  The following code fragment demonstrates the creation of an application pool, setting the identity, and setting properties.&lt;br /&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;public static bool CreateApplicationPool(string applicationPoolName, ProcessModelIdentityType identityType, string applicationPoolIdentity, string password, string managedRuntimeVersion, bool autoStart, bool enable32BitAppOnWin64,ManagedPipelineMode managedPipelineMode, long queueLength, TimeSpan idleTimeout, long periodicRestartPrivateMemory, TimeSpan periodicRestartTime)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;{  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; try   &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;{      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;if (identityType == ProcessModelIdentityType.SpecificUser)      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;{        &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; if (string.IsNullOrEmpty(applicationPoolName))           &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;      throw new ArgumentNullException("applicationPoolName", "CreateApplicationPool: applicationPoolName is null or empty.");         &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;if (string.IsNullOrEmpty(applicationPoolIdentity))          &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;     throw new ArgumentNullException("applicationPoolIdentity", "CreateApplicationPool: applicationPoolIdentity is null or empty.");        &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; if (string.IsNullOrEmpty(password))            &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;    throw new ArgumentNullException("password", "CreateApplicationPool: password is null or empty.");    &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  }      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;using (ServerManager mgr = new ServerManager())      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;{        &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; ApplicationPool newAppPool = mgr.ApplicationPools.Add(applicationPoolName);        &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; if (identityType == ProcessModelIdentityType.SpecificUser)       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  {         &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;   newAppPool.ProcessModel.IdentityType = ProcessModelIdentityType.SpecificUser;            newAppPool.ProcessModel.UserName = applicationPoolIdentity;            newAppPool.ProcessModel.Password = password;       &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  }        &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; else        &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; {           &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; newAppPool.ProcessModel.IdentityType = identityType;      &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;   }           &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; if (!string.IsNullOrEmpty(managedRuntimeVersion))               newAppPool.ManagedRuntimeVersion = managedRuntimeVersion;               newAppPool.AutoStart = autoStart;              &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; newAppPool.Enable32BitAppOnWin64 = enable32BitAppOnWin64;               newAppPool.ManagedPipelineMode = managedPipelineMode;          &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  if (queueLength &gt; 0)             &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  newAppPool.QueueLength = queueLength;           &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; if (idleTimeout != TimeSpan.MinValue)               &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;newAppPool.ProcessModel.IdleTimeout = idleTimeout;          &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  if (periodicRestartPrivateMemory &gt; 0)               newAppPool.Recycling.PeriodicRestart.PrivateMemory = periodicRestartPrivateMemory;            if (periodicRestartTime != TimeSpan.MinValue)               newAppPool.Recycling.PeriodicRestart.Time = periodicRestartTime;           &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; mgr.CommitChanges();     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;    }  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; }  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; catch (Exception ex) &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  {     &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; throw new Exception(ex.Message, ex); &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;  }  &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt; return true; &lt;/span&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;}&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-1948199897461219959?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/1948199897461219959/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=1948199897461219959' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/1948199897461219959'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/1948199897461219959'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/11/about-iisinternet-information-servicces.html' title='About IIS(Internet Information Servicces)'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-363710118253902213</id><published>2008-11-04T22:35:00.000-08:00</published><updated>2008-11-04T23:04:20.965-08:00</updated><title type='text'>Using LINQ to Create a Pager for SQL Data in C#</title><content type='html'>&lt;div align="justify"&gt;Using LINQ to SQL, we can make use of the built-in methods to page the database data a lot easier than with using SQL alone. LINQ to SQL can make it extremely easy for us to create pages from our data source using just two methods - Skip and Take.Skip allows us to skip a certain number of records, and Take allows us to select a certain number of records.&lt;br /&gt;In this tutorial, we will be creating a SQL database and adding a LINQ to SQL Class that Visual Studio creates to represent our database. We will then extend the class to support paging of the data, using the methods mentioned above.Let's start by creating our database. In this example, we will use one table named tblEmployees with three columns - id, name, position.Once the database is set up, we will add some sample data - we will need at least 5 records to make use of the paging feature.&lt;br /&gt;Once we have our database set up and have added data to it, we then need to create a representation of our database using a LINQ to SQL Class. Right-click your project in the Solution Explorer, and goto Add ASP.NET Folder &gt; App_Code. Now right-click the App_Code folder and choose Add New Item.. LINQ to SQL Classes. This will bring up the Object Relationship Designer. All we need to do here is drag the tables we will be working with into the Designer, from the Server Explorer, and then Save. This will allow Visual Studio to create a representation of our database. For this example, we will name it Employees.dbml&lt;br /&gt;Now we will create an extension of this class by again right-clicking the App_Code folder and choose Add New Item.. Class. We will also name this Employees and change the public class to public partial class. We may need to also add extra assembly references; we will be using the System.Collections.Generic, System.Data.Linq and System.Linq in particular.We are going to extend this class by providing methods to select the data in pages. Our first method will select all the data:&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;public static IEnumerable&lt;tblemployee&gt; Select()&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;{&lt;br /&gt;EmployeesDataContext db = new EmployeesDataContext();&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;return db.tblEmployees;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;}&lt;/span&gt;&lt;br /&gt;Notice the EmployeesDataContext refers to our LINQ to SQL class.Next, we add a method to move between the pages of the data:&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;public static IEnumerable&lt;tblemployee&gt; SelectPage(int startRowIndex, int maximumRows)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;{&lt;br /&gt;return Select().Skip(startRowIndex).Take(maximumRows);&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;}&lt;/span&gt;&lt;br /&gt;This method will be called when a new page is requested through PostBack. The GridView's paging links will provide the variables required for this method.Finally, we create a method that will get the number of records in the database:&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;public static int SelectCount()&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;{&lt;br /&gt;return Select().Count();&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#000000;"&gt;The entire class extension will look something like this:&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;using System;&lt;br /&gt;using System.Data;&lt;br /&gt;using System.Configuration;&lt;br /&gt;using System.Linq;&lt;br /&gt;using System.Data.Linq;&lt;br /&gt;using System.Web;&lt;br /&gt;using System.Web.Security;&lt;br /&gt;using System.Web.UI;&lt;br /&gt;using System.Web.UI.HtmlControls;&lt;br /&gt;using System.Web.UI.WebControls;&lt;br /&gt;using System.Web.UI.WebControls.WebParts;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;/// &lt;summary&gt;/// Extension class for Employees.dbml/// &lt;/summary&gt;&lt;br /&gt;public partial class Employees{&lt;br /&gt;public static IEnumerable&lt;tblemployee&gt; Select()&lt;br /&gt;{&lt;br /&gt;EmployeesDataContext db = new EmployeesDataContext();return db.tblEmployees;&lt;br /&gt;}&lt;br /&gt;public static IEnumerable&lt;tblemployee&gt; SelectPage(int startRowIndex, int maximumRows)&lt;br /&gt;{&lt;br /&gt;return Select().Skip(startRowIndex).Take(maximumRows);&lt;br /&gt;}&lt;br /&gt;public static int SelectCount()&lt;br /&gt;{&lt;br /&gt;return Select().Count();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;Now we are done with the class, and can implement the functionality into our ASPX page. To make this work, we will need to use a GridView control and an ObjectDataSource:&lt;br /&gt;&lt;/div&gt;&lt;img id="BLOGGER_PHOTO_ID_5265064839090820946" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 177px; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_278xsQcO1rU/SRFEk11oV1I/AAAAAAAAAA4/7MWPfxq56nY/s320/1.JPG" border="0" /&gt;&lt;br /&gt;&lt;?xml:namespace prefix = asp /&gt;&lt;asp:scriptmanager id="ScriptManager1" runat="server"&gt;&lt;contenttemplate&gt;&lt;asp:gridview id="DataGrid1" runat="server" width="400px"&gt;&lt;asp:objectdatasource id="ObjectDataSource1" runat="server"&gt;Because we are using VS.NET 2008, we can simply add AJAX Functionality to our web application using a ScriptManager and UpdatePanel.In order to implement paging, we need to set the EnablePaging attributes on both of our controls. We also set the Method attributes of the ObjectDataSource to reflect those we created in our partial class - note that the TypeName refers to our class name.&lt;/asp:objectdatasource&gt;&lt;/asp:gridview&gt;&lt;/asp:scriptmanager&gt;&lt;br /&gt;&lt;asp:scriptmanager runat="server"&gt;&lt;asp:gridview runat="server" width="400px"&gt;&lt;asp:objectdatasource runat="server"&gt;NOTE: We can change the PageSize to set the number of items on each page.&lt;br /&gt;&lt;br /&gt;&lt;div align="justify"&gt;&lt;pre&gt;&lt;br /&gt;&lt;form id="form1" runat="server"&gt;&lt;img id="BLOGGER_PHOTO_ID_5265065264977626498" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 202px; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_278xsQcO1rU/SRFE9oY9RYI/AAAAAAAAABA/5s34MDVrDKw/s320/2.JPG" border="0" /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;asp:scriptmanager id="ScriptManager1" runat="server"&gt;&lt;/asp:scriptmanager&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;asp:updatepanel id="UpdatePanel1" runat="server"&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;contenttemplate&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;asp:gridview id="DataGrid1" runat="server" width="400px" datasourceid="ObjectDataSource1" pagesize="5" allowpaging="true"&gt;&lt;/asp:gridview&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;asp:objectdatasource id="ObjectDataSource1" runat="server" typename="Employees" selectmethod="SelectPage" selectcountmethod="SelectCount" enablepaging="true"&gt;&lt;/asp:objectdatasource&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/contenttemplate&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/asp:updatepanel&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style="color:#ff9900;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;br /&gt;&lt;form id="form1" runat="server"&gt;&lt;br /&gt;&lt;asp:scriptmanager id="ScriptManager1" runat="server"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;&lt;asp:updatepanel id="UpdatePanel1" runat="server"&gt;&lt;br /&gt;&lt;contenttemplate&gt;&lt;br /&gt;&lt;asp:gridview id="DataGrid1" runat="server" width="400px" datasourceid="ObjectDataSource1" pagesize="5" allowpaging="true"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;&lt;asp:objectdatasource id="ObjectDataSource1" runat="server" typename="Employees" selectmethod="SelectPage" selectcountmethod="SelectCount" enablepaging="true"&gt;&lt;/asp:objectdatasource&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;&lt;/contenttemplate&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;&lt;/asp:updatepanel&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff9900;"&gt;&lt;/form&gt;&lt;/div&gt;&lt;/span&gt;&lt;/asp:gridview&gt;&lt;/asp:scriptmanager&gt;&lt;/asp:objectdatasource&gt;&lt;/asp:gridview&gt;&lt;/asp:scriptmanager&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-363710118253902213?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/363710118253902213/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=363710118253902213' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/363710118253902213'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/363710118253902213'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/11/using-linq-to-create-pager-for-sql-data.html' title='Using LINQ to Create a Pager for SQL Data in C#'/><author><name>Piyush Srivastava</name><uri>http://www.blogger.com/profile/07995834856320205913</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_278xsQcO1rU/TUlTVvyJ9II/AAAAAAAAABw/_lmK-mo5EEY/s220/Image0833.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_278xsQcO1rU/SRFEk11oV1I/AAAAAAAAAA4/7MWPfxq56nY/s72-c/1.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-2639660590846241134</id><published>2008-11-04T21:59:00.000-08:00</published><updated>2008-11-04T22:24:02.599-08:00</updated><title type='text'>Adding to XML File using LINQ and C#</title><content type='html'>&lt;div&gt;This tutorial was created with Visual Studio 2008, but can be replicated in 2005 if you download and install Microsoft's LINQ Community Technology Preview release, which can be downloaded from here.&lt;br /&gt;LINQ has the amazing ability to communicate and interact with many various data sources - databases, XML and varying objects. In this tutorial, we will be using a Windows Form to look at how we can use LINQ to add data to an XML file for storage. This is a quick and easy alternative to using a database. An XML file would be good for storing less information, which is not sensitive.&lt;br /&gt;&lt;br /&gt;The XML file we will be using in this example is as follows:&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;persons&gt;&lt;person&gt;&lt;name&gt;&lt;?xml version="1.0" encoding="utf-8" ?&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;persons&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;&lt;/persons&gt;&lt;/span&gt;&lt;span style="color:#ff0000;"&gt;&lt;/person&gt;&lt;/span&gt;&lt;img id="BLOGGER_PHOTO_ID_5265055201049339122" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 200px; CURSOR: hand; HEIGHT: 320px; TEXT-ALIGN: center" alt="" src="http://1.bp.blogspot.com/_278xsQcO1rU/SRE7z1VeZPI/AAAAAAAAAAw/YoObKM_fuxU/s320/XMLPIC.JPG" border="0" /&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/persons&gt;&lt;/span&gt;&lt;br /&gt;We will create a Windows Form to view the XML file, and also to add new data to it. We will add three textboxes to the form - for name, city and age; two buttons - for adding and viewing XML data; and a Rich Text Box for viewing the XML data. We can also add labels to the text boxes.&lt;br /&gt;Once our form is ready, we can move to the code-behind and add the namespaces we are going to use. The majority of which are added automatically. We may need to add System.Xml.Linq, however. It will look something like this:&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Collections.Generic;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.ComponentModel;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Data;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Drawing;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Linq;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Text;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Windows.Forms;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Xml.Linq;&lt;/span&gt;&lt;br /&gt;Once we have added our references, we will create an on-click handler for the view button. We will add the following code-behind:&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;private void button1_Click(object sender, EventArgs e){&lt;br /&gt;XDocument xmlDoc = XDocument.Load("People.xml");&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;var persons = from person in xmlDoc.Descendants("Person")&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;select new{&lt;br /&gt;Name = person.Element("Name").Value,&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;City = person.Element("City").Value,&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Age = person.Element("Age").Value,&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;};&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;txtResults.Text = "";&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;foreach (var person in persons){&lt;br /&gt;txtResults.Text = txtResults.Text + "Name: " + person.Name + "\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;txtResults.Text = txtResults.Text + "City: " + person.City + "\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;txtResults.Text = txtResults.Text + "Age: " + person.Age + "\n\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;if (txtResults.Text == "")&lt;br /&gt;txtResults.Text = "No Results.";&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;}&lt;/span&gt;&lt;br /&gt;This code-block utilizes LINQ, first loading the XML file into memory, and then selecting all the data from within. The LINQ query looks similar to a SQL statement. We select all data from the XML file and then loop through this data, outputting all results into the text box. Finally, we check to see if the XML file is empty.&lt;br /&gt;Next, we will add the code for the button to add new data to the XML file. We create another handler for the other button:&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;private void button2_Click(object sender, EventArgs e){&lt;br /&gt;XDocument xmlDoc = XDocument.Load("People.xml");&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;xmlDoc.Element("Persons").Add(new XElement("Person", new XElement("Name", txtName.Text),&lt;br /&gt;new XElement("City", txtCity.Text), new XElement("Age", txtAge.Text)));&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;xmlDoc.Save("People.xml");&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;}&lt;/span&gt;&lt;br /&gt;Similar to the other button, this one also opens the XML file, to enable us to edit it. We then simply add an element to the XML file, into the Persons element.Now our Window Form can both read and write to the XML file. The entire code-behind looks something like this:&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Collections.Generic;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.ComponentModel;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Data;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Drawing;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Linq;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Text;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Windows.Forms;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;using System.Xml.Linq;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;namespace LINQtoXML_cs{&lt;br /&gt;public partial class Form1 : Form{&lt;br /&gt;public Form1(){&lt;br /&gt;InitializeComponent();&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;private void button1_Click(object sender, EventArgs e){&lt;br /&gt;XDocument xmlDoc = XDocument.Load("People.xml");&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;var persons = from person in xmlDoc.Descendants("Person")&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;select new{&lt;br /&gt;Name = person.Element("Name").Value,&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;City = person.Element("City").Value,&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;Age = person.Element("Age").Value,&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;};&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;txtResults.Text = "";&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;foreach (var person in persons){&lt;br /&gt;txtResults.Text = txtResults.Text + "Name: " + person.Name + "\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;txtResults.Text = txtResults.Text + "City: " + person.City + "\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;txtResults.Text = txtResults.Text + "Age: " + person.Age + "\n\n";&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;if (txtResults.Text == "")&lt;br /&gt;txtResults.Text = "No Results.";&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;private void button2_Click(object sender, EventArgs e)&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;{&lt;br /&gt;XDocument xmlDoc = XDocument.Load("People.xml");xmlDoc.Element("Persons").Add(new XElement("Person", new XElement("Name", txtName.Text),&lt;br /&gt;new XElement("City", txtCity.Text), new XElement("Age", txtAge.Text)));xmlDoc.Save("People.xml");&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color:#ff0000;"&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/3068650074752359005-2639660590846241134?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/2639660590846241134/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=2639660590846241134' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/2639660590846241134'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/2639660590846241134'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/11/adding-to-xml-file-using-linq-and-c.html' title='Adding to XML File using LINQ and C#'/><author><name>Piyush Srivastava</name><uri>http://www.blogger.com/profile/07995834856320205913</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_278xsQcO1rU/TUlTVvyJ9II/AAAAAAAAABw/_lmK-mo5EEY/s220/Image0833.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_278xsQcO1rU/SRE7z1VeZPI/AAAAAAAAAAw/YoObKM_fuxU/s72-c/XMLPIC.JPG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-694799667369973262</id><published>2008-11-04T21:48:00.000-08:00</published><updated>2008-11-04T21:58:44.465-08:00</updated><title type='text'>Performance Tips and Tricks in .NET Applications</title><content type='html'>&lt;div align="justify"&gt;&lt;br /&gt;Summary: This article is for developers who want to tweak their applications for optimal performance in the managed world. Sample code, explanations and design guidelines are addressed for Database, Windows Forms and ASP applications, as well as language-specific tips for Microsoft Visual Basic and Managed C++. (25 printed pages)&lt;br /&gt;Contents&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms973839.aspx#dotnetperftips_topic1"&gt;Overview&lt;/a&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms973839.aspx#dotnetperftips_topic2"&gt;Performance Tips for All Applications&lt;/a&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms973839.aspx#dotnetperftips_topic3"&gt;Tips for Database Access&lt;/a&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms973839.aspx#dotnetperftips_topic4"&gt;Performance Tips for ASP.NET Applications&lt;/a&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms973839.aspx#dotnetperftips_topic5"&gt;Tips for Porting and Developing in Visual Basic&lt;/a&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms973839.aspx#dotnetperftips_topic6"&gt;Tips for Porting and Developing in Managed C++&lt;/a&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms973839.aspx#dotnetperftips_topic7"&gt;Additional Resources&lt;/a&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms973839.aspx#dotnetperftips_topic8"&gt;Appendix: Cost of Virtual Calls and Allocations&lt;/a&gt;&lt;br /&gt;&lt;a name="dotnetperftips_topic1"&gt;&lt;/a&gt;Overview&lt;br /&gt;This white paper is designed as a reference for developers writing applications for .NET and looking for various ways to improve performance. If you are a developer who is new to .NET, you should be familiar with both the platform and your language of choice. This paper strictly builds on that knowledge, and assumes that the programmer already knows enough to get the program running. If you are porting an existing application to .NET, it's worth reading this document before you begin the port. Some of the tips here are helpful in the design phase, and provide information you should be aware of before you begin the port.&lt;br /&gt;This paper is divided into segments, with tips organized by project and developer type. The first set of tips is a must-read for writing in any language, and contains advice that will help you with any target language on the Common Language Runtime (CLR). A related section follows with ASP-specific tips. The second set of tips is organized by language, dealing with specific tips about using Managed C++ and Microsoft® Visual Basic®.&lt;br /&gt;Due to schedule limitations, the version 1 (v1) run time had to target the broadest functionality first, and then deal with special-case optimizations later. This results in a few pigeonhole cases where performance becomes an issue. As such, this paper covers several tips that are designed to avoid this case. These tips will not be relevant in the next version (vNext), as these cases are systematically identified and optimized. I'll point them out as we go, and it is up to you to decide whether it is worth the effort.&lt;br /&gt;&lt;a name="dotnetperftips_topic2"&gt;&lt;/a&gt;Performance Tips for All Applications&lt;br /&gt;There are a few tips to remember when working on the CLR in any language. These are relevant to everyone, and should be the first line of defense when dealing with performance issues.&lt;br /&gt;Throw Fewer Exceptions&lt;br /&gt;Throwing exceptions can be very expensive, so make sure that you don't throw a lot of them. Use Perfmon to see how many exceptions your application is throwing. It may surprise you to find that certain areas of your application throw more exceptions than you expected. For better granularity, you can also check the exception number programmatically by using Performance Counters.&lt;br /&gt;Finding and designing away exception-heavy code can result in a decent perf win. Bear in mind that this has nothing to do with try/catch blocks: you only incur the cost when the actual exception is thrown. You can use as many try/catch blocks as you want. Using exceptions gratuitously is where you lose performance. For example, you should stay away from things like using exceptions for control flow.&lt;br /&gt;Here's a simple example of how expensive exceptions can be: we'll simply run through a For loop, generating thousands or exceptions and then terminating. Try commenting out the throw statement to see the difference in speed: those exceptions result in tremendous overhead.&lt;br /&gt;&lt;br /&gt;public static void Main(string[] args){&lt;br /&gt;int j = 0;&lt;br /&gt;for(int i = 0; i &lt; j =" i;" href="http://msdn.microsoft.com/en-us/library/04fy9ya1.aspx"&gt;gritty details of marshalling can be explored further on the MSDN Library. I recommend reading it carefully if you spend a lot of your time marshalling.&lt;br /&gt;Design with ValueTypes&lt;br /&gt;Use simple structs when you can, and when you don't do a lot of boxing and unboxing. Here's a simple example to demonstrate the speed difference:&lt;br /&gt;using System;&lt;br /&gt;namespace ConsoleApplication{&lt;br /&gt;public struct foo{&lt;br /&gt;public foo(double arg){ this.y = arg; }&lt;br /&gt;public double y;&lt;br /&gt;}&lt;br /&gt;public class bar{&lt;br /&gt;public bar(double arg){ this.y = arg; }&lt;br /&gt;public double y;&lt;br /&gt;}&lt;br /&gt;class Class1{&lt;br /&gt;static void Main(string[] args){&lt;br /&gt;System.Console.WriteLine("starting struct loop...");&lt;br /&gt;for(int i = 0; i &lt; test =" new" i =" 0;" test2 =" new" href="http://msdn.microsoft.com/en-us/library/ms973838.aspx"&gt;Performance Considerations of Run-Time Technologies in the .NET Framework.&lt;br /&gt;Use AddRange to Add Groups&lt;br /&gt;Use AddRange to add a whole collection, rather than adding each item in the collection iteratively. Nearly all windows controls and collections have both Add and AddRange methods, and each is optimized for a different purpose. Add is useful for adding a single item, whereas AddRange has some extra overhead but wins out when adding multiple items. Here are just a few of the classes that support Add and AddRange:&lt;br /&gt;StringCollection, TraceCollection, etc.&lt;br /&gt;HttpWebRequest&lt;br /&gt;UserControl&lt;br /&gt;ColumnHeader&lt;br /&gt;Trim Your Working Set&lt;br /&gt;Minimize the number of assemblies you use to keep your working set small. If you load an entire assembly just to use one method, you're paying a tremendous cost for very little benefit. See if you can duplicate that method's functionality using code that you already have loaded.&lt;br /&gt;Keeping track of your working set is difficult, and could probably be the subject of an entire paper. Here are some tips to help you out:&lt;br /&gt;Use vadump.exe to track your working set. This is discussed in another white paper covering various tools for the managed environment.&lt;br /&gt;Look at Perfmon or Performance Counters. They can give you detail feedback about the number of classes that you load, or the number of methods that get JITed. You can get readouts for how much time you spend in the loader, or what percent of your execution time is spent paging.&lt;br /&gt;Use For Loops for String Iteration—version 1&lt;br /&gt;In C#, the foreach keyword allows you to walk across items in a list, string, etc. and perform operations on each item. This is a very powerful tool, since it acts as a general-purpose enumerator over many types. The tradeoff for this generalization is speed, and if you rely heavily on string iteration you should use a For loop instead. Since strings are simple character arrays, they can be walked using much less overhead than other structures. The JIT is smart enough (in many cases) to optimize away bounds-checking and other things inside a For loop, but is prohibited from doing this on foreach walks. The end result is that in version 1, a For loop on strings is up to five times faster than using foreach. This will change in future versions, but for version 1 this is a definite way to increase performance.&lt;br /&gt;Here's a simple test method to demonstrate the difference in speed. Try running it, then removing the For loop and uncommenting the foreach statement. On my machine, the For loop took about a second, with about 3 seconds for the foreach statement.&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;public static void Main(string[] args) {&lt;br /&gt;string s = "monkeys!";&lt;br /&gt;int dummy = 0;&lt;br /&gt;&lt;br /&gt;System.Text.StringBuilder sb = new System.Text.StringBuilder(s);&lt;br /&gt;for(int i = 0; i &lt; s =" sb.ToString();" i =" 0;" name="dotnetperftips_topic2a"&gt;Use StringBuilder for Complex String Manipulation&lt;br /&gt;When a string is modified, the run time will create a new string and return it, leaving the original to be garbage collected. Most of the time this is a fast and simple way to do it, but when a string is being modified repeatedly it begins to be a burden on performance: all of those allocations eventually get expensive. Here's a simple example of a program that appends to a string 50,000 times, followed by one that uses a StringBuilder object to modify the string in place. The StringBuilder code is much faster, and if you run them it becomes immediately obvious.&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;namespace ConsoleApplication1.Feedback&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;public class Feedback{&lt;br /&gt;public Feedback(){&lt;br /&gt;text = "You have ordered: \n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public string text;&lt;br /&gt;&lt;br /&gt;public static int Main(string[] args) {&lt;br /&gt;Feedback test = new Feedback();&lt;br /&gt;String str = test.text;&lt;br /&gt;for(int i=0;i&lt;50000;i++){ str =" str" href="javascript:CopyCode("&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;namespace ConsoleApplication1.Feedback&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;using System;&lt;br /&gt;&lt;br /&gt;public class Feedback{&lt;br /&gt;public Feedback(){&lt;br /&gt;text = "You have ordered: \n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public string text;&lt;br /&gt;&lt;br /&gt;public static int Main(string[] args) {&lt;br /&gt;Feedback test = new Feedback();&lt;br /&gt;System.Text.StringBuilder SB =&lt;br /&gt;new System.Text.StringBuilder(test.text);&lt;br /&gt;for(int i=0;i&lt;50000;i++){ name="dotnetperftips_topic3"&gt;Tips for Database Access&lt;br /&gt;The philosophy of tuning for database access is to use only the functionality that you need, and to design around a 'disconnected' approach: make several connections in sequence, rather than holding a single connection open for a long time. You should take this change into account and design around it.&lt;br /&gt;Microsoft recommends an N-Tier strategy for maximum performance, as opposed to a direct client-to-database connection. Consider this as part of your design philosophy, as many of the technologies in place are optimized to take advantage of a multi-tired scenario.&lt;br /&gt;Use the Optimal Managed Provider&lt;br /&gt;Make the correct choice of managed provider, rather than relying on a generic accessor. There are managed providers written specifically for many different databases, such as SQL (System.Data.SqlClient). If you use a more generic interface such as System.Data.Odbc when you could be using a specialized component, you will lose performance dealing with the added level of indirection. Using the optimal provider can also have you speaking a different language: the Managed SQL Client speaks TDS to a SQL database, providing a dramatic improvement over the generic OleDbprotocol.&lt;br /&gt;Pick Data Reader Over Data Set When You Can&lt;br /&gt;Use a data reader whenever when you don't need to keep the data lying around. This allows a fast read of the data, which can be cached if the user desires. A reader is simply a stateless stream that allows you to read data as it arrives, and then drop it without storing it to a dataset for more navigation. The stream approach is faster and has less overhead, since you can start using data immediately. You should evaluate how often you need the same data to decide if the caching for navigation makes sense for you. Here's a small table demonstrating the difference between DataReader and DataSet on both ODBC and SQL providers when pulling data from a server (higher numbers are better):&lt;br /&gt;&lt;br /&gt;ADO&lt;br /&gt;SQL&lt;br /&gt;DataSet&lt;br /&gt;801&lt;br /&gt;2507&lt;br /&gt;DataReader&lt;br /&gt;1083&lt;br /&gt;4585&lt;br /&gt;As you can see, the highest performance is achieved when using the optimal managed provider along with a data reader. When you don't need to cache your data, using a data reader can provide you with an enormous performance boost.&lt;br /&gt;Use Mscorsvr.dll for MP Machines&lt;br /&gt;For stand-alone middle-tier and server applications, make sure mscorsvr is being used for multiprocessor machines. Mscorwks is not optimized for scaling or throughput, while the server version has several optimizations that allow it to scale well when more than one processor is available.&lt;br /&gt;Use Stored Procedures Whenever Possible&lt;br /&gt;Stored procedures are highly optimized tools that result in excellent performance when used effectively. Set up stored procedures to handle inserts, updates, and deletes with the data adapter. Stored procedures do not have to be interpreted, compiled or even transmitted from the client, and cut down on both network traffic and server overhead. Be sure to use CommandType.StoredProcedure instead of CommandType.Text&lt;br /&gt;Be Careful About Dynamic Connection Strings&lt;br /&gt;Connection pooling is a useful way to reuse connections for multiple requests, rather than paying the overhead of opening and closing a connection for each request. It's done implicitly, but you get one pool per unique connection string. If you're generating connection strings dynamically, make sure the strings are identical each time so pooling occurs. Also be aware that if delegation is occurring, you'll get one pool per user. There are a lot of options that you can set for the connection pool, and you can track the performance of the pool by using the Perfmon to keep track of things like response time, transactions/sec, etc.&lt;br /&gt;Turn Off Features You Don't Use&lt;br /&gt;Turn off automatic transaction enlistment if it's not needed. For the SQL Managed Provider, it's done via the connection string:&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;SqlConnection conn = new SqlConnection(&lt;br /&gt;"Server=mysrv01;&lt;br /&gt;Integrated Security=true;&lt;br /&gt;Enlist=false");&lt;br /&gt;When filling a dataset with the data adapter, don't get primary key information if you don't have to (e.g. don't set MissingSchemaAction.Add with key):&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;public DataSet SelectSqlSrvRows(DataSet dataset,string connection,string query){&lt;br /&gt;SqlConnection conn = new SqlConnection(connection);&lt;br /&gt;SqlDataAdapter adapter = new SqlDataAdapter();&lt;br /&gt;adapter.SelectCommand = new SqlCommand(query, conn);&lt;br /&gt;adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;&lt;br /&gt;adapter.Fill(dataset);&lt;br /&gt;return dataset;&lt;br /&gt;}&lt;br /&gt;Avoid Auto-Generated Commands&lt;br /&gt;When using a data adapter, avoid auto-generated commands. These require additional trips to the server to retrieve meta data, and give you a lower level of interaction control. While using auto-generated commands is convenient, it's worth the effort to do it yourself in performance-critical applications.&lt;br /&gt;Beware ADO Legacy Design&lt;br /&gt;Be aware that when you execute a command or call fill on the adapter, every record specified by your query is returned.&lt;br /&gt;If server cursors are absolutely required, they can be implemented through a stored procedure in t-sql. Avoid where possible because server cursor-based implementations don't scale very well.&lt;br /&gt;If needed, implement paging in a stateless and connectionless manner. You can add additional records to the dataset by:&lt;br /&gt;Making sure PK info is present&lt;br /&gt;Changing the data adapter's select command as appropriate, and&lt;br /&gt;Calling Fill&lt;br /&gt;Keep Your Datasets Lean&lt;br /&gt;Only put the records you need into the dataset. Remember that the dataset stores all of its data in memory, and that the more data you request, the longer it will take to transmit across the wire.&lt;br /&gt;Use Sequential Access as Often as Possible&lt;br /&gt;With a data reader, use CommandBehavior.SequentialAccess. This is essential for dealing with blob data types since it allows data to be read off of the wire in small chunks. While you can only work with one piece of the data at a time, the latency for loading a large data type disappears. If you don't need to work the whole object at once, using Sequential Access will give you much better performance.&lt;br /&gt;&lt;a name="dotnetperftips_topic4"&gt;&lt;/a&gt;Performance Tips for ASP.NET Applications&lt;br /&gt;Cache Aggressively&lt;br /&gt;When designing an app using ASP.NET, make sure you design with an eye on caching. On server versions of the OS, you have a lot of options for tweaking the use of caches on the server and client side. There are several features and tools in ASP that you can make use of to gain performance.&lt;br /&gt;Output Caching—Stores the static result of an ASP request. Specified using the &lt;@% OutputCache %&gt; directive:&lt;br /&gt;Duration—Time item exists in the cache&lt;br /&gt;VaryByParam—Varies cache entries by Get/Post params&lt;br /&gt;VaryByHeader—Varies cache entries by Http header&lt;br /&gt;VaryByCustom—Varies cache entries by browser&lt;br /&gt;Override to vary by whatever you want:&lt;br /&gt;Fragment Caching—When it is not possible to store an entire page (privacy, personalization, dynamic content), you can use fragment caching to store parts of it for quicker retrieval later.&lt;br /&gt;a) VaryByControl—Varies the cached items by values of a control&lt;br /&gt;Cache API—Provides extremely fine granularity for caching by keeping a hashtable of cached objects in memory (System.web.UI.caching). It also:&lt;br /&gt;a) Includes Dependencies (key, file, time)&lt;br /&gt;b) Automatically expires unused items&lt;br /&gt;c) Supports Callbacks&lt;br /&gt;Caching intelligently can give you excellent performance, and it's important to think about what kind of caching you need. Imagine a complex e-commerce site with several static pages for login, and then a slew of dynamically-generated pages containing images and text. You might want to use Output Caching for those login pages, and then Fragment Caching for the dynamic pages. A toolbar, for example, could be cached as a fragment. For even better performance, you could cache commonly used images and boilerplate text that appear frequently on the site using the Cache API. For detailed information on caching (with sample code), check out the &lt;a href="http://www.gotdotnet.com/quickstart/aspplus/"&gt;ASP. NET&lt;/a&gt; Web site.&lt;br /&gt;Use Session State Only If You Need To&lt;br /&gt;One extremely powerful feature of ASP.NET is its ability to store session state for users, such as a shopping cart on an e-commerce site or a browser history. Since this is on by default, you pay the cost in memory even if you don't use it. If you're not using Session State, turn it off and save yourself the overhead by adding &lt;@% EnabledSessionState = false %&gt; to your asp. This comes with several other options, which are explained at the &lt;a href="http://www.gotdotnet.com/quickstart/aspplus/"&gt;ASP. NET&lt;/a&gt; Web site.&lt;br /&gt;For pages that only read session state, you can choose EnabledSessionState=readonly. This carries less overhead than full read/write session state, and is useful when you need only part of the functionality and don't want to pay for the write capabilities.&lt;br /&gt;Use View State Only If You Need To&lt;br /&gt;An example of View State might be a long form that users must fill out: if they click Back in their browser and then return, the form will remain filled. When this functionality isn't used, this state eats up memory and performance. Perhaps the largest performance drain here is that a round-trip signal must be sent across the network each time the page is loaded to update and verify the cache. Since it is on by default, you will need to specify that you do not want to use View State with &lt;@% EnabledViewState = false %&gt;. You should read more about View State on the the &lt;a href="http://www.gotdotnet.com/quickstart/aspplus/"&gt;ASP. NET&lt;/a&gt; Web site to learn about some of the other options and settings to which you have access.&lt;br /&gt;Avoid STA COM&lt;br /&gt;Apartment COM is designed to deal with threading in unmanaged environments. There are two kinds of Apartment COM: single-threaded and multithreaded. MTA COM is designed to handle multithreading, whereas STA COM relies on the messaging system to serialize thread requests. The managed world is free-threaded, and using Single Threaded Apartment COM requires that all unmanaged threads essentially share a single thread for interop. This results in a massive performance hit, and should be avoided whenever possible. If you can't port the Apartment COM object to the managed world, use &lt;@%AspCompat = "true" %&gt; for pages that use them. For a more &lt;a href="http://msdn.microsoft.com/en-us/library/ms809311.aspx"&gt;detailed explanation of STA COM&lt;/a&gt;, see the MSDN Library.&lt;br /&gt;Batch Compile&lt;br /&gt;Always batch compile before deploying a large page into the Web. This can be initiated by doing one request to a page per directory and waiting until the CPU idles again. This prevents the Web server from being bogged down with compilations while also trying to serve out pages.&lt;br /&gt;Remove Unnecessary Http Modules&lt;br /&gt;Depending on the features used, remove unused or unnecessary http modules from the pipeline. Reclaiming the added memory and wasted cycles can provide you with a small speed boost.&lt;br /&gt;Avoid the Autoeventwireup Feature&lt;br /&gt;Instead of relying on autoeventwireup, override the events from Page. For example, instead of writing a Page_Load() method, try overloading the public void OnLoad() method. This allows the run time from having to do a CreateDelegate() for every page.&lt;br /&gt;Encode Using ASCII When You Don't Need UTF&lt;br /&gt;By default, ASP.NET comes configured to encode requests and responses as UTF-8. If ASCII is all your application needs, eliminated the UTF overhead can give you back a few cycles. Note that this can only be done on a per-application basis.&lt;br /&gt;Use the Optimal Authentication Procedure&lt;br /&gt;There are several different ways to authenticate a user and some of more expensive than others (in order of increasing cost: None, Windows, Forms, Passport). Make sure you use the cheapest one that best fits your needs.&lt;br /&gt;&lt;a name="dotnetperftips_topic5"&gt;&lt;/a&gt;Tips for Porting and Developing in Visual Basic&lt;br /&gt;A lot has changed under the hood from Microsoft® Visual Basic® 6 to Microsoft® Visual Basic® 7, and the performance map has changed with it. Due to the added functionality and security restrictions of the CLR, some functions are simply unable to run as quickly as they did in Visual Basic 6. In fact, there are several areas where Visual Basic 7 gets trounced by its predecessor. Fortunately, there are two pieces of good news:&lt;br /&gt;Most of the worst slowdowns occur during one-time functions, such as loading a control for the first time. The cost is there, but you only pay it once.&lt;br /&gt;There are a lot of areas where Visual Basic 7 is faster, and these areas tend to lie in functions that are repeated during run time. This means that the benefit grows over time, and in several cases will outweigh the one-time costs.&lt;br /&gt;The majority of the performance issues come from areas where the run time does not support a feature of Visual Basic 6, and it has to be added to preserve the feature in Visual Basic 7. Working outside of the run time is slower, making some features far more expensive to use. The bright side is that you can avoid these problems with a little effort. There are two main areas that require work to optimize for performance, and few simple tweaks you can do here and there. Taken together, these can help you step around performance drains, and take advantage of the functions that are much faster in Visual Basic 7.&lt;br /&gt;Error Handling&lt;br /&gt;The first concern is error handling. This has changed a lot in Visual Basic 7, and there are performance issues related to the change. Essentially, the logic required to implement OnErrorGoto and Resume is extremely expensive. I suggest taking a quick look at your code, and highlighting all the areas where you use the Err object, or any error-handling mechanism. Now look at each of these instances, and see if you can rewrite them to use try/catch. A lot of developers will find that they can convert to try/catch easily for most of these cases, and they should see a good performance improvement in their program. The rule of thumb is "if you can easily see the translation, do it."&lt;br /&gt;Here's an example of a simple Visual Basic program that uses On Error Goto compared with the try/catch version.&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;Sub SubWithError(&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;On Error Goto SWETrap&lt;br /&gt;Dim x As Integer&lt;br /&gt;Dim y As Integer&lt;br /&gt;x = x / y&lt;br /&gt;SWETrap:&lt;br /&gt;Exit Sub&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Sub SubWithErrorResumeLabel()&lt;br /&gt;On Error Goto SWERLTrap&lt;br /&gt;Dim x As Integer&lt;br /&gt;Dim y As Integer&lt;br /&gt;x = x / y&lt;br /&gt;SWERLTrap:&lt;br /&gt;Resume SWERLExit&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;SWERLExit:&lt;br /&gt;Exit Sub&lt;br /&gt;&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;Sub SubWithError(&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;Dim x As Integer&lt;br /&gt;Dim y As Integer&lt;br /&gt;Try&lt;br /&gt;x = x / y&lt;br /&gt;Catch&lt;br /&gt;Return&lt;br /&gt;End Try&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;Sub SubWithErrorResumeLabel()&lt;br /&gt;Dim x As Integer&lt;br /&gt;Dim y As Integer&lt;br /&gt;Try&lt;br /&gt;x = x / y&lt;br /&gt;Catch&lt;br /&gt;Goto SWERLExit&lt;br /&gt;End Try&lt;br /&gt;&lt;br /&gt;SWERLExit:&lt;br /&gt;Return&lt;br /&gt;End Sub&lt;br /&gt;&lt;br /&gt;The speed increase is noticeable. SubWithError() takes 244 milliseconds using OnErrorGoto, and only 169 milliseconds using try/catch. The second function takes 179 milliseconds compared to 164 milliseconds for the optimized version.&lt;br /&gt;Use Early Binding&lt;br /&gt;The second concern deals with objects and typecasting. Visual Basic 6 does a lot of work under the hood to support casting of objects, and many programmers aren't even aware of it. In Visual Basic 7, this is an area that out of which you can squeeze a lot of performance. When you compile, use early binding. This tells the compiler to insert a Type Coercion is only done when explicitly mentioned. This has two major effects:&lt;br /&gt;Strange errors become easier to track down.&lt;br /&gt;Unneeded coercions are eliminated, leading to substantial performance improvements.&lt;br /&gt;When you use an object as if it were of a different type, Visual Basic will coerce the object for you if you don't specify. This is handy, since the programmer has to worry about less code. The downside is that these coercions can do unexpected things, and the programmer has no control over them.&lt;br /&gt;There are instances when you have to use late binding, but most of the time if you're not sure then you can get away with early binding. For Visual Basic 6 programmers, this can be a bit awkward at first, since you have to worry about types more than in the past. This should be easy for new programmers, and people familiar with Visual Basic 6 will pick it up in no time.&lt;br /&gt;Turn On Option Strict and Explicit&lt;br /&gt;With Option Strict on, you protect yourself from inadvertent late binding and enforce a higher level of coding discipline. For a list of the restrictions present with Option Strict, see the MSDN Library. The caveat to this is that all narrowing type coercions must be explicitly specified. However, this in itself may uncover other sections of your code that are doing more work than you had previously thought, and it may help you stomp some bugs in the process.&lt;br /&gt;Option Explicit is less restrictive than Option Strict, but it still forces programmers to provide more information in their code. Specifically, you must declare a variable before using it. This moves the type-inference from the run time into compile time. This eliminated check translates into added performance for you.&lt;br /&gt;I recommend that you start with Option Explicit, and then turn on Option Strict. This will protect you from a deluge of compiler errors, and allow you to gradually start working in the stricter environment. When both of these options are used, you ensure maximum performance for your application.&lt;br /&gt;Use Binary Compare for Text&lt;br /&gt;When comparing text, use binary compare instead of text compare. At run time, the overhead is much lighter for binary.&lt;br /&gt;Minimize the Use of Format()&lt;br /&gt;When you can, use toString() instead of format(). In most cases, it will provide you with the functionality you need, with much less overhead.&lt;br /&gt;Use Charw&lt;br /&gt;Use charw instead of char. The CLR uses Unicode internally, and char must be translated at run time if it is used. This can result in a substantial performance loss, and specifying that your characters are a full word long (using charw) eliminates this conversion.&lt;br /&gt;Optimize Assignments&lt;br /&gt;Use exp += val instead of exp = exp + val. Since exp can be arbitrarily complex, this can result in lots of unnecessary work. This forces the JIT to evaluate both copies of exp, and many times this is not needed. The first statement can be optimized far better than the second, since the JIT can avoid evaluating the exp twice.&lt;br /&gt;Avoid Unnecessary Indirection&lt;br /&gt;When you use byRef, you pass pointers instead of the actual object. Many times this makes sense (side-effecting functions, for example), but you don't always need it. Passing pointers results in more indirection, which is slower than accessing a value that is on the stack. When you don't need to go through the heap, it is best to avoid it.&lt;br /&gt;Put Concatenations in One Expression&lt;br /&gt;If you have multiple concatenations on multiple lines, try to stick them all on one expression. The compiler can optimize by modifying the string in place, providing a speed and memory boost. If the statements are split into multiple lines, the Visual Basic compiler will not generate the Microsoft Intermediate Language (MSIL) to allow in-place concatenation. See the &lt;a href="http://msdn.microsoft.com/en-us/library/ms973839.aspx#dotnetperftips_topic2a"&gt;StringBuilder example&lt;/a&gt; discussed earlier.&lt;br /&gt;Include Return Statements&lt;br /&gt;Visual Basic allows a function to return a value without using the return statement. While Visual Basic 7 supports this, explicitly using return allows the JIT to perform slightly more optimizations. Without a return statement, each function is given several local variables on stack to transparently support returning values without the keyword. Keeping these around makes it harder for the JIT to optimize, and can impact the performance of your code. Look through your functions and insert return as needed. It doesn't change the semantics of the code at all, and it can help you get more speed from your application.&lt;br /&gt;&lt;a name="dotnetperftips_topic6"&gt;&lt;/a&gt;Tips for Porting and Developing in Managed C++&lt;br /&gt;Microsoft is targeting Managed C++ (MC++) at a specific set of developers. MC++ is not the best tool for every job. After reading this document, you may decide that C++ is not the best tool, and that the tradeoff costs are not worth the benefits. If you aren't sure about MC++, there are many good &lt;a href="http://msdn.microsoft.com/vstudio/techinfo/articles/upgrade/managedext.asp"&gt;resources&lt;/a&gt; to help you make your decision This section is targeted at developers who have already decided that they want to use MC++ in some way, and want to know about the performance aspects of it.&lt;br /&gt;For C++ developers, working Managed C++ requires that several decisions be made. Are you porting some old code? If so, do you want to move the entire thing to managed space or are you instead planning to implement a wrapper? I'm going to focus on the 'port-everything' option or deal with writing MC++ from scratch for the purposes of this discussion, since those are the scenarios where the programmer will notice a performance difference.&lt;br /&gt;Benefits of the Managed World&lt;br /&gt;The most powerful feature of Managed C++ is the ability to mix and match managed and unmanaged code at the expression level. No other language allows you to do this, and there are some powerful benefits you can get from it if used properly. I'll walk through some examples of this later on.&lt;br /&gt;The managed world also gives you huge design wins, in that a lot of common problems are taken care of for you. Memory management, thread scheduling and type coercions can be left to the run time if you desire, allowing you to focus your energies on the parts of the program that need it. With MC++, you can choose exactly how much control you want to keep.&lt;br /&gt;MC++ programmers have the luxury of being able to use the Microsoft Visual C® 7 (VC7) backend when compiling to IL, and then using the JIT on top of that. Programmers that are used to working with the Microsoft C++ compiler are used to things being lightning-fast. The JIT was designed with different goals, and has a different set of strengths and weaknesses. The VC7 compiler, not bound by the time restrictions of the JIT, can perform certain optimizations that the JIT cannot, such as whole-program analysis, more aggressive inlining and enregistration. There are also some optimizations that can be performed only in typesafe environments, leaving more room for speed than C++ allows.&lt;br /&gt;Because of the different priorities in the JIT, some operations are faster than before while others are slower. There are tradeoffs you make for safety and language flexibility, and some of them aren't cheap. Fortunately, there are things a programmer can do to minimize the costs.&lt;br /&gt;Porting: All C++ Code Can Compile to MSIL&lt;br /&gt;Before we go any further, it's important to note that you can compile any C++ code into MSIL. Everything will work, but there's no guarantee of type-safety and you pay the marshalling penalty if you do a lot of interop. Why is it helpful to compile to MSIL if you don't get any of the benefits? In situations where you are porting a large code base, this allows you to gradually port your code in pieces. You can spend your time porting more code, rather than writing special wrappers to glue the ported and not-yet-ported code together if you use MC++, and that can result in a big win. It makes porting applications a very clean process. To learn more about compiling C++ to MSIL, take a look at the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlvalidatingreader.readtypedvalue.aspx"&gt;/clr compiler option&lt;/a&gt;.&lt;br /&gt;However, simply compiling your C++ code to MSIL doesn't give you the security or flexibility of the managed world. You need to write in MC++, and in v1 that means giving up a few features. The list below is not supported in the current version of the CLR, but may be in the future. Microsoft chose to support the most common features first, and had to cut some others in order to ship. There is nothing that prevents them from being added later, but in the meantime you will need to do without them:&lt;br /&gt;Multiple Inheritance&lt;br /&gt;Templates&lt;br /&gt;Deterministic Finalization&lt;br /&gt;You can always interoperate with unsafe code if you need those features, but you will pay the performance penalty of marshalling data back and forth. And bear in mind that those features can only be used inside the unmanaged code. The managed space has no knowledge of their existence. If you are deciding to port your code, think about how much you rely on those features in your design. In a few cases, the redesign is too expensive and you will want to stick with unmanaged code. This is the first decision you should make, before you start hacking.&lt;br /&gt;Advantages of MC++ Over C# or Visual Basic&lt;br /&gt;Coming from an unmanaged background, MC++ preserves a lot of the ability to handle unsafe code. MC++'s ability to mix managed and unmanaged code smoothly provides the developer with a lot of power, and you can choose where on the gradient you want to sit when writing your code. On one extreme, you can write everything in straight, unadulterated C++ and just compile with /clr. On the other, you can write everything as managed objects and deal with the language limitations and performance problems mentioned above.&lt;br /&gt;But the real power of MC++ comes when you choose somewhere in between. MC++ allows you to tweak some of the performance hits inherent in managed code, by giving you precise control over when to use unsafe features. C# has some of this functionality in the unsafe keyword, but it's not an integral part of the language and it is far less useful than MC++. Let's step through some examples showing the finer granularity available in MC++, and we'll talk about the situations where it comes in handy.&lt;br /&gt;Generalized "byref" pointers&lt;br /&gt;In C# you can only take the address of some member of a class by passing it to a ref parameter. In MC++, a byref pointer is a first-class construct. You can take the address of an item in the middle of an array and return that address from a function:&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;Byte* AddrInArray( Byte b[] ) {&lt;br /&gt;return &amp;amp;b[5];&lt;br /&gt;}&lt;br /&gt;We exploit this feature for returning a pointer to the "characters" in a System.String via our helper routine, and we can even loop through arrays using these pointers:&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;System::Char* PtrToStringChars(System::String*);&lt;br /&gt;for( Char*pC = PtrToStringChars(S"boo");&lt;br /&gt;pC != NULL;&lt;br /&gt;pC++ )&lt;br /&gt;{&lt;br /&gt;... *pC ...&lt;br /&gt;}&lt;br /&gt;You can also do a linked-list traversal with injection in MC++ by taking the address of the "next" field (which you cannot do in C#):&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;Node **w = &amp;Head;&lt;br /&gt;while(true) {&lt;br /&gt;if( *w == 0 val &lt; (*w)-&gt;val ) {&lt;br /&gt;Node *t = new Node(val,*w);&lt;br /&gt;*w = t;&lt;br /&gt;break;&lt;br /&gt;}&lt;br /&gt;w = &amp;amp;(*w)-&gt;next;&lt;br /&gt;}&lt;br /&gt;In C#, you can't point to "Head", or take the address of the "next" field, so you have make a special-case where you're inserting at the first location, or if "Head" is null. Moreover, you have to look one node ahead all the time in the code. Compare this to what a good C# would produce:&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;if( Head==null val &lt; t =" new" head =" t;" w="Head;" next ="=" t =" new" next =" t;" w =" w.next;" href="javascript:CopyCode("&gt;&lt;br /&gt;__value struct V {&lt;br /&gt;int i;&lt;br /&gt;};&lt;br /&gt;int main() {&lt;br /&gt;V v = {10};&lt;br /&gt;__box V *pbV = __box(v);&lt;br /&gt;pbV-&gt;i += 10; // update without casting&lt;br /&gt;}&lt;br /&gt;In C# you have to unbox to a "v", then update the value and re-box back to an Object:&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;struct B { public int i; }&lt;br /&gt;static void Main() {&lt;br /&gt;B b = new B();&lt;br /&gt;b.i = 5;&lt;br /&gt;object o = b; // implicit box&lt;br /&gt;B b2 = (B)o; // explicit unbox&lt;br /&gt;b2.i++; // update&lt;br /&gt;o = b2; // implicit re-box&lt;br /&gt;}&lt;br /&gt;STL Collections vs. Managed Collections—v1&lt;br /&gt;The bad news: In C++, using the STL Collections was often just as fast as writing that functionality by hand. The CLR frameworks are very fast, but they suffer from boxing and unboxing issues: everything is an object, and without template or generic support, all actions have to be checked at run time.&lt;br /&gt;The good news: In the long term, you can bet that this problem will go away as generics are added to the run time. Code you deploy today will experience the speed boost without any changes. In the short term, you can use static casting to prevent the check, but this is no longer safe. I recommend using this method in tight code where performance is absolutely critical, and you've identified two or three hot spots.&lt;br /&gt;Use Stack Managed Objects&lt;br /&gt;In C++, you specify that an object should be managed by the stack or the heap. You can still do this in MC++, but there are restrictions you should be aware of. The CLR uses ValueTypes for all stack-managed objects, and there are limitations to what ValueTypes can do (no inheritance, for example). &lt;a href="http://msdn.microsoft.com/en-us/library/aa735672.aspx"&gt;More information&lt;/a&gt; is available on the MSDN Library.&lt;br /&gt;Corner Case: Beware Indirect Calls Within Managed Code—v1&lt;br /&gt;In the v1 run time, all indirect function calls are made natively, and therefore require a transition into unmanaged space. Any indirect function call can only be made from native mode, which means that all indirect calls from managed code need a managed-to-unmanaged transition. This is a serious problem when the table returns a managed function, since a second transition must then be made to execute the function. When compared to the cost of executing a single Call instruction, the cost is fifty- to one hundred times slower than in C++!&lt;br /&gt;Fortunately, when you are calling a method that resides within a garbage-collected class, optimization removes this. However, in the specific case of a regular C++ file that has been compiled using /clr, the method return will be considered managed. Since this cannot be removed by optimization, you are hit with the full double-transition cost. Below is an example of such a case.&lt;br /&gt;&lt;a href="javascript:CopyCode("&gt;&lt;/a&gt;&lt;br /&gt;//////////////////////// a.h: //////////////////////////&lt;br /&gt;class X {&lt;br /&gt;public:&lt;br /&gt;void mf1();&lt;br /&gt;void mf2();&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;typedef void (X::*pMFunc_t)();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;////////////// a.cpp: compiled with /clr /////////////////&lt;br /&gt;#include "a.h"&lt;br /&gt;&lt;br /&gt;int main(){&lt;br /&gt;pMFunc_t pmf1 = &amp;amp;X::mf1;&lt;br /&gt;pMFunc_t pmf2 = &amp;amp;X::mf2;&lt;br /&gt;&lt;br /&gt;X *pX = new X();&lt;br /&gt;(pX-&gt;*pmf1)();&lt;br /&gt;(pX-&gt;*pmf2)();&lt;br /&gt;&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;////////////// b.cpp: compiled without /clr /////////////////&lt;br /&gt;#include "a.h"&lt;br /&gt;&lt;br /&gt;void X::mf1(){}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;////////////// c.cpp: compiled with /clr ////////////////////&lt;br /&gt;#include "a.h"&lt;br /&gt;void X::mf2(){}&lt;br /&gt;There are several ways to avoid this:&lt;br /&gt;Make the class into a managed class ("__gc")&lt;br /&gt;Remove the indirect call, if possible&lt;br /&gt;Leave the class compiled as unmanaged code (e.g. do not use /clr)&lt;br /&gt;Minimize Performance Hits—version 1&lt;br /&gt;There are several operations or features that are simply more expensive in MC++ under version 1 JIT. I'll list them and give some explanation, and then we'll talk about what you can do about them.&lt;br /&gt;Abstractions—This is an area where the beefy, slow C++ backend compiler wins heavily over the JIT. If you wrap an int inside a class for abstraction purposes, and you access it strictly as an int, the C++ compiler can reduce the overhead of the wrapper to practically nothing. You can add many levels of abstraction to the wrapper, without increasing the cost. The JIT is unable to take the time necessary to eliminate this cost, making deep abstractions more expensive in MC++.&lt;br /&gt;Floating Point—The v1 JIT does not currently perform all the FP-specific optimizations that the VC++ backend does, making floating point operations more expensive for now.&lt;br /&gt;Multidimensional Arrays—The JIT is better at handling jagged arrays than multidimensional ones, so use jagged arrays instead.&lt;br /&gt;64 bit Arithmetic—In future versions, 64-bit optimizations will be added to the JIT.&lt;br /&gt;What You Can Do&lt;br /&gt;At every phase of development, there are several things you can do. With MC++, the design phase is perhaps the most important area, as it will determine how much work you end up doing and how much performance you get in return. When you sit down to write or port an application, you should consider the following things:&lt;br /&gt;Identify areas where you use multiple inheritance, templates, or deterministic finalization. You will have to get rid of these, or else leave that part of your code in unmanaged space. Think about the cost of redesigning, and identify areas that can be ported.&lt;br /&gt;Locate performance hot spots, such as deep abstractions or virtual function calls across managed space. These will also require a design decision.&lt;br /&gt;Look for objects that have been specified as stack-managed. Make sure they can be converted into ValueTypes. Mark the others for conversion to heap-managed objects.&lt;br /&gt;During the coding stage, you should be aware of the operations that are more expensive and the options you have in dealing with them. One of the nicest things about MC++ is that you come to grips with all the performance issues up front, before you start coding: this is helpful in paring down work later on. However, there are still some tweaks you can perform while you code and debug.&lt;br /&gt;Determine which areas make heavy use of floating point arithmetic, multidimensional arrays or library functions. Which of these areas are performance critical? Use profilers to pick the fragments where the overhead is costing you most, and pick which option seems best:&lt;br /&gt;Keep the whole fragment in unmanaged space.&lt;br /&gt;Use static casts on the library accesses.&lt;br /&gt;Try tweaking boxing/unboxing behavior (explained later).&lt;br /&gt;Code your own structure.&lt;br /&gt;Finally, work to minimize the number of transitions you make. If you have some unmanaged code or an interop call sitting in a loop, make the entire loop unmanaged. That way you'll only pay the transition cost twice, rather than for each iteration of the loop.&lt;br /&gt;&lt;a name="dotnetperftips_topic7"&gt;&lt;/a&gt;Additional Resources&lt;br /&gt;Related topics on performance in the .NET Framework include:&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms973838.aspx"&gt;Performance Considerations of Run-Time Technologies in the .NET Framework&lt;/a&gt;&lt;br /&gt;Watch for future articles currently under development, including an overview of design, architectural and coding philosophies, a walkthrough of performance analysis tools in the managed world, and a performance comparison of .NET to other enterprise applications available today.&lt;br /&gt;&lt;a name="dotnetperftips_topic8"&gt;&lt;/a&gt;Appendix: Cost of Virtual Calls and Allocations&lt;br /&gt;Call Type&lt;br /&gt;# Calls/sec&lt;br /&gt;ValueType Non-Virtual Call&lt;br /&gt;809971805.600&lt;br /&gt;Class Non-Virtual Call&lt;br /&gt;268478412.546&lt;br /&gt;Class Virtual Call&lt;br /&gt;109117738.369&lt;br /&gt;ValueType Virtual (Obj Method) Call&lt;br /&gt;3004286.205&lt;br /&gt;ValueType Virtual (Overridden Obj Method) Call&lt;br /&gt;2917140.844&lt;br /&gt;Load Type by Newing (Non-Static)&lt;br /&gt;1434.720&lt;br /&gt;Load Type by Newing (Virtual Methods)&lt;br /&gt;1369.863&lt;br /&gt;Note The test machine is a PIII 733Mhz, running Windows 2000 Professional with Service Pack 2.&lt;br /&gt;This chart compares the cost associated with different types of method calls, as well as the cost of instantiating a type that contains virtual methods. The higher the number, the more calls/instantiations-per-second can be performed. While these numbers will certainly vary on different machines and configurations, the relative cost of performing one call over another remains significant.&lt;br /&gt;ValueType Non-Virtual Call: This test calls an empty non-virtual method contained within a ValueType.&lt;br /&gt;Class Non-Virtual Call: This test calls an empty non-virtual method contained within a class.&lt;br /&gt;Class Virtual Call: This test calls an empty virtual method contained within a class.&lt;br /&gt;ValueType Virtual (Obj Method) Call: This test calls ToString() (a virtual method) on a ValueType, which resorts to the default object method.&lt;br /&gt;ValueType Virtual (Overridden Obj Method) Call: This test calls ToString() (a virtual method) on a ValueType that has overridden the default.&lt;br /&gt;Load Type by Newing (Static): This test allocates space for a class with only static methods.&lt;br /&gt;Load Type by Newing (Virtual Methods): This test allocates space for a class with virtual methods.&lt;br /&gt;One conclusion you can draw is that Virtual Function calls are about two times as expensive as regular calls when you're calling a method in a class. Bear in mind that calls are cheap to begin with, so I wouldn't remove all virtual calls. You should always use virtual methods when it makes sense to do so.&lt;br /&gt;The JIT cannot inline virtual methods, so you lose a potential optimization if you get rid of non-virtual methods.&lt;br /&gt;Allocating space for an object that has virtual methods is slightly slower than the allocation for an object without them, since extra work must be done to find space for the virtual tables.&lt;br /&gt;Notice that calling a non-virtual method within a ValueType is more than three times as fast as in a class, but once you treat it as a class you lose terribly. This is characteristic of ValueTypes: treat them like structs and they're lighting fast. Treat them like classes and they're painfully slow. ToString() is a virtual method, so before it can be called, the struct must be converted to an object on the heap. Instead of being twice as slow, calling a virtual method on a ValueType is now eighteen times as slow! The moral of the story? Don't treat ValueTypes as classes. &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-694799667369973262?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/694799667369973262/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=694799667369973262' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/694799667369973262'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/694799667369973262'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/11/performance-tips-and-tricks-in-net.html' title='Performance Tips and Tricks in .NET Applications'/><author><name>Piyush Srivastava</name><uri>http://www.blogger.com/profile/07995834856320205913</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_278xsQcO1rU/TUlTVvyJ9II/AAAAAAAAABw/_lmK-mo5EEY/s220/Image0833.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-118110607952857100</id><published>2008-11-04T21:27:00.000-08:00</published><updated>2008-11-04T21:48:18.413-08:00</updated><title type='text'>What is LINQ?</title><content type='html'>&lt;ul&gt;&lt;li&gt;&lt;div align="justify"&gt;&lt;br /&gt;&lt;strong&gt;&lt;u&gt;Microsoft Babies&lt;/u&gt;&lt;br /&gt;&lt;/strong&gt;Microsoft new baby yes I am talking about LINQ stand for Language-Integrated Query is now available as a integral part of Visual Studio Orcas. Microsoft releases the new Visual Studio with the name of Orcas and all Microsoft previous efforts (Windows Communication Foundation WCF, Windows Workflow Foundation WWF, Windows Presentation Foundation WPF, Windows CardSpace and LINQ) are integrated in this Studio. From last one and half years Anders Hejlsberg team done a tremendous job in the overcoming the gap between the data impedance. Mr. Anders team gives a native syntax to developers in the form LINQ to C# and VB.Net for accessing data from any repository. The repository could be in memory object, database (still MS SQL Server only) and XML files.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is LINQ?&lt;/strong&gt;&lt;br /&gt;Still lots of folks don’t understand what LINQ is doing. Basically LINQ address the current database development model in the context of Object Oriented Programming Model. If some one wants to develop database application on .Net platform the very simple approach he uses ADO.Net. ADO.Net is serving as middle ware in application and provides complete object oriented wrapper around the database SQL. Developing application in C# and VB.Net so developer must have good knowledge of object oriented concept as well as SQL, so it means developer must be familiar with both technologies to develop an application. If here I can say SQL statements are become part of the C# and VB.Net code so it’s not mistaken in form of LINQ. According to Anders Hejlsberg the chief architect of C#.&lt;br /&gt;&lt;br /&gt;“Microsoft original motivation behind LINQ was to address the impedance mismatch between programming languages and database.”&lt;br /&gt;&lt;br /&gt;LINQ has a great power of querying on any source of data, data source could be the collections of objects, database or XML files. We can easily retrieve data from any object that implements the IEnumerable&lt;t&gt; interface. Microsoft basically divides LINQ into three areas and that are give below.&lt;br /&gt;&lt;br /&gt;LINQ to Object {Queries performed against the in-memory data}&lt;br /&gt;LINQ to ADO.Net&lt;br /&gt;LINQ to SQL (formerly DLinq) {Queries performed against the relation database only Microsoft SQL Server Supported}&lt;br /&gt;LINQ to DataSet {Supports queries by using ADO.NET data sets and data tables}&lt;br /&gt;LINQ to Entities {Microsoft ORM solution}&lt;br /&gt;LINQ to XML (formerly XLinq) { Queries performed against the XML source}&lt;br /&gt;&lt;br /&gt;I hope few above lines increase your concrete knowledge about Microsoft LINQ and now we write some code snippet of LINQ.&lt;br /&gt;Code Snippet&lt;br /&gt;int[] nums = &lt;a href="http://www.google.com/search?q=new+msdn.microsoft.com"&gt;new&lt;/a&gt; int[] {0,1,2};&lt;br /&gt;var res = from a in nums&lt;br /&gt;where a &lt; nums =" int[]" result =" nums.Sum();"&gt;Aggregation &lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;Aggregate , Average ,Count ,LongCount, Max, Min, Sum&lt;br /&gt;&lt;strong&gt;Conversion &lt;/strong&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;Cast,OfType,ToArray,ToDictionary, ToList, ToLookup, ToSequence&lt;br /&gt;&lt;strong&gt;Element&lt;/strong&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;DefaultIfEmpty, ElementAt, ElementAtOrDefault, First, FirstOrDefault, Last, LastOrDefault, Single, SingleOrDefault&lt;br /&gt;&lt;strong&gt;Equality&lt;/strong&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;EqualAll&lt;br /&gt;&lt;strong&gt;Generation&lt;/strong&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;Empty, Range, Repeat&lt;br /&gt;&lt;strong&gt;Grouping&lt;/strong&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;GroupBy&lt;br /&gt;&lt;strong&gt;Joining&lt;/strong&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;GroupJoin, Join&lt;br /&gt;&lt;strong&gt;Ordering&lt;/strong&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;OrderBy, ThenBy, OrderByDescending, ThenByDescending, Reverse&lt;br /&gt;&lt;strong&gt;Partitioning&lt;/strong&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;Skip, SkipWhile, Take, TakeWhile&lt;br /&gt;&lt;strong&gt;Quantifiers&lt;/strong&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;All, Any, Contains&lt;br /&gt;&lt;strong&gt;Restriction&lt;/strong&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;Where&lt;br /&gt;&lt;strong&gt;Selection&lt;/strong&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;Select, SelectMany&lt;br /&gt;&lt;strong&gt;Set&lt;/strong&gt;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div align="justify"&gt;Concat, Distinct, Except, Intersect, Union&lt;br /&gt;To the good use of above operator types I need samle patient class so here it&lt;br /&gt;using System;&lt;br /&gt;public class Patient&lt;br /&gt;{&lt;br /&gt;// Fields&lt;br /&gt;private string _name;&lt;br /&gt;private int _age;&lt;br /&gt;private string _gender;&lt;br /&gt;private string _area;&lt;br /&gt;// Properties&lt;br /&gt;public string PatientName&lt;br /&gt;{&lt;br /&gt;get { return _name; }&lt;br /&gt;set { _name = value; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;public string Area&lt;br /&gt;{&lt;br /&gt;get { return _area; }&lt;br /&gt;set { _area = value; }&lt;br /&gt;}&lt;br /&gt;public String Gender&lt;br /&gt;{&lt;br /&gt;get { return _gender; }&lt;br /&gt;set { _gender = value; }&lt;br /&gt;}&lt;br /&gt;public int Age&lt;br /&gt;{&lt;br /&gt;get { return _age; }&lt;br /&gt;set { _age = value; }&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Here is my code that intiliaze patients object with following data.&lt;br /&gt;&lt;br /&gt;List&lt;patient&gt; patients = new List&lt;patient&gt; {&lt;br /&gt;new Patient { PatientName="Ali Khan", Age=20, Gender="Male" , Area = "Gulshan"},&lt;br /&gt;new Patient { PatientName="Ahmed Siddiqui", Age=25 ,Gender="Male", Area = "NorthKarachi" },&lt;br /&gt;new Patient { PatientName="Nida Ali", Age=20, Gender="Female", Area = "NorthNazimabad"},&lt;br /&gt;new Patient { PatientName="Sana Khan", Age=18, Gender="Female", Area = "NorthNazimabad"},&lt;br /&gt;new Patient { PatientName="Shahbaz Khan", Age=19, Gender="Male", Area = "Gulshan"},&lt;br /&gt;new Patient { PatientName="Noman Altaf", Age=19, Gender="Male", Area = "Gulshan"},&lt;br /&gt;new Patient { PatientName="Uzma Shah", Age=23, Gender="Female", Area = "NorthKarachi"}};&lt;br /&gt;&lt;br /&gt;Patient p = new Patient();&lt;br /&gt;p.Age =33; p.Gender = "male";&lt;br /&gt;p.PatientName = "Hammad Ali";&lt;br /&gt;p.Area = "Defence";&lt;br /&gt;patients.Add(p);&lt;br /&gt;&lt;br /&gt;This code snippet fetch those records whose gender is equal to “Male”.&lt;br /&gt;gdView.DataSource = from pa in patients&lt;br /&gt;where pa.Gender == "Male"&lt;br /&gt;orderby pa.PatientName, pa.Gender, pa.Age&lt;br /&gt;select pa;&lt;br /&gt;gdView.DataBind();&lt;br /&gt;&lt;br /&gt;The following code snippet uses the selection operator type, which brings all those records whose age is more than 20 years.&lt;br /&gt;var mypatient = from pa in patients&lt;br /&gt;where pa.Age &gt; 20&lt;br /&gt;orderby pa.PatientName, pa.Gender, pa.Age&lt;br /&gt;select pa;&lt;br /&gt;&lt;br /&gt;foreach(var pp in mypatient)&lt;br /&gt;{&lt;br /&gt;Debug.WriteLine(pp.PatientName + " "+ pp.Age + " " + pp.Gender);&lt;br /&gt;}&lt;br /&gt;The following code snippet uses the grouping operator type that group patient data on the bases area.&lt;br /&gt;var op = from pa in patients&lt;br /&gt;group pa by pa.Area into gselect new {area = g.Key, count = g.Count(), allpatient = g};&lt;br /&gt;&lt;br /&gt;foreach(var g in op)&lt;br /&gt;{&lt;br /&gt;Debug.WriteLine(g.count+ "," + g.area);&lt;br /&gt;foreach(var l in g.allpatient)&lt;br /&gt;{&lt;br /&gt;Debug.WriteLine("\t"+l.PatientName);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;This code snippet determine the count of those records, which lay in above 20 years.&lt;br /&gt;int patientCount = (from pa in patients&lt;br /&gt;where pa.Age &gt; 20&lt;br /&gt;orderby pa.PatientName, pa.Gender, pa.Age&lt;br /&gt;select pa).Count();&lt;br /&gt;All the above codes are few example of LINQ to Object technique of LINQ. In my up coming post you will see both LINQ to SQL and LINQ to XML code snippets.&lt;br /&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-118110607952857100?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/118110607952857100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=118110607952857100' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/118110607952857100'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/118110607952857100'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/11/what-is-linq.html' title='What is LINQ?'/><author><name>Piyush Srivastava</name><uri>http://www.blogger.com/profile/07995834856320205913</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://3.bp.blogspot.com/_278xsQcO1rU/TUlTVvyJ9II/AAAAAAAAABw/_lmK-mo5EEY/s220/Image0833.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-9085726145540338310</id><published>2008-11-03T21:05:00.000-08:00</published><updated>2008-11-04T22:14:57.940-08:00</updated><title type='text'>XSLT transformation with c#</title><content type='html'>&lt;a href="http://2.bp.blogspot.com/_byHCNcMp7rg/SRE4b0uXnJI/AAAAAAAAAEU/OEW0LK8uXUg/s1600-h/pic11.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5265051490033573010" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 290px; CURSOR: hand; HEIGHT: 285px; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_byHCNcMp7rg/SRE4b0uXnJI/AAAAAAAAAEU/OEW0LK8uXUg/s320/pic11.bmp" border="0" /&gt;&lt;/a&gt; &lt;img id="BLOGGER_PHOTO_ID_5265051603987469250" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 279px; CURSOR: hand; HEIGHT: 284px; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_byHCNcMp7rg/SRE4idPGE8I/AAAAAAAAAEc/41JWFHvto8o/s320/pic12.bmp" border="0" /&gt;&lt;img id="BLOGGER_PHOTO_ID_5265051706559619154" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 294px; CURSOR: hand; HEIGHT: 255px; TEXT-ALIGN: center" alt="" src="http://1.bp.blogspot.com/_byHCNcMp7rg/SRE4obWM4FI/AAAAAAAAAEk/6485A2x8hFQ/s320/pic13.bmp" border="0" /&gt;&lt;br /&gt;Figure 1 - XSL Transforming an XML Data File based on Radio Selection&lt;br /&gt;XSL (eXtensible Stylesheet Language) is a powerful XML language that enables you to specify how you want your XML data to appear on your Web Page. Table 1 shows a list of common XSL commands and what they do:&lt;br /&gt;&lt;img id="BLOGGER_PHOTO_ID_5264668461566507410" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 132px; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_byHCNcMp7rg/SQ_cEoffuZI/AAAAAAAAAC8/Okxrxqw0qIY/s320/pic4.bmp" border="0" /&gt;&lt;img id="BLOGGER_PHOTO_ID_5264668602472541938" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 174px; TEXT-ALIGN: center" alt="" src="http://4.bp.blogspot.com/_byHCNcMp7rg/SQ_cM1aHLvI/AAAAAAAAADE/OS21jPS-vAc/s320/pic5.bmp" border="0" /&gt;&lt;img id="BLOGGER_PHOTO_ID_5265043714090212082" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 230px; TEXT-ALIGN: center" alt="" src="http://4.bp.blogspot.com/_byHCNcMp7rg/SRExXNFAGvI/AAAAAAAAADM/TTPALGXCON0/s320/pic6.bmp" border="0" /&gt;In our ASP.NET application we want to take a list of customers and display them nicely on a web page. The XSL code in listing 1a cycles through each customer in the XML customer data shown in listing 1b and transforms the information into a readable HTML Table (listing 2). The transform uses the XSL for-each select command to loop and builds the table row by row. Within the loop, the transform fills the appropriate customer information using the XSL value-of select command, selecting on each Customer node in the XML file.&lt;br /&gt;&lt;br /&gt;&lt;img id="BLOGGER_PHOTO_ID_5265045910499714194" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 243px; TEXT-ALIGN: center" alt="" src="http://1.bp.blogspot.com/_byHCNcMp7rg/SREzXDV1ZJI/AAAAAAAAADs/FPsscJeHSt8/s320/pic10.bmp" border="0" /&gt;If the XSL transform in listing 1a is applied to the XML Data in listing 1b, the HTML table output in listing 2 results:&lt;br /&gt;Listing 2 - Output resulting from the xsl transform of listing 1a applied to xml data in listing 1b&lt;br /&gt;&lt;img id="BLOGGER_PHOTO_ID_5265043964919022946" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 232px; TEXT-ALIGN: center" alt="" src="http://3.bp.blogspot.com/_byHCNcMp7rg/SRExlzfQBWI/AAAAAAAAADc/BOV82URTTeg/s320/pic8.bmp" border="0" /&gt;&lt;strong&gt;Using ASP.NET to Transform XML&lt;/strong&gt;&lt;br /&gt;ASP.NET comes with an XML control that allows you to transform an XML file using XSL. You just need to do 2 things: (1) assign an XmlDocument containing the XML you want to transform to the XML control's Document property. (2) assign an XslTransform class containing the XSL to the Transform property of the XML control.&lt;br /&gt;&lt;strong&gt;Listing 3 - Making the transform happen using the Xml class&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;// get the physical directory path of the root default page's directory&lt;br /&gt;string path = Path.GetDirectoryName(Request.PhysicalPath);&lt;br /&gt;// Create the Xml Document&lt;br /&gt;XmlDocument xmlDoc = new XmlDocument();&lt;br /&gt;// load the xml customer database from the customers.xml file&lt;br /&gt;xmlDoc.Load(String.Format("{0}/Docs/{1}", path, "customers.xml"));&lt;br /&gt;&lt;/span&gt;If we just wanted to use the existing XSL contained in the customerformat.xsl file, then the process of retrieving the XSL is fairly straightforward. Simply construct the XslTransform object and call the Load method, just like we did with the XmlDocument. &lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;div&gt;&lt;strong&gt;Listing 5 - Loading a StyleSheet into an XslTransform object&lt;/strong&gt;&lt;br /&gt;&lt;span style="color:#cc6600;"&gt;// by loading it indirectly with an XmlReader&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color:#cc6600;"&gt;XslTransform xslTransform = new XslTransform();&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="color:#cc6600;"&gt;xslTransform.Load(String.Format("{0}/Docs/{1}",path, Session["TransformFile"]));&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;However, we would like to do something a bit more interesting. We want to be able to manipulate the XSL in memory. Therefore we need a way to read the XSL, convert it to a string, alter it, and then shove the string into an XslTransform object. This turns out to be a little less straightforward. The XSL we want to load into memory is shown below in listing 6. Note that this XSL differs from the XSL in listing 1a with just one xsl command, xsl:if. We want to be able to dynamically replace the expression &lt;?xml:namespace prefix = xsl /&gt;&lt;xsl:if test="{0}"&gt;with a boolean expression of our choosing, such as &lt;xsl:if test="Employee='yes'"&gt;. In the case of our ASP.NET program, we want to replace the expression {0} with something that is always true (such as the boolean expression 1 &gt; 0) when Employees Only is not checked, but we want to filter on the condition 'Employee='yes' when Employees Only is checked. This way, all workers (consultants and employees) will be shown when the employees checkbox is not checked, but only employees will be shown when the employees check box is checked.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;strong&gt;Listing 6 - XSL Transform with xsl:if to produce a table based on a given condition&lt;img id="BLOGGER_PHOTO_ID_5265044097538733762" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 247px; TEXT-ALIGN: center" alt="" src="http://2.bp.blogspot.com/_byHCNcMp7rg/SRExthiQNsI/AAAAAAAAADk/jYjUUUUr1ig/s320/pic9.bmp" border="0" /&gt;&lt;/strong&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;img id="BLOGGER_PHOTO_ID_5265043844917807234" style="DISPLAY: block; MARGIN: 0px auto 10px; WIDTH: 320px; CURSOR: hand; HEIGHT: 47px; TEXT-ALIGN: center" alt="" src="http://1.bp.blogspot.com/_byHCNcMp7rg/SRExe0cuyII/AAAAAAAAADU/lFDXnIlVh-E/s320/pic7.bmp" border="0" /&gt;In order to read the XSL into a string that we can manipulate in memory we will use a StreamReader. Then we'll replace the {0} in the string with the appropriate boolean expression using the string Replace method. Next we'll read the string into a memory stream and then use the memory stream to construct an XmlTextReader containing the string. Finally, we will construct the XslTransform object with the XmlTextReader containing the manipulated XSL string. As convoluted as this sounds, it is a workable approach. However, it would have been faster if there were a XslTransform method you could call that took a string containing the XSL.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Listing 7 - Dynamically changing XSL inside a string and loading the string into and XslTransform object&lt;/strong&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;// need to go through a bit of a convoluted task// to load the transform with a string// by loading it indirectly with an XmlReader&lt;br /&gt;XslTransform xslTransform = new XslTransform();&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;xslTransform.Load(String.Format("{0}/Docs/{1}",path, Session["TransformFile"]));&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;StreamReader sr = new StreamReader(String.Format("{0}/Docs/{1}", path, Session["TransformFile"]));&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;string xslBlock = sr.ReadToEnd();&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;sr.Close();&lt;br /&gt;// alter the 'xsl:if' statement in the xsl string // to test for filtering on employees&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;if (chkEmployee.Checked) &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;// if 'only employees' is checked, &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;// put a condition to test whether or not &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;// we have an employee &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;// in the xsl:if expression &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;xslBlock = xslBlock.Replace("{0}", "Employee = \'yes\'"); &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;} &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;else &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;// if 'only employees' is not checked, &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;// put a condition that is always true (1&gt;0) &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;// in the xsl:if expression &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;xslBlock = xslBlock.Replace("{0}", "1 &amp;gt; 0");&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;}&lt;br /&gt;// need to convert the xsl string to a memory stream&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;// in order to put it in the xml reader. &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;MemoryStream ms = new MemoryStream(System.Text.ASCIIEncoding.ASCII.GetBytes(xslBlock)); &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;XmlReader reader = new XmlTextReader(ms&lt;span style="color:#333333;"&gt;);&lt;/span&gt; &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;// load the tranform with the XmlReader containing &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;// the xsl transform string &lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color:#cc6600;"&gt;xslTransform.Load(reader);&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br /&gt;Although XSL may seem complex, it is actually a useful language for taking an XML file containing data and presenting it effectively on a web page. This article has shown you how you can take advantage of the features in ASP.NET to alter XSL on the fly in response to input from the web browser and display your XML data differently. So add a bit of style to your ASP.NET apps, to C a sharper view of your data with a combination of stylesheets and .NET. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;/xsl:if&gt;&lt;/xsl:if&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-9085726145540338310?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/9085726145540338310/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=9085726145540338310' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/9085726145540338310'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/9085726145540338310'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/11/blog-post.html' title='XSLT transformation with c#'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_byHCNcMp7rg/SRE4b0uXnJI/AAAAAAAAAEU/OEW0LK8uXUg/s72-c/pic11.bmp' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-1525619928004087880</id><published>2008-10-22T06:48:00.000-07:00</published><updated>2008-10-22T06:49:33.389-07:00</updated><title type='text'>Object Serialization</title><content type='html'>&lt;span class="Apple-style-span" style="font-family: verdana; font-size: 13px; "&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;In simple words serialization is a process of storing the object instance to a disk file. Serialization stores state of the object i.e. member variable values to disk. Deserialization is reverse of serialization i.e. it's a process of reading objects from a file where they have been stored. In this code sample we will see how to serialize and deserialize objects using C#.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Namespaces involved&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Following namespaces are involved in serialization process :&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;System.Runtime.Serialization&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;System.Runtime.Serialization.Formatters.Binary&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Example 1&lt;br /&gt;&lt;/strong&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; System;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; System.IO;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; System.Runtime.Serialization;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; System.Runtime.Serialization.Formatters.Binary;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; SerialTest&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; SerializeNow()&lt;br /&gt;{&lt;br /&gt;ClassToSerialize c=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; ClassToSerialize();&lt;br /&gt;File f=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; File("temp.dat");&lt;br /&gt;Stream s=f.Open(FileMode.Create);&lt;br /&gt;BinaryFormatter b=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; BinaryFormatter();&lt;br /&gt;b.Serialize(s,c);&lt;br /&gt;s.Close();&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; DeSerializeNow()&lt;br /&gt;{&lt;br /&gt;ClassToSerialize c=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; ClassToSerialize();&lt;br /&gt;File f=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; File("temp.dat");&lt;br /&gt;Stream s=f.Open(FileMode.Open);&lt;br /&gt;BinaryFormatter b=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; BinaryFormatter();&lt;br /&gt;c=(ClassToSerialize)b.Deserialize(s);&lt;br /&gt;Console.WriteLine(c.name);&lt;br /&gt;s.Close();&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;static&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; Main(&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;[] s)&lt;br /&gt;{&lt;br /&gt;SerialTest st=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; SerialTest();&lt;br /&gt;st.SerializeNow();&lt;br /&gt;st.DeSerializeNow();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; ClassToSerialize&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; age=100;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; name="bipin";&lt;br /&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt; &lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Here we have our own class named ClassToSerialize. This class has two public valiables name and age with some default values. We will write this class to a disk file (temp.dat) using SerializeTest class.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;SerializeTest class has two methods SerializeNow() and DeSerializeNow() which perform the task of serialization and deserialization respectively.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The general steps for serializing are :&lt;/span&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Create an instance of File that will store serialized object.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Create a stream from the file object.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Create an instance of BinaryFormatter.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Call serialize method of the instance passing it stream and object to serialize.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The steps for de-serializing the object are similar. The only change is that you need to call deserialize method of BinaryFormatter object.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Now, let us see an example where we have used 'real' class with public and shared members and properties to encapsulate them. The class also uses another supporting class. This is just to make clear that if your class contains further classes, all the classes in the chain will be serialized.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Example 2&lt;/strong&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; System;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; System.IO;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; System.Runtime.Serialization;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; System.Runtime.Serialization.Formatters.Binary;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; SerialTest&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; SerializeNow()&lt;br /&gt;{&lt;br /&gt;ClassToSerialize c=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; ClassToSerialize();&lt;br /&gt;c.Name="bipin";&lt;br /&gt;c.Age=26;&lt;br /&gt;ClassToSerialize.CompanyName="xyz";&lt;br /&gt;File f=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; File("temp.dat");&lt;br /&gt;Stream s=f.Open(FileMode.Create);&lt;br /&gt;BinaryFormatter b=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; BinaryFormatter();&lt;br /&gt;b.Serialize(s,c);&lt;br /&gt;s.Close();&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; DeSerializeNow()&lt;br /&gt;{&lt;br /&gt;ClassToSerialize c=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; ClassToSerialize();&lt;br /&gt;File f=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; File("temp.dat");&lt;br /&gt;Stream s=f.Open(FileMode.Open);&lt;br /&gt;BinaryFormatter b=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; BinaryFormatter();&lt;br /&gt;c=(ClassToSerialize)b.Deserialize(s);&lt;br /&gt;Console.WriteLine("Name :" + c.Name);&lt;br /&gt;Console.WriteLine("Age :" + c.Age);&lt;br /&gt;Console.WriteLine("Company Name :" + ClassToSerialize.CompanyName);&lt;br /&gt;Console.WriteLine("Company Name :" + c.GetSupportClassString());&lt;br /&gt;s.Close();&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;static&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; Main(&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;[] s)&lt;br /&gt;{&lt;br /&gt;SerialTest st=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; SerialTest();&lt;br /&gt;st.SerializeNow();&lt;br /&gt;st.DeSerializeNow();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; ClassToSerialize&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; age;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; name;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;static&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; companyname;&lt;br /&gt;SupportClass supp=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; SupportClass();&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; ClassToSerialize()&lt;br /&gt;{&lt;br /&gt;supp.SupportClassString="In support class";&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; Age&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;get&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; age;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;set&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;{&lt;br /&gt;age=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;value&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; Name&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;get&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; name;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;set&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;{&lt;br /&gt;name=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;value&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;static&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; CompanyName&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;get&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; companyname;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;set&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;{&lt;br /&gt;companyname=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;value&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; GetSupportClassString()&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; supp.SupportClassString;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; SupportClass&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; SupportClassString;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;Example 3&lt;br /&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;&lt;br /&gt;The final example shows how to serialize array of objects.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; System;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; System.IO;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; System.Runtime.Serialization;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; System.Runtime.Serialization.Formatters.Binary;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; SerialTest&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; SerializeNow()&lt;br /&gt;{&lt;br /&gt;ClassToSerialize[] c=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; ClassToSerialize[3];&lt;br /&gt;c[0]=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; ClassToSerialize();&lt;br /&gt;c[0].Name="bipin";&lt;br /&gt;c[0].Age=26;&lt;br /&gt;c[1]=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; ClassToSerialize();&lt;br /&gt;c[1].Name="abc";&lt;br /&gt;c[1].Age=75;&lt;br /&gt;c[2]=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; ClassToSerialize();&lt;br /&gt;c[2].Name="pqr";&lt;br /&gt;c[2].Age=50;&lt;br /&gt;ClassToSerialize.CompanyName="xyz";&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;File f=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; File("temp.dat");&lt;br /&gt;Stream s=f.Open(FileMode.Create);&lt;br /&gt;BinaryFormatter b=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; BinaryFormatter();&lt;br /&gt;b.Serialize(s,c);&lt;br /&gt;s.Close();&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; DeSerializeNow()&lt;br /&gt;{&lt;br /&gt;ClassToSerialize[] c;&lt;br /&gt;File f=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; File("temp.dat");&lt;br /&gt;Stream s=f.Open(FileMode.Open);&lt;br /&gt;BinaryFormatter b=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; BinaryFormatter();&lt;br /&gt;c=(ClassToSerialize[])b.Deserialize(s);&lt;br /&gt;Console.WriteLine("Name :" + c[2].Name);&lt;br /&gt;Console.WriteLine("Age :" + c[2].Age);&lt;br /&gt;Console.WriteLine("Company Name :" + ClassToSerialize.CompanyName);&lt;br /&gt;s.Close();&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;static&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; Main(&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;[] s)&lt;br /&gt;{&lt;br /&gt;SerialTest st=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; SerialTest();&lt;br /&gt;st.SerializeNow();&lt;br /&gt;st.DeSerializeNow();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; ClassToSerialize&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; age;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;private&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; name;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;static&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; companyname;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; Age&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;get&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; age;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;set&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;{&lt;br /&gt;age=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;value&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; Name&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;get&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; name;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;set&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;{&lt;br /&gt;name=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;value&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;static&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; CompanyName&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;get&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;{&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt; companyname;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;set&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;{&lt;br /&gt;companyname=&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;value&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span class="Apple-style-span" style="color: rgb(204, 102, 0);"&gt;;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3068650074752359005-1525619928004087880?l=futureapps.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://futureapps.blogspot.com/feeds/1525619928004087880/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3068650074752359005&amp;postID=1525619928004087880' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/1525619928004087880'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3068650074752359005/posts/default/1525619928004087880'/><link rel='alternate' type='text/html' href='http://futureapps.blogspot.com/2008/10/object-serialization.html' title='Object Serialization'/><author><name>Vigneshwar Gupta</name><uri>http://www.blogger.com/profile/07138473961386598095</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://1.bp.blogspot.com/_byHCNcMp7rg/SOlm7Dcl7mI/AAAAAAAAAAM/xmfprUiBX4I/S220/DSC03756.JPG'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3068650074752359005.post-8617141266867552571</id><published>2008-10-22T06:39:00.000-07:00</published><updated>2008-10-22T06:48:06.499-07:00</updated><title type='text'>Read and Write XML</title><content type='html'>&lt;span class="Apple-style-span"   style="  ;font-family:verdana;font-size:13px;"&gt;&lt;p&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-size: 13px; font-weight: normal; "&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Introduction to Microsoft .NET XML Namespaces and Classes&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;Before start working with XML document in .NET Framework, It is important to know about .NET namespace and classes provided by .NET Runtime Library. .NET provides five namespace - System.Xml, System.Xml.Schema, System.Xml.Serialization, System.Xml.XPath, and System.Xml.Xsl to support XML classes. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The System.Xml namespace contains major XML classes. This namespace contains many classes to read and write XML documents. In this article, we are going to concentrate on reader and write class. These reader and writer classes are used to read and write XMl documents. These classes are - XmlReader, XmlTextReader, XmlValidatingReader, XmlNodeReader, XmlWriter, and XmlTextWriter. As you can see there are four reader and two writer classes. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The XmlReader class is an abstract bases classes and contains methods and properties to read a document. The Read method reads a node in the stream. Besides reading functionality, this class also contains methods to navigate through a document nodes. Some of these methods are MoveToAttribute, MoveToFirstAttribute, MoveToContent, MoveToFirstContent, MoveToElement and  MoveToNextAttribute. ReadString, ReadInnerXml, ReadOuterXml, and ReadStartElement are more read methods. This class also has a method Skip to skip current node and move to next one. We'll see these methods in our sample example. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The XmlTextReader, XmlNodeReader and XmlValidatingReader classes are derived from XmlReader class. As their name explains, they are used to read text, node, and schemas.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The XmlWrite class contains functionality to write data to XML documents. This class provides many write method to write XML document items. This class is base class for XmlTextWriter class, which we'll be using in our sample example. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The &lt;strong&gt;XmlNode&lt;/strong&gt; class plays an important role. Although, this class represents a single node of XML but that could be the root node of an XML document and could represent the entire file. This class is an abstract base class for many useful classes for inserting, removing, and replacing nodes, navigating through the document. It also contains properties to get a parent or child, name, last child, node type and more. Three major classes derived from XmlNode are XmlDocument, XmlDataDocument and XmlDocumentFragment. XmlDocument class represents an XML document and provides methods and properties to load and save a document. It also provides functionality to add XML items such as attributes, comments, spaces, elements, and new nodes. The Load and LoadXml methods can be used to load XML documents and Save method to save a document respectively. XmlDocumentFragment class represents a document fragment, which can be used to add to a document. The XmlDataDocument class provides methods and properties to work with ADO.NET data set objects.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;In spite of above discussed classes, System.Xml namespace contains more classes. Few of them are XmlConvert, XmlLinkedNode, and XmlNodeList. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Next namespace in Xml series is System.Xml.Schema. It classes  to work with XML schemas such XmlSchema, XmlSchemaAll, XmlSchemaXPath, XmlSchemaType. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The System.Xml.Serialization namespace contains classes that are used to serialize objects into XML format documents or streams. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The System.Xml.XPath Namespce contains XPath related classes to use XPath specifications. This namespace has following classes  -XPathDocument, XPathExression, XPathNavigator, and XPathNodeIterator. With the help of XpathDocument, XpathNavigator provides a fast navigation though XML documents. This class contains many Move methods to move through a document. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The System.Xml.Xsl namespace contains classes to work with XSL/T transformations.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Reading XML Documents&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;In my sample application, I'm using books.xml to read and display its data through XmlTextReader. This file comes with VS.NET samples. You can search this on your machine and change the path of the file in the following line: &lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;XmlTextReader textReader = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; XmlTextReader("C:\\books.xml");&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;Or you can use any XML file. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;The XmlTextReader, XmlNodeReader and XmlValidatingReader classes are derived from XmlReader class. Besides XmlReader methods and properties, these classes also contain members to read text, node, and schemas respectively. I am using XmlTextReader class to read an XML file. You read a file by passing file name as a parameter in constructor. &lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;"&gt;XmlTextReader textReader = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; XmlTextReader("C:\\books.xml");&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;After creating an instance of XmlTextReader, you call Read method to start reading the document. After read method is called, you can read all information and data stored in a document. XmlReader class has properties such as Name, BaseURI, Depth, LineNumber an so on.&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;List 1 reads a document and displays a node information using these properties. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;About Sample Example 1&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;In this sample example, I read an XML file using XmlTextReader and call Read method to read its node one by one until end of file and display the contents to the console output. &lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Sample Example 1.&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt; System;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;using&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt; System.Xml;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;namespace&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt; ReadXml1&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;{&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;Class1&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;{&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;        &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;static&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;void&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt; Main(&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;string&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;[] args)&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;{&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;            &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;// Create an isntance of XmlTextReader and call Read method to read the file&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;            &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;XmlTextReader&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt; textReader = &lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;XmlTextReader&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;(&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;"C:\\books.xml"&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;);&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;textReader.Read();&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;            &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;// If the node has value&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;            &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;while&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt; (textReader.Read())&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;            &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;{&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;                &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;// Move to fist element&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;                &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;textReader.MoveToElement();&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;                &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;Console&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;.WriteLine(&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;"XmlTextReader Properties Test"&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;);&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;                &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;Console&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;.WriteLine(&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;"==================="&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;);&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;                &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=""&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;// Read this element's properties and display them on console&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(153, 0, 0);"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal" style="margin-top: 0in; margin-right: 0in; margin-bottom: 0pt; margin-left: 0in; "&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; "&gt;&lt;span&gt;&lt;span&gt;&lt;span class="Apple-s
