<?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-2523394595390906940</id><updated>2011-11-27T15:20:28.351-08:00</updated><category term='Threading'/><category term='Constructor'/><category term='Delegate'/><category term='Exception'/><category term='Performance'/><category term='Lambda'/><category term='My'/><category term='CommandLine'/><category term='Design'/><category term='Build'/><category term='http'/><category term='Indexers'/><category term='Casting'/><category term='Collection'/><category term='Event'/><category term='DesignPatterns'/><category term='Inheritance'/><category term='Serialization'/><title type='text'>.NET Code Snippets</title><subtitle type='html'>Snippets compilation by Ajit Singh</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>21</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-1154233183797422323</id><published>2011-07-16T19:26:00.001-07:00</published><updated>2011-07-16T19:26:46.953-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Performance'/><title type='text'>Measure time for code execution</title><content type='html'>&lt;p&gt;&lt;font face="Courier New"&gt;void Main()      &lt;br /&gt;{       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; int startTick = Environment.TickCount;       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Thread.Sleep(1000);       &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; int endTick = Environment.TickCount;&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font face="Courier New"&gt;&amp;#160;&amp;#160;&amp;#160; Console.WriteLine(&amp;quot;Thread slept for {0} ms&amp;quot;,&amp;#160;&amp;#160;&amp;#160; (endTick - startTick));      &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-1154233183797422323?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/1154233183797422323/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2011/07/measure-time-for-code-execution.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/1154233183797422323'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/1154233183797422323'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2011/07/measure-time-for-code-execution.html' title='Measure time for code execution'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-7399482467436511631</id><published>2010-05-08T01:30:00.001-07:00</published><updated>2010-09-18T06:09:52.159-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Lambda'/><title type='text'>Lambda Expressions Sample</title><content type='html'>&lt;pre class="brush: csharp;"&gt;  using System;&lt;br /&gt;   &lt;br /&gt;  //A lambda expression is an anonymous function that can contain expressions and statements,&lt;br /&gt;  //and can be used to create delegates or expression tree types.&lt;br /&gt;   &lt;br /&gt;  //All lambda expressions use the lambda operator =&amp;gt;, which is read as &amp;quot;goes to&amp;quot;.&lt;br /&gt;  //The left side of the lambda operator specifies the input parameters&lt;br /&gt;  //(if any) and the right side holds the expression or statement block.&lt;br /&gt;   &lt;br /&gt;  //The lambda expression x =&amp;gt; x * x is read &amp;quot;x goes to x times x.&amp;quot;&lt;br /&gt;   &lt;br /&gt;  //This expression can be assigned to a delegate type.&lt;br /&gt;   &lt;br /&gt;  delegate string NoInputStrOutputDel ();&lt;br /&gt;  delegate int IntInputIntOutputDel ( int i );&lt;br /&gt;  delegate string MultiStrInputStrOutputDel ( string salutation , string firstName , string lastName );&lt;br /&gt;   &lt;br /&gt;  public class MyClass&lt;br /&gt;  {&lt;br /&gt;      public static void Main ()&lt;br /&gt;      {&lt;br /&gt;   &lt;br /&gt;          NoInputStrOutputDel del1 = () =&amp;gt; &amp;quot;Output without Input&amp;quot;;&lt;br /&gt;          Console.WriteLine ( del1 () );&lt;br /&gt;   &lt;br /&gt;          IntInputIntOutputDel del2 = x =&amp;gt; x * x;&lt;br /&gt;          Console.WriteLine ( del2 ( 5 ) );&lt;br /&gt;   &lt;br /&gt;          MultiStrInputStrOutputDel del3 = ( i , j , k ) =&amp;gt; &amp;quot;Hello &amp;quot; + i + &amp;quot; &amp;quot; + j + &amp;quot; &amp;quot; + k;&lt;br /&gt;          Console.WriteLine ( del3 ( &amp;quot;Mr.&amp;quot; , &amp;quot;Ajit&amp;quot; , &amp;quot;Singh&amp;quot; ) );&lt;br /&gt;   &lt;br /&gt;          Console.ReadKey ();&lt;br /&gt;   &lt;br /&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/2523394595390906940-7399482467436511631?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/7399482467436511631/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/05/lambda-expressions-sample.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/7399482467436511631'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/7399482467436511631'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/05/lambda-expressions-sample.html' title='Lambda Expressions Sample'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-7026206792658461994</id><published>2010-03-20T19:42:00.001-07:00</published><updated>2010-09-18T06:11:29.918-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='http'/><title type='text'>Reading cookie info from a URL in .net code</title><content type='html'>&lt;pre class="brush: csharp;"&gt;using System;&lt;br /&gt;using System.Collections.Generic;&lt;br /&gt;using System.Net;&lt;br /&gt;class MainApp&lt;br /&gt;{&lt;br /&gt;    static void Main ( string[] args )&lt;br /&gt;    {&lt;br /&gt;        string URL = &amp;quot;http://www.yahoo.com&amp;quot;;&lt;br /&gt;        //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(args[0]);  &lt;br /&gt;        HttpWebRequest request = ( HttpWebRequest ) WebRequest.Create ( URL );&lt;br /&gt;        request.CookieContainer = new CookieContainer ();&lt;br /&gt;        HttpWebResponse response = ( HttpWebResponse ) request.GetResponse ();&lt;br /&gt;        // Print the properties of each cookie.  &lt;br /&gt;        foreach ( Cookie cook in response.Cookies )&lt;br /&gt;        {&lt;br /&gt;            Console.WriteLine ( &amp;quot;Cookie:&amp;quot; );&lt;br /&gt;            Console.WriteLine ( &amp;quot;{0} = {1}&amp;quot; , cook.Name , cook.Value );&lt;br /&gt;            Console.WriteLine ( &amp;quot;Domain: {0}&amp;quot; , cook.Domain );&lt;br /&gt;            Console.WriteLine ( &amp;quot;Path: {0}&amp;quot; , cook.Path );&lt;br /&gt;            Console.WriteLine ( &amp;quot;Port: {0}&amp;quot; , cook.Port );&lt;br /&gt;            Console.WriteLine ( &amp;quot;Secure: {0}&amp;quot; , cook.Secure );&lt;br /&gt;            Console.WriteLine ( &amp;quot;When issued: {0}&amp;quot; , cook.TimeStamp );&lt;br /&gt;            Console.WriteLine ( &amp;quot;Expires: {0} (expired? {1})&amp;quot; ,&lt;br /&gt;              cook.Expires , cook.Expired );&lt;br /&gt;            Console.WriteLine ( &amp;quot;Don't save: {0}&amp;quot; , cook.Discard );&lt;br /&gt;            Console.WriteLine ( &amp;quot;Comment: {0}&amp;quot; , cook.Comment );&lt;br /&gt;            Console.WriteLine ( &amp;quot;Uri for comments: {0}&amp;quot; , cook.CommentUri );&lt;br /&gt;            Console.WriteLine ( &amp;quot;Version: RFC {0}&amp;quot; , cook.Version == 1 ? &amp;quot;2109&amp;quot; : &amp;quot;2965&amp;quot; );&lt;br /&gt;            // Show the string representation of the cookie.  &lt;br /&gt;            Console.WriteLine ( &amp;quot;String: {0}&amp;quot; , cook.ToString () );&lt;br /&gt;        }&lt;br /&gt;        // Wait for user  &lt;br /&gt;        Console.ReadKey ();&lt;br /&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/2523394595390906940-7026206792658461994?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/7026206792658461994/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/03/reading-cookie-info-from-url-in-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/7026206792658461994'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/7026206792658461994'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/03/reading-cookie-info-from-url-in-net.html' title='Reading cookie info from a URL in .net code'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-4586934914616258618</id><published>2010-03-04T11:10:00.001-08:00</published><updated>2010-03-04T11:10:49.289-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='DesignPatterns'/><title type='text'>DoFactory design patterns and sample codes</title><content type='html'>&lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/Patterns.aspx" target="_blank"&gt;DoFactory Design Patterns page.&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Creational Patterns&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternAbstract.aspx"&gt;Abstract Factory&lt;/a&gt;    &lt;br /&gt;&amp;#160; Creates an instance of several families of classes&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternBuilder.aspx"&gt;Builder&lt;/a&gt;    &lt;br /&gt;&amp;#160; Separates object construction from its representation&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternFactory.aspx"&gt;Factory Method&lt;/a&gt;    &lt;br /&gt;&amp;#160; Creates an instance of several derived classes&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternPrototype.aspx"&gt;Prototype&lt;/a&gt;    &lt;br /&gt;&amp;#160; A fully initialized instance to be copied or cloned&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternSingleton.aspx"&gt;Singleton&lt;/a&gt;    &lt;br /&gt;&amp;#160; A class of which only a single instance can exist&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Structural Patterns&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternAdapter.aspx"&gt;Adapter&lt;/a&gt;    &lt;br /&gt;&amp;#160; Match interfaces of different classes&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternBridge.aspx"&gt;Bridge&lt;/a&gt;    &lt;br /&gt;&amp;#160; Separates an object’s interface from its implementation&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternComposite.aspx"&gt;Composite&lt;/a&gt;    &lt;br /&gt;&amp;#160; A tree structure of simple and composite objects&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternDecorator.aspx"&gt;Decorator&lt;/a&gt;    &lt;br /&gt;&amp;#160; Add responsibilities to objects dynamically&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternFacade.aspx"&gt;Facade&lt;/a&gt;    &lt;br /&gt;&amp;#160; A single class that represents an entire subsystem&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternFlyweight.aspx"&gt;Flyweight&lt;/a&gt;    &lt;br /&gt;&amp;#160; A fine-grained instance used for efficient sharing&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternProxy.aspx"&gt;Proxy&lt;/a&gt;    &lt;br /&gt;&amp;#160; An object representing another object&lt;/p&gt;  &lt;p&gt;&lt;b&gt;Behavioral Patterns&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternChain.aspx"&gt;Chain of Resp.&lt;/a&gt;    &lt;br /&gt;&amp;#160; A way of passing a request between a chain of objects&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternCommand.aspx"&gt;Command&lt;/a&gt;    &lt;br /&gt;&amp;#160; Encapsulate a command request as an object&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternInterpreter.aspx"&gt;Interpreter&lt;/a&gt;    &lt;br /&gt;&amp;#160; A way to include language elements in a program&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternIterator.aspx"&gt;Iterator&lt;/a&gt;    &lt;br /&gt;&amp;#160; Sequentially access the elements of a collection&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternMediator.aspx"&gt;Mediator&lt;/a&gt;    &lt;br /&gt;&amp;#160; Defines simplified communication between classes&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternMemento.aspx"&gt;Memento&lt;/a&gt;    &lt;br /&gt;&amp;#160; Capture and restore an object's internal state&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternObserver.aspx"&gt;Observer&lt;/a&gt;    &lt;br /&gt;&amp;#160; A way of notifying change to a number of classes&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternState.aspx"&gt;State&lt;/a&gt;    &lt;br /&gt;&amp;#160; Alter an object's behavior when its state changes&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternStrategy.aspx"&gt;Strategy&lt;/a&gt;    &lt;br /&gt;&amp;#160; Encapsulates an algorithm inside a class&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternTemplate.aspx"&gt;Template Method&lt;/a&gt;    &lt;br /&gt;&amp;#160; Defer the exact steps of an algorithm to a subclass&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.dofactory.com/Patterns/PatternVisitor.aspx"&gt;Visitor&lt;/a&gt;    &lt;br /&gt;&amp;#160; Defines a new operation to a class without change&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-4586934914616258618?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/4586934914616258618/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/03/dofactory-design-patterns-and-sample.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/4586934914616258618'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/4586934914616258618'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/03/dofactory-design-patterns-and-sample.html' title='DoFactory design patterns and sample codes'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-5780025730986751708</id><published>2010-03-04T10:16:00.001-08:00</published><updated>2010-09-18T06:14:38.034-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Constructor'/><title type='text'>Default constructor calling another constructor</title><content type='html'>&lt;pre class="brush: csharp;"&gt;using System;  &lt;br /&gt;using System.Collections;  &lt;br /&gt;public class Inventor  &lt;br /&gt;{  &lt;br /&gt;  public string Name;  &lt;br /&gt;  public string Nationality;  &lt;br /&gt;  public string[] Inventions;  &lt;br /&gt;  private DateTime dob;  &lt;br /&gt;  public Inventor()  &lt;br /&gt;    : this(null, DateTime.MinValue, null)  &lt;br /&gt;  { }  &lt;br /&gt;  public Inventor(string name, DateTime dateOfBirth, string nationality)  &lt;br /&gt;  {  &lt;br /&gt;    this.Name = name;  &lt;br /&gt;    this.dob = dateOfBirth;  &lt;br /&gt;    this.Nationality = nationality;  &lt;br /&gt;  }  &lt;br /&gt;  public DateTime DOB  &lt;br /&gt;  {  &lt;br /&gt;    get { return dob; }  &lt;br /&gt;    set { dob = value; }  &lt;br /&gt;  }  &lt;br /&gt;  public int GetAge(DateTime on)  &lt;br /&gt;  {  &lt;br /&gt;    // not very accurate, but it will do the job ;-)  &lt;br /&gt;    return on.Year - dob.Year;  &lt;br /&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/2523394595390906940-5780025730986751708?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/5780025730986751708/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/03/default-constructor-calling-another.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/5780025730986751708'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/5780025730986751708'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/03/default-constructor-calling-another.html' title='Default constructor calling another constructor'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-6021833681397148185</id><published>2010-03-04T03:44:00.001-08:00</published><updated>2010-09-18T06:16:54.881-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Threading'/><title type='text'>Threading : Performing long running operations using multiple asynchronous actions</title><content type='html'>&lt;pre class="brush: csharp;"&gt;using System.Threading;  &lt;br /&gt; using System;  &lt;br /&gt; using System.Linq;  &lt;br /&gt; using System.Collections.Generic;  &lt;br /&gt; using System.Diagnostics;  &lt;br /&gt; public static class Extensions   &lt;br /&gt;{   &lt;br /&gt;  public static void ExecAsync(this IEnumerable&amp;lt;Action&amp;gt; actions)   &lt;br /&gt;  {   &lt;br /&gt;    int count = 0;   &lt;br /&gt;    AutoResetEvent[] events = new AutoResetEvent[actions.Count()];   &lt;br /&gt;    IAsyncResult[] results = new IAsyncResult[actions.Count()];   &lt;br /&gt;    for (int i = 0; i &amp;lt; events.Length; i++)   &lt;br /&gt;    {   &lt;br /&gt;      events[i] = new AutoResetEvent(false);   &lt;br /&gt;    }   &lt;br /&gt;    foreach (var action in actions)   &lt;br /&gt;    {   &lt;br /&gt;      int localCount = count;   &lt;br /&gt;      results[count++]=    &lt;br /&gt;        action.BeginInvoke((r) =&amp;gt;   &lt;br /&gt;        {   &lt;br /&gt;          try   &lt;br /&gt;          {   &lt;br /&gt;            if (r.IsCompleted)   &lt;br /&gt;            {   &lt;br /&gt;              Action act = r.AsyncState as Action;   &lt;br /&gt;              act.EndInvoke(results[localCount]);   &lt;br /&gt;            }   &lt;br /&gt;          }   &lt;br /&gt;          finally   &lt;br /&gt;          {   &lt;br /&gt;            //set the event regardless of whether there is an exception so that the main thread   &lt;br /&gt;            //is not blocked indefinitely.   &lt;br /&gt;            events[localCount].Set();   &lt;br /&gt;          }   &lt;br /&gt;        }, action);   &lt;br /&gt;    }   &lt;br /&gt;    WaitHandle.WaitAll(events);   &lt;br /&gt;  }   &lt;br /&gt;}   &lt;br /&gt;class Program    &lt;br /&gt;{   &lt;br /&gt;  public static string[] GetUsers()   &lt;br /&gt;  {   &lt;br /&gt;    //simulate a long running operation   &lt;br /&gt;    Thread.Sleep(3000);   &lt;br /&gt;    Console.WriteLine(&amp;quot;Current Thread:{0}&amp;quot;, Thread.CurrentThread.ManagedThreadId);   &lt;br /&gt;    return new[]{&amp;quot;Jack&amp;quot;,&amp;quot;Jon&amp;quot;,&amp;quot;Jim&amp;quot;};         &lt;br /&gt;  }   &lt;br /&gt;  public static string[] GetCountries()   &lt;br /&gt;  {   &lt;br /&gt;    //simulate a long running operation   &lt;br /&gt;    Thread.Sleep(4000);   &lt;br /&gt;    Console.WriteLine(&amp;quot;Current Thread:{0}&amp;quot;,Thread.CurrentThread.ManagedThreadId);   &lt;br /&gt;    return new[] { &amp;quot;US&amp;quot;,&amp;quot;UK&amp;quot;,&amp;quot;Canada&amp;quot; };   &lt;br /&gt;  }   &lt;br /&gt;  public static string[] GetLanguages()   &lt;br /&gt;  {   &lt;br /&gt;    //simulate a long running operation   &lt;br /&gt;    Thread.Sleep(3000);   &lt;br /&gt;    Console.WriteLine(&amp;quot;Current Thread:{0}&amp;quot;, Thread.CurrentThread.ManagedThreadId);   &lt;br /&gt;    return new[] { &amp;quot;English&amp;quot;, &amp;quot;French&amp;quot;, &amp;quot;German&amp;quot; };   &lt;br /&gt;  }   &lt;br /&gt;  static void Main(string[] args)   &lt;br /&gt;  {   &lt;br /&gt;    string[] countries;   &lt;br /&gt;    string[] users;   &lt;br /&gt;    string[] languages;   &lt;br /&gt;    Console.WriteLine(Environment.NewLine);   &lt;br /&gt;    Console.WriteLine(&amp;quot;Running Synchronously&amp;quot;);   &lt;br /&gt;    Console.WriteLine(&amp;quot;---------------------&amp;quot;);   &lt;br /&gt;    Stopwatch watch = new Stopwatch();   &lt;br /&gt;    watch.Start();   &lt;br /&gt;    countries = GetCountries();   &lt;br /&gt;    users = GetUsers();   &lt;br /&gt;    languages = GetLanguages();   &lt;br /&gt;    watch.Stop();   &lt;br /&gt;    Console.WriteLine(&amp;quot;Total time taken:{0} seconds&amp;quot;, watch.Elapsed.Seconds);   &lt;br /&gt;    watch.Reset();   &lt;br /&gt;    watch.Start();   &lt;br /&gt;    Console.WriteLine(&amp;quot;Running Asynchronously&amp;quot;);   &lt;br /&gt;    Console.WriteLine(&amp;quot;----------------------&amp;quot;);   &lt;br /&gt;    List&amp;lt;Action&amp;gt; actions = new List&amp;lt;Action&amp;gt;()   &lt;br /&gt;    {   &lt;br /&gt;      () =&amp;gt; countries = GetCountries(),   &lt;br /&gt;      () =&amp;gt; users = GetUsers(),   &lt;br /&gt;      () =&amp;gt; languages = GetLanguages(),   &lt;br /&gt;    };   &lt;br /&gt;    actions.ExecAsync();   &lt;br /&gt;    watch.Stop();   &lt;br /&gt;    Console.WriteLine(&amp;quot;Total time taken:{0} seconds&amp;quot;,watch.Elapsed.Seconds);  &lt;br /&gt;    Console.ReadLine();  &lt;br /&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/2523394595390906940-6021833681397148185?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/6021833681397148185/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/03/threading-performing-long-running.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/6021833681397148185'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/6021833681397148185'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/03/threading-performing-long-running.html' title='Threading : Performing long running operations using multiple asynchronous actions'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-3460295162848290968</id><published>2010-03-04T03:20:00.001-08:00</published><updated>2010-09-18T06:18:59.360-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Design'/><title type='text'>Designing classes with Fluent Interfaces</title><content type='html'>&lt;p&gt;&lt;a title="http://martinfowler.com/bliki/FluentInterface.html" href="http://martinfowler.com/bliki/FluentInterface.html"&gt;http://martinfowler.com/bliki/FluentInterface.html&lt;/a&gt;&lt;/p&gt;  &lt;pre class="brush: csharp;"&gt;using System;  &lt;br /&gt; using System.Collections.Generic;  &lt;br /&gt; using System.Linq;  &lt;br /&gt; using System.Text;  &lt;br /&gt;public class TestClass  &lt;br /&gt;{  &lt;br /&gt;  static void Main()  &lt;br /&gt;  {  &lt;br /&gt;    Person person = new Person();  &lt;br /&gt;    person.Set.FirstName(&amp;quot;Joe&amp;quot;).Age(35).LastName(&amp;quot;Patrick&amp;quot;).IsActive();  &lt;br /&gt;    Console.WriteLine(person.FirstName+ &amp;quot; &amp;quot;+ person.LastName+&amp;quot;'s age is &amp;quot;+ person.Age );  &lt;br /&gt;    Console.ReadLine();  &lt;br /&gt;  }  &lt;br /&gt;}  &lt;br /&gt;public class Person  &lt;br /&gt;{  &lt;br /&gt;  public Person()  &lt;br /&gt;  {  &lt;br /&gt;    _set = new PersonFluentInterface(this);  &lt;br /&gt;  }  &lt;br /&gt;  private string _firstName;  &lt;br /&gt;  private string _LastName;  &lt;br /&gt;  private int _age;  &lt;br /&gt;  private readonly PersonFluentInterface _set;  &lt;br /&gt;  private bool _isActive;  &lt;br /&gt;  public PersonFluentInterface Set  &lt;br /&gt;  {  &lt;br /&gt;    get { return _set; }  &lt;br /&gt;  }  &lt;br /&gt;  public string FirstName  &lt;br /&gt;  {  &lt;br /&gt;    get { return _firstName; }  &lt;br /&gt;    set { _firstName = value; }  &lt;br /&gt;  }  &lt;br /&gt;  public string LastName  &lt;br /&gt;  {  &lt;br /&gt;    get { return _LastName; }  &lt;br /&gt;    set { _LastName = 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;  public bool IsActive  &lt;br /&gt;  {  &lt;br /&gt;    get { return _isActive; }  &lt;br /&gt;    set { _isActive = value; }  &lt;br /&gt;  }  &lt;br /&gt;  public class PersonFluentInterface  &lt;br /&gt;  {  &lt;br /&gt;    private readonly Person _person;  &lt;br /&gt;    public PersonFluentInterface(Person person)  &lt;br /&gt;    {  &lt;br /&gt;      _person = person;  &lt;br /&gt;    }  &lt;br /&gt;    public PersonFluentInterface FirstName(string firstName)  &lt;br /&gt;    {  &lt;br /&gt;      _person.FirstName = firstName;  &lt;br /&gt;      return this;  &lt;br /&gt;    }  &lt;br /&gt;    public PersonFluentInterface LastName(string lastName)  &lt;br /&gt;    {  &lt;br /&gt;      _person.LastName = lastName;  &lt;br /&gt;      return this;  &lt;br /&gt;    }  &lt;br /&gt;    public PersonFluentInterface Age(int age)  &lt;br /&gt;    {  &lt;br /&gt;      _person.Age = age;  &lt;br /&gt;      return this;  &lt;br /&gt;    }  &lt;br /&gt;    public PersonFluentInterface IsActive()  &lt;br /&gt;    {  &lt;br /&gt;      _person.IsActive = true;  &lt;br /&gt;      return this;  &lt;br /&gt;    }  &lt;br /&gt;    public PersonFluentInterface IsNotActive()  &lt;br /&gt;    {  &lt;br /&gt;      _person.IsActive = false;  &lt;br /&gt;      return this;  &lt;br /&gt;    }  &lt;br /&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/2523394595390906940-3460295162848290968?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/3460295162848290968/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/03/designing-classes-with-fluent.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/3460295162848290968'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/3460295162848290968'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/03/designing-classes-with-fluent.html' title='Designing classes with Fluent Interfaces'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-4891662432467995398</id><published>2010-03-04T01:49:00.001-08:00</published><updated>2010-03-04T01:49:58.702-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Serialization'/><title type='text'>Serialization : serializing multiple types</title><content type='html'>&lt;pre style="border-bottom: #cccccc 1px dashed; text-align: left; border-left: #cccccc 1px dashed; padding-bottom: 0px; line-height: 20px; padding-left: 0px; width: 99%; padding-right: 0px; font-family: arial; background: #f0f0f0; height: auto; color: #000000; font-size: 12px; overflow: auto; border-top: #cccccc 1px dashed; border-right: #cccccc 1px dashed; padding-top: 0px"&gt;&lt;code style="word-wrap: normal; color: #000000"&gt; using System;  &lt;br /&gt; using System.IO;  &lt;br /&gt; using System.Xml;  &lt;br /&gt; using System.Xml.Serialization;  &lt;br /&gt; // This defines the object that will be serialized.  &lt;br /&gt; public class Teacher  &lt;br /&gt; {  &lt;br /&gt;   public string Name;  &lt;br /&gt;   public Teacher() { }  &lt;br /&gt;   /* Note that the Info field returns an array of objects.  &lt;br /&gt;     Any object can be added to the array by adding the  &lt;br /&gt;     object type to the array passed to the extraTypes argument. */  &lt;br /&gt;   [XmlArray(ElementName = &amp;quot;ExtraInfo&amp;quot;, IsNullable = true)]  &lt;br /&gt;   public object[] Info;  &lt;br /&gt;   public Phone PhoneInfo;  &lt;br /&gt; }  &lt;br /&gt; // This defines one of the extra types to be included.  &lt;br /&gt; public class Address  &lt;br /&gt; {  &lt;br /&gt;   public string City;  &lt;br /&gt;   public Address() { }  &lt;br /&gt;   public Address(string city)  &lt;br /&gt;   {  &lt;br /&gt;     City = city;  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt; // Another extra type to include.  &lt;br /&gt; public class Phone  &lt;br /&gt; {  &lt;br /&gt;   public string PhoneNumber;  &lt;br /&gt;   public Phone() { }  &lt;br /&gt;   public Phone(string phoneNumber)  &lt;br /&gt;   {  &lt;br /&gt;     PhoneNumber = phoneNumber;  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt; // Another type, derived from Phone  &lt;br /&gt; public class InternationalPhone : Phone  &lt;br /&gt; {  &lt;br /&gt;   public string CountryCode;  &lt;br /&gt;   public InternationalPhone() { }  &lt;br /&gt;   public InternationalPhone(string countryCode)  &lt;br /&gt;   {  &lt;br /&gt;     CountryCode = countryCode;  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt; public class Run  &lt;br /&gt; {  &lt;br /&gt;   public static void Main()  &lt;br /&gt;   {  &lt;br /&gt;     Run test = new Run();  &lt;br /&gt;     test.SerializeObject(&amp;quot;Teacher.xml&amp;quot;);  &lt;br /&gt;     test.DeserializeObject(&amp;quot;Teacher.xml&amp;quot;);  &lt;br /&gt;     Console.ReadLine();  &lt;br /&gt;   }  &lt;br /&gt;   private void SerializeObject(string filename)  &lt;br /&gt;   {  &lt;br /&gt;     // Writing the file requires a TextWriter.  &lt;br /&gt;     TextWriter myStreamWriter = new StreamWriter(filename);  &lt;br /&gt;     // Create a Type array.  &lt;br /&gt;     Type[] extraTypes = new Type[3];  &lt;br /&gt;     extraTypes[0] = typeof(Address);  &lt;br /&gt;     extraTypes[1] = typeof(Phone);  &lt;br /&gt;     extraTypes[2] = typeof(InternationalPhone);  &lt;br /&gt;     // Create the XmlSerializer instance.  &lt;br /&gt;     XmlSerializer mySerializer = new XmlSerializer  &lt;br /&gt;     (typeof(Teacher), extraTypes);  &lt;br /&gt;     Teacher teacher = new Teacher();  &lt;br /&gt;     teacher.Name = &amp;quot;Mike&amp;quot;;  &lt;br /&gt;     // Add extra types to the Teacher object  &lt;br /&gt;     object[] info = new object[2];  &lt;br /&gt;     info[0] = new Address(&amp;quot;Springville&amp;quot;);  &lt;br /&gt;     info[1] = new Phone(&amp;quot;555-0100&amp;quot;);  &lt;br /&gt;     teacher.Info = info;  &lt;br /&gt;     teacher.PhoneInfo = new InternationalPhone(&amp;quot;000&amp;quot;);  &lt;br /&gt;     mySerializer.Serialize(myStreamWriter, teacher);  &lt;br /&gt;     myStreamWriter.Close();  &lt;br /&gt;   }  &lt;br /&gt;   private void DeserializeObject(string filename)  &lt;br /&gt;   {  &lt;br /&gt;     // Create a Type array.  &lt;br /&gt;     Type[] extraTypes = new Type[3];  &lt;br /&gt;     extraTypes[0] = typeof(Address);  &lt;br /&gt;     extraTypes[1] = typeof(Phone);  &lt;br /&gt;     extraTypes[2] = typeof(InternationalPhone);  &lt;br /&gt;     // Create the XmlSerializer instance.  &lt;br /&gt;     XmlSerializer mySerializer = new XmlSerializer  &lt;br /&gt;     (typeof(Teacher), extraTypes);  &lt;br /&gt;     // Reading a file requires a FileStream.  &lt;br /&gt;     FileStream fs = new FileStream(filename, FileMode.Open);  &lt;br /&gt;     Teacher teacher = (Teacher)mySerializer.Deserialize(fs);  &lt;br /&gt;     // Read the extra information.  &lt;br /&gt;     Address a = (Address)teacher.Info[0];  &lt;br /&gt;     Phone p = (Phone)teacher.Info[1];  &lt;br /&gt;     InternationalPhone Ip =  &lt;br /&gt;     (InternationalPhone)teacher.PhoneInfo;  &lt;br /&gt;     Console.WriteLine(teacher.Name);  &lt;br /&gt;     Console.WriteLine(a.City);  &lt;br /&gt;     Console.WriteLine(p.PhoneNumber);  &lt;br /&gt;     Console.WriteLine(Ip.CountryCode);  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt; /*  &lt;br /&gt; &amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;  &lt;br /&gt; &amp;lt;Teacher xmlns:xsi=&amp;quot;http://www.w3.org/2001/XMLSchema-instance&amp;quot; xmlns:xsd=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot;&amp;gt;  &lt;br /&gt;  &amp;lt;Name&amp;gt;Mike&amp;lt;/Name&amp;gt;  &lt;br /&gt;  &amp;lt;ExtraInfo&amp;gt;  &lt;br /&gt;   &amp;lt;anyType xsi:type=&amp;quot;Address&amp;quot;&amp;gt;  &lt;br /&gt;    &amp;lt;City&amp;gt;Springville&amp;lt;/City&amp;gt;  &lt;br /&gt;   &amp;lt;/anyType&amp;gt;  &lt;br /&gt;   &amp;lt;anyType xsi:type=&amp;quot;Phone&amp;quot;&amp;gt;  &lt;br /&gt;    &amp;lt;PhoneNumber&amp;gt;555-0100&amp;lt;/PhoneNumber&amp;gt;  &lt;br /&gt;   &amp;lt;/anyType&amp;gt;  &lt;br /&gt;  &amp;lt;/ExtraInfo&amp;gt;  &lt;br /&gt;  &amp;lt;PhoneInfo xsi:type=&amp;quot;InternationalPhone&amp;quot;&amp;gt;  &lt;br /&gt;   &amp;lt;CountryCode&amp;gt;000&amp;lt;/CountryCode&amp;gt;  &lt;br /&gt;  &amp;lt;/PhoneInfo&amp;gt;  &lt;br /&gt; &amp;lt;/Teacher&amp;gt;  &lt;br /&gt; */  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-4891662432467995398?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/4891662432467995398/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/03/serialization-serializing-multiple.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/4891662432467995398'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/4891662432467995398'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/03/serialization-serializing-multiple.html' title='Serialization : serializing multiple types'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-2785703109008854626</id><published>2010-02-28T04:42:00.001-08:00</published><updated>2010-02-28T04:42:40.474-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Collection'/><title type='text'>Creating a non-generic custom collection supporting simple iteration</title><content type='html'>&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; using System;  &lt;br /&gt; using System.Collections;  &lt;br /&gt; public class Person  &lt;br /&gt; {  &lt;br /&gt;   public Person(string fName, string lName)  &lt;br /&gt;   {  &lt;br /&gt;     this.firstName = fName;  &lt;br /&gt;     this.lastName = lName;  &lt;br /&gt;   }  &lt;br /&gt;   public string firstName;  &lt;br /&gt;   public string lastName;  &lt;br /&gt; }  &lt;br /&gt; public class People : IEnumerable  &lt;br /&gt; {  &lt;br /&gt;   private Person[] _people;  &lt;br /&gt;   public People(Person[] pArray)  &lt;br /&gt;   {  &lt;br /&gt;     _people = new Person[pArray.Length];  &lt;br /&gt;     for (int i = 0; i &amp;lt; pArray.Length; i++)  &lt;br /&gt;     {  &lt;br /&gt;       _people[i] = pArray[i];  &lt;br /&gt;     }  &lt;br /&gt;   }  &lt;br /&gt;   public IEnumerator GetEnumerator()  &lt;br /&gt;   {  &lt;br /&gt;     return new PeopleEnum(_people);  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt; public class PeopleEnum : IEnumerator  &lt;br /&gt; {  &lt;br /&gt;   public Person[] _people;  &lt;br /&gt;   // Enumerators are positioned before the first element  &lt;br /&gt;   // until the first MoveNext() call.  &lt;br /&gt;   int position = -1;  &lt;br /&gt;   public PeopleEnum(Person[] list)  &lt;br /&gt;   {  &lt;br /&gt;     _people = list;  &lt;br /&gt;   }  &lt;br /&gt;   public bool MoveNext()  &lt;br /&gt;   {  &lt;br /&gt;     position++;  &lt;br /&gt;     return (position &amp;lt; _people.Length);  &lt;br /&gt;   }  &lt;br /&gt;   public void Reset()  &lt;br /&gt;   {  &lt;br /&gt;     position = -1;  &lt;br /&gt;   }  &lt;br /&gt;   public object Current  &lt;br /&gt;   {  &lt;br /&gt;     get  &lt;br /&gt;     {  &lt;br /&gt;       try  &lt;br /&gt;       {  &lt;br /&gt;         return _people[position];  &lt;br /&gt;       }  &lt;br /&gt;       catch (IndexOutOfRangeException)  &lt;br /&gt;       {  &lt;br /&gt;         throw new InvalidOperationException();  &lt;br /&gt;       }  &lt;br /&gt;     }  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt; class App  &lt;br /&gt; {  &lt;br /&gt;   static void Main()  &lt;br /&gt;   {  &lt;br /&gt;     Person[] peopleArray = new Person[3]  &lt;br /&gt;     {  &lt;br /&gt;       new Person("John", "Smith"),  &lt;br /&gt;       new Person("Jim", "Johnson"),  &lt;br /&gt;       new Person("Sue", "Rabon"),  &lt;br /&gt;     };  &lt;br /&gt;     People peopleList = new People(peopleArray);  &lt;br /&gt;     foreach (Person p in peopleList)  &lt;br /&gt;       Console.WriteLine(p.firstName + " " + p.lastName);  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt; /* This code produces output similar to the following:  &lt;br /&gt;  *   &lt;br /&gt;  * John Smith  &lt;br /&gt;  * Jim Johnson  &lt;br /&gt;  * Sue Rabon  &lt;br /&gt;  *   &lt;br /&gt;  */  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-2785703109008854626?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/2785703109008854626/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/creating-non-generic-custom-collection.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/2785703109008854626'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/2785703109008854626'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/creating-non-generic-custom-collection.html' title='Creating a non-generic custom collection supporting simple iteration'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-3832209686451336977</id><published>2010-02-28T02:16:00.001-08:00</published><updated>2010-02-28T02:16:36.431-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Collection'/><title type='text'>Generic Collection Classes from Wintellect’s Power Collections Library</title><content type='html'>&lt;p&gt;&lt;a title="http://www.codeplex.com/PowerCollections" href="http://www.codeplex.com/PowerCollections"&gt;http://www.codeplex.com/PowerCollections&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://lh4.ggpht.com/_jwjzQG-ntts/S4pCc4jOnEI/AAAAAAAACHg/Cskk3bIPun4/s1600-h/image%5B20%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Wintellect Power Collections" border="0" alt="Wintellect Power Collections" src="http://lh3.ggpht.com/_jwjzQG-ntts/S4pCghvWlTI/AAAAAAAACHk/YXyvMdwOKAs/image_thumb%5B16%5D.png?imgmax=800" width="762" height="541" /&gt;&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/2523394595390906940-3832209686451336977?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/3832209686451336977/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/generic-collection-classes-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/3832209686451336977'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/3832209686451336977'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/generic-collection-classes-from.html' title='Generic Collection Classes from Wintellect’s Power Collections Library'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://lh3.ggpht.com/_jwjzQG-ntts/S4pCghvWlTI/AAAAAAAACHk/YXyvMdwOKAs/s72-c/image_thumb%5B16%5D.png?imgmax=800' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-3342775156215427588</id><published>2010-02-27T04:17:00.001-08:00</published><updated>2010-02-27T04:17:59.942-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Exception'/><title type='text'>Exception Handling : Try..Catch..Finally</title><content type='html'>&lt;pre style="border-bottom: #cccccc 1px dashed; text-align: left; border-left: #cccccc 1px dashed; padding-bottom: 0px; line-height: 20px; padding-left: 0px; width: 99%; padding-right: 0px; font-family: arial; background: #f0f0f0; height: auto; color: #000000; font-size: 12px; overflow: auto; border-top: #cccccc 1px dashed; border-right: #cccccc 1px dashed; padding-top: 0px"&gt;&lt;code style="word-wrap: normal; color: #000000"&gt; using System;  &lt;br /&gt; using System.IO;  &lt;br /&gt; class FinallyDemo  &lt;br /&gt; {  &lt;br /&gt;   static void Main(string[] args)  &lt;br /&gt;   {  &lt;br /&gt;     FileStream outStream = null;  &lt;br /&gt;     FileStream inStream = null;  &lt;br /&gt;     try  &lt;br /&gt;     {  &lt;br /&gt;       outStream = File.OpenWrite(&amp;quot;DestinationFile.txt&amp;quot;);  &lt;br /&gt;       inStream = File.OpenRead(&amp;quot;BogusInputFile.txt&amp;quot;);  &lt;br /&gt;     }  &lt;br /&gt;     catch (FileNotFoundException fnfex)  &lt;br /&gt;     {  &lt;br /&gt;       Console.WriteLine(fnfex.ToString());  &lt;br /&gt;     }  &lt;br /&gt;     catch (Exception ex)  &lt;br /&gt;     {  &lt;br /&gt;       Console.WriteLine(ex.ToString());  &lt;br /&gt;     }  &lt;br /&gt;     finally  &lt;br /&gt;     {  &lt;br /&gt;       if (outStream != null)  &lt;br /&gt;       {  &lt;br /&gt;         outStream.Close();  &lt;br /&gt;         Console.WriteLine(&amp;quot;outStream closed.&amp;quot;);  &lt;br /&gt;       }  &lt;br /&gt;       if (inStream != null)  &lt;br /&gt;       {  &lt;br /&gt;         inStream.Close();  &lt;br /&gt;         Console.WriteLine(&amp;quot;inStream closed.&amp;quot;);  &lt;br /&gt;       }  &lt;br /&gt;     }  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-3342775156215427588?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/3342775156215427588/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/exception-handling-trycatchfinally.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/3342775156215427588'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/3342775156215427588'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/exception-handling-trycatchfinally.html' title='Exception Handling : Try..Catch..Finally'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-2120842075922113792</id><published>2010-02-27T04:05:00.001-08:00</published><updated>2010-02-27T04:07:32.886-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Event'/><title type='text'>Events : Simple existing and custom events using delegate</title><content type='html'>&lt;pre style="border-bottom: #cccccc 1px dashed; text-align: left; border-left: #cccccc 1px dashed; padding-bottom: 0px; line-height: 20px; padding-left: 0px; width: 99%; padding-right: 0px; font-family: arial; background: #f0f0f0; height: auto; color: #000000; font-size: 12px; overflow: auto; border-top: #cccccc 1px dashed; border-right: #cccccc 1px dashed; padding-top: 0px"&gt;&lt;code style="word-wrap: normal; color: #000000"&gt; using System;  &lt;br /&gt; using System.Drawing;  &lt;br /&gt; using System.Windows.Forms;  &lt;br /&gt; // custom delegate  &lt;br /&gt; public delegate void StartDelegate();  &lt;br /&gt; class EventDemo : Form  &lt;br /&gt; {  &lt;br /&gt;   // custom event  &lt;br /&gt;   public event StartDelegate StartEvent;  &lt;br /&gt;   public EventDemo()  &lt;br /&gt;   {  &lt;br /&gt;     Button clickMe = new Button();  &lt;br /&gt;     clickMe.Parent = this;  &lt;br /&gt;     clickMe.Text = &amp;quot;Click Me&amp;quot;;  &lt;br /&gt;     clickMe.Location = new Point(  &lt;br /&gt;       (ClientSize.Width - clickMe.Width) / 2,  &lt;br /&gt;       (ClientSize.Height - clickMe.Height) / 2);  &lt;br /&gt;     // an EventHandler delegate is assigned  &lt;br /&gt;     // to the button's Click event  &lt;br /&gt;     clickMe.Click += new EventHandler(OnClickMeClicked);  &lt;br /&gt;     // our custom &amp;quot;StartDelegate&amp;quot; delegate is assigned  &lt;br /&gt;     // to our custom &amp;quot;StartEvent&amp;quot; event.  &lt;br /&gt;     StartEvent += new StartDelegate(OnStartEvent);  &lt;br /&gt;     // fire our custom event  &lt;br /&gt;     StartEvent();  &lt;br /&gt;   }  &lt;br /&gt;   // this method is called when the &amp;quot;clickMe&amp;quot; button is pressed  &lt;br /&gt;   public void OnClickMeClicked(object sender, EventArgs ea)  &lt;br /&gt;   {  &lt;br /&gt;     MessageBox.Show(&amp;quot;You Clicked My Button!&amp;quot;);  &lt;br /&gt;   }  &lt;br /&gt;   // this method is called when the &amp;quot;StartEvent&amp;quot; Event is fired  &lt;br /&gt;   public void OnStartEvent()  &lt;br /&gt;   {  &lt;br /&gt;     MessageBox.Show(&amp;quot;I Just Started!&amp;quot;);  &lt;br /&gt;   }  &lt;br /&gt;   static void Main(string[] args)  &lt;br /&gt;   {  &lt;br /&gt;     Application.Run(new EventDemo());  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-2120842075922113792?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/2120842075922113792/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/events-simple-events-using-delegate.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/2120842075922113792'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/2120842075922113792'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/events-simple-events-using-delegate.html' title='Events : Simple existing and custom events using delegate'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-7883618386997758709</id><published>2010-02-26T23:20:00.001-08:00</published><updated>2010-02-26T23:20:58.435-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Casting'/><title type='text'>Casting, IS and AS Operator</title><content type='html'>&lt;p&gt;The IS operator checks whether an object is compatible with a given type, and the result of the evaluation is a Boolean: true or false. The is operator will never throw an exception.&lt;/p&gt;  &lt;pre style="border-bottom: #cccccc 1px dashed; text-align: left; border-left: #cccccc 1px dashed; padding-bottom: 0px; line-height: 20px; padding-left: 0px; width: 99%; padding-right: 0px; font-family: arial; background: #f0f0f0; height: auto; color: #000000; font-size: 12px; overflow: auto; border-top: #cccccc 1px dashed; border-right: #cccccc 1px dashed; padding-top: 0px"&gt;&lt;code style="word-wrap: normal; color: #000000"&gt; using System;  &lt;br /&gt; // This type is implicitly derived from System.Object.  &lt;br /&gt; internal class Employee /* : System.Object */ {  &lt;br /&gt; }  &lt;br /&gt; internal class Manager : Employee {  &lt;br /&gt; }  &lt;br /&gt; public static class Program {  &lt;br /&gt;   public static void Main() {  &lt;br /&gt;    // No cast needed since new returns an Employee object  &lt;br /&gt;    // and Object is a base type of Employee.  &lt;br /&gt;    Object o = new Employee();  &lt;br /&gt;    // Cast required since Employee is derived from Object.  &lt;br /&gt;    // Other languages (such as Visual Basic) might not require   &lt;br /&gt;    // this cast to compile.  &lt;br /&gt;    Employee e = (Employee) o;  &lt;br /&gt;   }  &lt;br /&gt;   public static void Main2() {  &lt;br /&gt;    // Construct a Manager object and pass it to PromoteEmployee.  &lt;br /&gt;    // A Manager IS-A Object: PromoteEmployee runs OK.  &lt;br /&gt;    Manager m = new Manager();  &lt;br /&gt;    PromoteEmployee(m);  &lt;br /&gt;    // Construct a DateTime object and pass it to PromoteEmployee.  &lt;br /&gt;    // A DateTime is NOT derived from Employee. PromoteEmployee   &lt;br /&gt;    // throws a System.InvalidCastException exception.   &lt;br /&gt;    DateTime newYears = new DateTime(2007, 1, 1);  &lt;br /&gt;    PromoteEmployee(newYears);  &lt;br /&gt;   }  &lt;br /&gt;   public static void PromoteEmployee(Object o) {  &lt;br /&gt;    // At this point, the compiler doesn’t know exactly what  &lt;br /&gt;    // type of object o refers to. So the compiler allows the   &lt;br /&gt;    // code to compile. However, at run time, the CLR does know   &lt;br /&gt;    // what type o refers to (each time the cast is performed) and  &lt;br /&gt;    // it checks whether the object’s type is Employee or any type  &lt;br /&gt;    // that is derived from Employee.  &lt;br /&gt;    Employee e = (Employee) o;  &lt;br /&gt;   }  &lt;br /&gt;   public static void PromoteEmployee2(Object o) {  &lt;br /&gt;    if (o is Employee) {  &lt;br /&gt;      Employee e = (Employee)o;  &lt;br /&gt;      // Use e within the remainder of the 'if' statement.   &lt;br /&gt;    }  &lt;br /&gt;   }  &lt;br /&gt;   public static void PromoteEmployee3(Object o) {  &lt;br /&gt;    Employee e = o as Employee;  &lt;br /&gt;    if (e != null) {  &lt;br /&gt;      // Use e within the 'if' statement.  &lt;br /&gt;    }  &lt;br /&gt;   }  &lt;br /&gt;   internal class B { // Base class  &lt;br /&gt;   }  &lt;br /&gt;   internal class D : B { // Derived class  &lt;br /&gt;   }  &lt;br /&gt;   private static void Main3() { // For Table 4-3 in the book  &lt;br /&gt;    Object o1 = new Object();  &lt;br /&gt;    Object o2 = new B();  &lt;br /&gt;    Object o3 = new D();  &lt;br /&gt;    Object o4 = o3;  &lt;br /&gt;    B b1 = new B();  &lt;br /&gt;    B b2 = new D();  &lt;br /&gt;    D d1 = new D();  &lt;br /&gt;    //B b3 = new Object();  &lt;br /&gt;    //D d2 = new Object();  &lt;br /&gt;    B b4 = d1;  &lt;br /&gt;    //D d3 = b2;  &lt;br /&gt;    D d4 = (D)d1;  &lt;br /&gt;    D d5 = (D)b2;  &lt;br /&gt;    D d6 = (D)b1; // Throws InvalidCastException  &lt;br /&gt;    B b5 = (B)o1; // Throws InvalidCastException  &lt;br /&gt;    B b6 = (D)b2;  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-7883618386997758709?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/7883618386997758709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/casting-is-and-as-operator.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/7883618386997758709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/7883618386997758709'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/casting-is-and-as-operator.html' title='Casting, IS and AS Operator'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-3154979003240206332</id><published>2010-02-26T20:53:00.001-08:00</published><updated>2010-02-26T20:54:02.530-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Build'/><title type='text'>Sample Assembly Info</title><content type='html'>&lt;pre style="border-bottom: #cccccc 1px dashed; text-align: left; border-left: #cccccc 1px dashed; padding-bottom: 0px; line-height: 20px; padding-left: 0px; width: 99%; padding-right: 0px; font-family: arial; background: #f0f0f0; height: auto; color: #000000; font-size: 12px; overflow: auto; border-top: #cccccc 1px dashed; border-right: #cccccc 1px dashed; padding-top: 0px"&gt;&lt;code style="word-wrap: normal; color: #000000"&gt; using System.Reflection;  &lt;br /&gt; // FileDescription version information:  &lt;br /&gt; [assembly: AssemblyTitle(&amp;quot;SampleAssemblyTypes.dll&amp;quot;)]  &lt;br /&gt; // Comments version information:  &lt;br /&gt; [assembly: AssemblyDescription(&amp;quot;This assembly contains SampleAssembly's types&amp;quot;)]  &lt;br /&gt; // CompanyName version information:  &lt;br /&gt; [assembly: AssemblyCompany(&amp;quot;SampleCompany&amp;quot;)]  &lt;br /&gt; // ProductName version information:  &lt;br /&gt; [assembly: AssemblyProduct(&amp;quot;SampleCompany (R) SampleAssembly's Type Library&amp;quot;)]  &lt;br /&gt; // LegalCopyright version information:  &lt;br /&gt; [assembly: AssemblyCopyright(&amp;quot;Copyright (c) SampleCompany 2010&amp;quot;)]  &lt;br /&gt; // LegalTrademarks version information:  &lt;br /&gt; [assembly: AssemblyTrademark(&amp;quot;SampleAssemblyTypes is a registered trademark of SampleCompany&amp;quot;)]  &lt;br /&gt; // AssemblyVersion version information:  &lt;br /&gt; [assembly: AssemblyVersion(&amp;quot;3.0.0.0&amp;quot;)]  &lt;br /&gt; // FILEVERSION/FileVersion version information:  &lt;br /&gt; [assembly: AssemblyFileVersion(&amp;quot;1.0.0.0&amp;quot;)]  &lt;br /&gt; // PRODUCTVERSION/ProductVersion version information:  &lt;br /&gt; [assembly: AssemblyInformationalVersion(&amp;quot;2.0.0.0&amp;quot;)]  &lt;br /&gt; // Set the Language field (discussed later in the &amp;quot;Culture&amp;quot; section)  &lt;br /&gt; [assembly: AssemblyCulture(&amp;quot;&amp;quot;)]  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-3154979003240206332?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/3154979003240206332/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/sample-assembly-info.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/3154979003240206332'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/3154979003240206332'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/sample-assembly-info.html' title='Sample Assembly Info'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-6465561090007354215</id><published>2010-02-22T04:24:00.001-08:00</published><updated>2010-05-15T12:30:48.948-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Delegate'/><title type='text'>Delegate Evolution: method, anonymous method, lambda expression, Func&lt;&gt; and Action&lt;&gt;</title><content type='html'>&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ffa74592-3a63-4a27-93ef-f4d9fc6113f0" class="wlWriterEditableSmartContent"&gt; &lt;div style="border: #000080 1px solid; color: #000; font-family: 'Courier New', Courier, Monospace; font-size: 10pt"&gt; &lt;div style="background: #ddd; overflow: auto"&gt; &lt;ol style="background: #ffffff; margin: 0 0 0 2.5em; padding: 0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff"&gt;using&lt;/span&gt; System;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;&lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Test&lt;/span&gt;&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;delegate&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; &lt;span style="color:#2b91af"&gt;TestDelegate&lt;/span&gt; ( &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; s );&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; M ( &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; s )&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    {&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine ( s );&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; s;&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; N ( &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; s )&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine ( s );&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Main ( &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;[] args )&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#008000"&gt;// Original delegate syntax required   &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// initialization with a named method.  &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;TestDelegate&lt;/span&gt; testdelA = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;TestDelegate&lt;/span&gt; ( M );&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// C# 2.0: A delegate can be initialized with  &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#008000"&gt;// inline code, called an &amp;quot;anonymous method.&amp;quot; This  &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// method takes a string as an input parameter.  &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;TestDelegate&lt;/span&gt; testDelB = &lt;span style="color:#0000ff"&gt;delegate&lt;/span&gt; ( &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; s ) { &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine ( s ); &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; s; };&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// C# 3.0. A delegate can be initialized with  &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#008000"&gt;// a lambda expression. The lambda also takes a string  &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// as an input parameter (x). The type of x is inferred by the compiler.  &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;TestDelegate&lt;/span&gt; testDelC = ( x ) =&amp;gt; { &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine ( x ); &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; x; };&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// Instantiate using Func delegate  &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;,&lt;span style="color:#0000ff"&gt;string&lt;/span&gt; &amp;gt; testDelD = M;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&amp;gt; testDelE = s =&amp;gt; { &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine ( s ); &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; s; };&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#008000"&gt;// Instantiate delegate using action for functions returing void  &lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Action&lt;/span&gt; &amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&amp;gt; testDelF = N;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Action&lt;/span&gt;&amp;lt;&lt;span style="color:#0000ff"&gt;string&lt;/span&gt;&amp;gt; testDelG = s =&amp;gt; { &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine ( s ); };&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// Invoke the delegates.  &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        testdelA ( &lt;span style="color:#a31515"&gt;&amp;quot;testdelA&amp;quot;&lt;/span&gt; );&lt;/li&gt; &lt;li&gt;        testDelB ( &lt;span style="color:#a31515"&gt;&amp;quot;testDelB&amp;quot;&lt;/span&gt; );&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        testDelC ( &lt;span style="color:#a31515"&gt;&amp;quot;testDelC&amp;quot;&lt;/span&gt; );&lt;/li&gt; &lt;li&gt;        testDelD ( &lt;span style="color:#a31515"&gt;&amp;quot;testDelD&amp;quot;&lt;/span&gt; );&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        testDelE ( &lt;span style="color:#a31515"&gt;&amp;quot;testDelE&amp;quot;&lt;/span&gt; );&lt;/li&gt; &lt;li&gt;        testDelF ( &lt;span style="color:#a31515"&gt;&amp;quot;testDelF&amp;quot;&lt;/span&gt; );&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        testDelG ( &lt;span style="color:#a31515"&gt;&amp;quot;testDelG&amp;quot;&lt;/span&gt; );&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#008000"&gt;// Keep console window open in debug mode.  &lt;/span&gt;&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.WriteLine ( &lt;span style="color:#a31515"&gt;&amp;quot;Press any key to exit.&amp;quot;&lt;/span&gt; );&lt;/li&gt; &lt;li&gt;        &lt;span style="color:#2b91af"&gt;Console&lt;/span&gt;.ReadKey ();&lt;/li&gt; &lt;li style="background: #f3f3f3"&gt;    }&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&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/2523394595390906940-6465561090007354215?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/6465561090007354215/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/delegate-evolution-method-anonymous.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/6465561090007354215'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/6465561090007354215'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/delegate-evolution-method-anonymous.html' title='Delegate Evolution: method, anonymous method, lambda expression, Func&amp;lt;&amp;gt; and Action&amp;lt;&amp;gt;'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-5223922749365926553</id><published>2010-02-21T05:23:00.001-08:00</published><updated>2010-02-21T05:23:42.695-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='My'/><title type='text'>How to use the My Namespace in C#</title><content type='html'>&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; //Add reference of Microsoft.VisualBasic.dll  &lt;br /&gt; using System;  &lt;br /&gt; using Microsoft.VisualBasic.Devices;  &lt;br /&gt; class TestMyServices  &lt;br /&gt; {  &lt;br /&gt;   static void Main()  &lt;br /&gt;   {  &lt;br /&gt;     // Play a sound with the Audio class:  &lt;br /&gt;     Audio myAudio = new Audio();  &lt;br /&gt;     Console.WriteLine("Playing sound...");  &lt;br /&gt;     myAudio.Play(@"c:\WINDOWS\Media\chimes.wav");  &lt;br /&gt;     // Display time information with the Clock class:  &lt;br /&gt;     Clock myClock = new Clock();  &lt;br /&gt;     Console.Write("Current day of the week: ");  &lt;br /&gt;     Console.WriteLine(myClock.LocalTime.DayOfWeek);  &lt;br /&gt;     Console.Write("Current date and time: ");  &lt;br /&gt;     Console.WriteLine(myClock.LocalTime);  &lt;br /&gt;     // Display machine information with the Computer class:  &lt;br /&gt;     Computer myComputer = new Computer();  &lt;br /&gt;     Console.WriteLine("Computer name: " + myComputer.Name);  &lt;br /&gt;     if (myComputer.Network.IsAvailable)  &lt;br /&gt;     {  &lt;br /&gt;       Console.WriteLine("Computer is connected to network.");  &lt;br /&gt;     }  &lt;br /&gt;     else  &lt;br /&gt;     {  &lt;br /&gt;       Console.WriteLine("Computer is not connected to network.");  &lt;br /&gt;     }  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-5223922749365926553?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/5223922749365926553/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/how-to-use-my-namespace-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/5223922749365926553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/5223922749365926553'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/how-to-use-my-namespace-in-c.html' title='How to use the My Namespace in C#'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-8082371142128266202</id><published>2010-02-20T01:16:00.001-08:00</published><updated>2010-02-20T01:16:00.634-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Collection'/><title type='text'>Implementing IEnumerator &amp; IEnumerable interfaces to a collection class to iterate using foreach statement</title><content type='html'>&lt;pre  style="font-family:arial;font-size:12px;border:1px dashed #CCCCCC;width:99%;height:auto;overflow:auto;background:#f0f0f0;padding:0px;color:#000000;text-align:left;line-height:20px;"&gt;&lt;code style="color:#000000;word-wrap:normal;"&gt; // tokens2.cs  &lt;br /&gt; using System;  &lt;br /&gt; using System.Collections;  &lt;br /&gt; public class Tokens : IEnumerable  &lt;br /&gt; {  &lt;br /&gt;   private string[] elements;  &lt;br /&gt;   Tokens(string source, char[] delimiters)  &lt;br /&gt;   {  &lt;br /&gt;     elements = source.Split(delimiters);  &lt;br /&gt;   }  &lt;br /&gt;   // IEnumerable Interface Implementation:  &lt;br /&gt;   public TokenEnumerator GetEnumerator() // non-IEnumerable version  &lt;br /&gt;   {  &lt;br /&gt;     return new TokenEnumerator(this);  &lt;br /&gt;   }  &lt;br /&gt;   IEnumerator IEnumerable.GetEnumerator() // IEnumerable version  &lt;br /&gt;   {  &lt;br /&gt;     return (IEnumerator)new TokenEnumerator(this);  &lt;br /&gt;   }  &lt;br /&gt;   // Inner class implements IEnumerator interface:  &lt;br /&gt;   public class TokenEnumerator : IEnumerator  &lt;br /&gt;   {  &lt;br /&gt;     private int position = -1;  &lt;br /&gt;     private Tokens t;  &lt;br /&gt;     public TokenEnumerator(Tokens t)  &lt;br /&gt;     {  &lt;br /&gt;       this.t = t;  &lt;br /&gt;     }  &lt;br /&gt;     public bool MoveNext()  &lt;br /&gt;     {  &lt;br /&gt;       if (position &amp;lt; t.elements.Length - 1)  &lt;br /&gt;       {  &lt;br /&gt;         position++;  &lt;br /&gt;         return true;  &lt;br /&gt;       }  &lt;br /&gt;       else  &lt;br /&gt;       {  &lt;br /&gt;         return false;  &lt;br /&gt;       }  &lt;br /&gt;     }  &lt;br /&gt;     public void Reset()  &lt;br /&gt;     {  &lt;br /&gt;       position = -1;  &lt;br /&gt;     }  &lt;br /&gt;     public string Current // non-IEnumerator version: type-safe  &lt;br /&gt;     {  &lt;br /&gt;       get  &lt;br /&gt;       {  &lt;br /&gt;         return t.elements[position];  &lt;br /&gt;       }  &lt;br /&gt;     }  &lt;br /&gt;     object IEnumerator.Current // IEnumerator version: returns object  &lt;br /&gt;     {  &lt;br /&gt;       get  &lt;br /&gt;       {  &lt;br /&gt;         return t.elements[position];  &lt;br /&gt;       }  &lt;br /&gt;     }  &lt;br /&gt;   }  &lt;br /&gt;   // Test Tokens, TokenEnumerator  &lt;br /&gt;   static void Main()  &lt;br /&gt;   {  &lt;br /&gt;     Tokens f = new Tokens("This is a well-done program.",  &lt;br /&gt;       new char[] { ' ', '-' });  &lt;br /&gt;     foreach (string item in f) // try changing string to int  &lt;br /&gt;     {  &lt;br /&gt;       Console.WriteLine(item);  &lt;br /&gt;     }  &lt;br /&gt;     Console.ReadLine();  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt; /*  &lt;br /&gt; Output:  &lt;br /&gt; This  &lt;br /&gt; is  &lt;br /&gt; a  &lt;br /&gt; well  &lt;br /&gt; done  &lt;br /&gt; program.  &lt;br /&gt;  */  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-8082371142128266202?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/8082371142128266202/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/implementing-ienumerator-ienumerable.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/8082371142128266202'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/8082371142128266202'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/implementing-ienumerator-ienumerable.html' title='Implementing IEnumerator &amp;amp; IEnumerable interfaces to a collection class to iterate using foreach statement'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-4417667329781308958</id><published>2010-02-20T00:35:00.001-08:00</published><updated>2010-02-20T00:38:23.558-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Inheritance'/><title type='text'>Method versioning in derived and base class using “override” and “new” keywords.</title><content type='html'>&lt;pre style="border-bottom: #cccccc 1px dashed; text-align: left; border-left: #cccccc 1px dashed; padding-bottom: 0px; line-height: 20px; padding-left: 0px; width: 99%; padding-right: 0px; font-family: arial; background: #f0f0f0; height: auto; color: #000000; font-size: 12px; overflow: auto; border-top: #cccccc 1px dashed; border-right: #cccccc 1px dashed; padding-top: 0px"&gt;&lt;code style="word-wrap: normal; color: #000000"&gt; using System;  &lt;br /&gt; public class MyBase  &lt;br /&gt; {  &lt;br /&gt;   public virtual string Meth1()  &lt;br /&gt;   {  &lt;br /&gt;     return &amp;quot;MyBase-Meth1&amp;quot;;  &lt;br /&gt;   }  &lt;br /&gt;   public virtual string Meth2()  &lt;br /&gt;   {  &lt;br /&gt;     return &amp;quot;MyBase-Meth2&amp;quot;;  &lt;br /&gt;   }  &lt;br /&gt;   public virtual string Meth3()  &lt;br /&gt;   {  &lt;br /&gt;     return &amp;quot;MyBase-Meth3&amp;quot;;  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt; class MyDerived : MyBase  &lt;br /&gt; {  &lt;br /&gt;   // Overrides the virtual method Meth1 using the override keyword:  &lt;br /&gt;   public override string Meth1()  &lt;br /&gt;   {  &lt;br /&gt;     return &amp;quot;MyDerived-Meth1&amp;quot;;  &lt;br /&gt;   }  &lt;br /&gt;   // Explicitly hide the virtual method Meth2 using the new  &lt;br /&gt;   // keyword:  &lt;br /&gt;   public new string Meth2()  &lt;br /&gt;   {  &lt;br /&gt;     return &amp;quot;MyDerived-Meth2&amp;quot;;  &lt;br /&gt;   }  &lt;br /&gt;   // Because no keyword is specified in the following declaration  &lt;br /&gt;   // a warning will be issued to alert the programmer that   &lt;br /&gt;   // the method hides the inherited member MyBase.Meth3():  &lt;br /&gt;   public string Meth3()  &lt;br /&gt;   {  &lt;br /&gt;     return &amp;quot;MyDerived-Meth3&amp;quot;;  &lt;br /&gt;   }  &lt;br /&gt;   public static void Main()  &lt;br /&gt;   {  &lt;br /&gt;     MyDerived mD = new MyDerived();  &lt;br /&gt;     MyBase mB = (MyBase)mD;  &lt;br /&gt;     MyBase mBn = new MyBase();  &lt;br /&gt;     Console.WriteLine(&amp;quot;Base Class&amp;quot;);  &lt;br /&gt;     System.Console.WriteLine(mBn.Meth1());  &lt;br /&gt;     System.Console.WriteLine(mBn.Meth2());  &lt;br /&gt;     System.Console.WriteLine(mBn.Meth3());  &lt;br /&gt;     Console.WriteLine(&amp;quot;---------------------&amp;quot;);  &lt;br /&gt;     Console.WriteLine(&amp;quot;Derived Class&amp;quot;);  &lt;br /&gt;     System.Console.WriteLine(mD.Meth1());  &lt;br /&gt;     System.Console.WriteLine(mD.Meth2());  &lt;br /&gt;     System.Console.WriteLine(mD.Meth3());  &lt;br /&gt;     Console.WriteLine(&amp;quot;---------------------&amp;quot;);  &lt;br /&gt;     Console.WriteLine(&amp;quot;Derived Class casted to base class&amp;quot;);  &lt;br /&gt;     System.Console.WriteLine(mB.Meth1());  &lt;br /&gt;     System.Console.WriteLine(mB.Meth2());  &lt;br /&gt;     System.Console.WriteLine(mB.Meth3());  &lt;br /&gt;     Console.ReadLine();  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt; /*  &lt;br /&gt; Output:  &lt;br /&gt; Base Class  &lt;br /&gt; MyBase-Meth1  &lt;br /&gt; MyBase-Meth2  &lt;br /&gt; MyBase-Meth3  &lt;br /&gt; ---------------------  &lt;br /&gt; Derived Class  &lt;br /&gt; MyDerived-Meth1  &lt;br /&gt; MyDerived-Meth2  &lt;br /&gt; MyDerived-Meth3  &lt;br /&gt; ---------------------  &lt;br /&gt; Derived Class casted to base class  &lt;br /&gt; MyDerived-Meth1  &lt;br /&gt; MyBase-Meth2  &lt;br /&gt; MyBase-Meth3  &lt;br /&gt; */  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-4417667329781308958?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/4417667329781308958/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/method-versioning-in-derived-and-base.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/4417667329781308958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/4417667329781308958'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/method-versioning-in-derived-and-base.html' title='Method versioning in derived and base class using “override” and “new” keywords.'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-4048468722807375016</id><published>2010-02-19T23:49:00.001-08:00</published><updated>2010-02-19T23:49:01.459-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Indexers'/><title type='text'>Indexers: Changing the word and characters occurrences in a document</title><content type='html'>&lt;pre style="border-bottom: #cccccc 1px dashed; text-align: left; border-left: #cccccc 1px dashed; padding-bottom: 0px; line-height: 20px; padding-left: 0px; width: 99%; padding-right: 0px; font-family: arial; background: url(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif) #f0f0f0; height: auto; color: #000000; font-size: 12px; overflow: auto; border-top: #cccccc 1px dashed; border-right: #cccccc 1px dashed; padding-top: 0px"&gt;&lt;code style="word-wrap: normal; color: #000000"&gt; // indexedproperty.cs  &lt;br /&gt; using System;  &lt;br /&gt; public class Document  &lt;br /&gt; {  &lt;br /&gt;   // Type allowing the document to be viewed like an array of words:  &lt;br /&gt;   public class WordCollection  &lt;br /&gt;   {  &lt;br /&gt;     readonly Document document; // The containing document  &lt;br /&gt;     internal WordCollection(Document d)  &lt;br /&gt;     {  &lt;br /&gt;       document = d;  &lt;br /&gt;     }  &lt;br /&gt;     // Helper function -- search character array &amp;quot;text&amp;quot;, starting at  &lt;br /&gt;     // character &amp;quot;begin&amp;quot;, for word number &amp;quot;wordCount.&amp;quot; Returns false  &lt;br /&gt;     // if there are less than wordCount words. Sets &amp;quot;start&amp;quot; and  &lt;br /&gt;     // length&amp;quot; to the position and length of the word within text:  &lt;br /&gt;     private bool GetWord(char[] text, int begin, int wordCount,   &lt;br /&gt;                     out int start, out int length)   &lt;br /&gt;     {   &lt;br /&gt;       int end = text.Length;  &lt;br /&gt;       int count = 0;  &lt;br /&gt;       int inWord = -1;  &lt;br /&gt;       start = length = 0;   &lt;br /&gt;       for (int i = begin; i &amp;lt;= end; ++i)   &lt;br /&gt;       {  &lt;br /&gt;         bool isLetter = i &amp;lt; end &amp;amp;&amp;amp; Char.IsLetterOrDigit(text[i]);  &lt;br /&gt;         if (inWord &amp;gt;= 0)   &lt;br /&gt;         {  &lt;br /&gt;           if (!isLetter)   &lt;br /&gt;           {  &lt;br /&gt;             if (count++ == wordCount)   &lt;br /&gt;             {  &lt;br /&gt;               start = inWord;  &lt;br /&gt;               length = i - inWord;  &lt;br /&gt;               return true;  &lt;br /&gt;             }  &lt;br /&gt;             inWord = -1;  &lt;br /&gt;           }  &lt;br /&gt;         }  &lt;br /&gt;         else   &lt;br /&gt;         {  &lt;br /&gt;           if (isLetter)  &lt;br /&gt;             inWord = i;  &lt;br /&gt;         }  &lt;br /&gt;       }  &lt;br /&gt;       return false;  &lt;br /&gt;     }  &lt;br /&gt;     // Indexer to get and set words of the containing document:  &lt;br /&gt;     public string this[int index]   &lt;br /&gt;     {  &lt;br /&gt;       get   &lt;br /&gt;       {   &lt;br /&gt;         int start, length;  &lt;br /&gt;         if (GetWord(document.TextArray, 0, index, out start,   &lt;br /&gt;                              out length))  &lt;br /&gt;           return new string(document.TextArray, start, length);  &lt;br /&gt;         else  &lt;br /&gt;           throw new IndexOutOfRangeException();  &lt;br /&gt;       }  &lt;br /&gt;       set   &lt;br /&gt;       {  &lt;br /&gt;         int start, length;  &lt;br /&gt;         if (GetWord(document.TextArray, 0, index, out start,   &lt;br /&gt;                              out length))   &lt;br /&gt;         {  &lt;br /&gt;           // Replace the word at start/length with the   &lt;br /&gt;           // string &amp;quot;value&amp;quot;:  &lt;br /&gt;           if (length == value.Length)   &lt;br /&gt;           {  &lt;br /&gt;             Array.Copy(value.ToCharArray(), 0,   &lt;br /&gt;                  document.TextArray, start, length);  &lt;br /&gt;           }  &lt;br /&gt;           else   &lt;br /&gt;           {  &lt;br /&gt;             char[] newText =   &lt;br /&gt;               new char[document.TextArray.Length +   &lt;br /&gt;                       value.Length - length];  &lt;br /&gt;             Array.Copy(document.TextArray, 0, newText,   &lt;br /&gt;                             0, start);  &lt;br /&gt;             Array.Copy(value.ToCharArray(), 0, newText,   &lt;br /&gt;                        start, value.Length);  &lt;br /&gt;             Array.Copy(document.TextArray, start + length,  &lt;br /&gt;                   newText, start + value.Length,  &lt;br /&gt;                  document.TextArray.Length - start  &lt;br /&gt;                               - length);  &lt;br /&gt;             document.TextArray = newText;  &lt;br /&gt;           }  &lt;br /&gt;         }            &lt;br /&gt;         else  &lt;br /&gt;           throw new IndexOutOfRangeException();  &lt;br /&gt;       }  &lt;br /&gt;     }  &lt;br /&gt;     // Get the count of words in the containing document:  &lt;br /&gt;     public int Count   &lt;br /&gt;     {  &lt;br /&gt;       get   &lt;br /&gt;       {   &lt;br /&gt;         int count = 0, start = 0, length = 0;  &lt;br /&gt;         while (GetWord(document.TextArray, start + length, 0,   &lt;br /&gt;                        out start, out length))  &lt;br /&gt;           ++count;  &lt;br /&gt;         return count;   &lt;br /&gt;       }  &lt;br /&gt;     }  &lt;br /&gt;   }  &lt;br /&gt;   // Type allowing the document to be viewed like an &amp;quot;array&amp;quot;   &lt;br /&gt;   // of characters:  &lt;br /&gt;   public class CharacterCollection  &lt;br /&gt;   {  &lt;br /&gt;     readonly Document document; // The containing document  &lt;br /&gt;     internal CharacterCollection(Document d)  &lt;br /&gt;     {  &lt;br /&gt;      document = d;   &lt;br /&gt;     }  &lt;br /&gt;     // Indexer to get and set characters in the containing document:  &lt;br /&gt;     public char this[int index]   &lt;br /&gt;     {  &lt;br /&gt;       get   &lt;br /&gt;       {   &lt;br /&gt;         return document.TextArray[index];   &lt;br /&gt;       }  &lt;br /&gt;       set   &lt;br /&gt;       {   &lt;br /&gt;         document.TextArray[index] = value;   &lt;br /&gt;       }  &lt;br /&gt;     }  &lt;br /&gt;     // Get the count of characters in the containing document:  &lt;br /&gt;     public int Count   &lt;br /&gt;     {  &lt;br /&gt;       get   &lt;br /&gt;       {   &lt;br /&gt;         return document.TextArray.Length;   &lt;br /&gt;       }  &lt;br /&gt;     }  &lt;br /&gt;   }  &lt;br /&gt;   // Because the types of the fields have indexers,   &lt;br /&gt;   // these fields appear as &amp;quot;indexed properties&amp;quot;:  &lt;br /&gt;   public readonly WordCollection Words;  &lt;br /&gt;   public readonly CharacterCollection Characters;  &lt;br /&gt;   private char[] TextArray; // The text of the document.   &lt;br /&gt;   public Document(string initialText)  &lt;br /&gt;   {  &lt;br /&gt;     TextArray = initialText.ToCharArray();  &lt;br /&gt;     Words = new WordCollection(this);  &lt;br /&gt;     Characters = new CharacterCollection(this);  &lt;br /&gt;   }  &lt;br /&gt;   public string Text   &lt;br /&gt;   {  &lt;br /&gt;     get   &lt;br /&gt;     {   &lt;br /&gt;       return new string(TextArray);   &lt;br /&gt;     }  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt; class Test  &lt;br /&gt; {  &lt;br /&gt;   static void Main()  &lt;br /&gt;   {  &lt;br /&gt;     Document d = new Document(  &lt;br /&gt;       &amp;quot;peter piper picked a peck of pickled peppers. How many pickled peppers did peter piper pick?&amp;quot;  &lt;br /&gt;     );  &lt;br /&gt;     // Change word &amp;quot;peter&amp;quot; to &amp;quot;penelope&amp;quot;:  &lt;br /&gt;     for (int i = 0; i &amp;lt; d.Words.Count; ++i)   &lt;br /&gt;     {  &lt;br /&gt;       if (d.Words[i] == &amp;quot;peter&amp;quot;)   &lt;br /&gt;         d.Words[i] = &amp;quot;penelope&amp;quot;;  &lt;br /&gt;     }  &lt;br /&gt;     // Change character &amp;quot;p&amp;quot; to &amp;quot;P&amp;quot;  &lt;br /&gt;     for (int i = 0; i &amp;lt; d.Characters.Count; ++i)   &lt;br /&gt;     {  &lt;br /&gt;       if (d.Characters[i] == 'p')  &lt;br /&gt;         d.Characters[i] = 'P';  &lt;br /&gt;     }  &lt;br /&gt;     Console.WriteLine(d.Text);  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-4048468722807375016?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/4048468722807375016/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/indexers-changing-word-and-characters.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/4048468722807375016'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/4048468722807375016'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/indexers-changing-word-and-characters.html' title='Indexers: Changing the word and characters occurrences in a document'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-485305088390997739</id><published>2010-02-19T23:10:00.001-08:00</published><updated>2010-02-19T23:10:06.812-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Indexers'/><title type='text'>Indexers</title><content type='html'>&lt;pre style="border-bottom: #cccccc 1px dashed; text-align: left; border-left: #cccccc 1px dashed; padding-bottom: 0px; line-height: 20px; padding-left: 0px; width: 99%; padding-right: 0px; font-family: arial; background: url(http://2.bp.blogspot.com/_z5ltvMQPaa8/SjJXr_U2YBI/AAAAAAAAAAM/46OqEP32CJ8/s320/codebg.gif) #f0f0f0; height: auto; color: #000000; font-size: 12px; overflow: auto; border-top: #cccccc 1px dashed; border-right: #cccccc 1px dashed; padding-top: 0px"&gt;&lt;code style="word-wrap: normal; color: #000000"&gt; using System;  &lt;br /&gt; class IndexerClass  &lt;br /&gt; {  &lt;br /&gt;   private int[] myArray = new int[100];  &lt;br /&gt;   public int this[int index]  // Indexer declaration  &lt;br /&gt;   {  &lt;br /&gt;     get  &lt;br /&gt;     {  &lt;br /&gt;       // Check the index limits.  &lt;br /&gt;       if (index &amp;lt; 0 || index &amp;gt;= 100)  &lt;br /&gt;         return 0;  &lt;br /&gt;       else  &lt;br /&gt;         return myArray[index];  &lt;br /&gt;     }  &lt;br /&gt;     set  &lt;br /&gt;     {  &lt;br /&gt;       if (!(index &amp;lt; 0 || index &amp;gt;= 100))  &lt;br /&gt;         myArray[index] = value;  &lt;br /&gt;     }  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt; public class MainClass  &lt;br /&gt; {  &lt;br /&gt;   public static void Main()  &lt;br /&gt;   {  &lt;br /&gt;     IndexerClass b = new IndexerClass();  &lt;br /&gt;     // Call the indexer to initialize the elements #3 and #5.  &lt;br /&gt;     b[3] = 256;  &lt;br /&gt;     b[5] = 1024;  &lt;br /&gt;     for (int i = 0; i &amp;lt;= 10; i++)  &lt;br /&gt;     {  &lt;br /&gt;       Console.WriteLine(&amp;quot;Element #{0} = {1}&amp;quot;, i, b[i]);  &lt;br /&gt;     }  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt;&lt;br /&gt;output:&lt;br /&gt;&lt;br /&gt; Element #0 = 0  &lt;br /&gt; Element #1 = 0  &lt;br /&gt; Element #2 = 0  &lt;br /&gt; Element #3 = 256  &lt;br /&gt; Element #4 = 0  &lt;br /&gt; Element #5 = 1024  &lt;br /&gt; Element #6 = 0  &lt;br /&gt; Element #7 = 0  &lt;br /&gt; Element #8 = 0  &lt;br /&gt; Element #9 = 0  &lt;br /&gt; Element #10 = 0  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-485305088390997739?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/485305088390997739/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/indexers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/485305088390997739'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/485305088390997739'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/indexers.html' title='Indexers'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2523394595390906940.post-8317480142554755332</id><published>2010-02-19T22:42:00.001-08:00</published><updated>2010-02-19T22:42:31.417-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='CommandLine'/><title type='text'>Number of Command Line Parameters</title><content type='html'>&lt;pre style="border-bottom: #cccccc 1px dashed; text-align: left; border-left: #cccccc 1px dashed; padding-bottom: 0px; line-height: 20px; padding-left: 0px; width: 99%; padding-right: 0px; font-family: arial; background: #f0f0f0; height: auto; color: #000000; font-size: 12px; overflow: auto; border-top: #cccccc 1px dashed; border-right: #cccccc 1px dashed; padding-top: 0px"&gt;&lt;code style="word-wrap: normal; color: #000000"&gt; &lt;br /&gt; using System;  &lt;br /&gt; public class CommandLine  &lt;br /&gt; {  &lt;br /&gt;   public static void Main(string[] args)  &lt;br /&gt;   {  &lt;br /&gt;     // The Length property is used to obtain the length of the array.   &lt;br /&gt;     // Notice that Length is a read-only property:  &lt;br /&gt;     Console.WriteLine(&amp;quot;Number of command line parameters = {0}&amp;quot;,  &lt;br /&gt;      args.Length);  &lt;br /&gt;     for(int i = 0; i &amp;lt; args.Length; i++)  &lt;br /&gt;     {  &lt;br /&gt;       Console.WriteLine(&amp;quot;Arg[{0}] = [{1}]&amp;quot;, i, args[i]);  &lt;br /&gt;     }  &lt;br /&gt;   }  &lt;br /&gt; }  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2523394595390906940-8317480142554755332?l=ajitsnippets.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://ajitsnippets.blogspot.com/feeds/8317480142554755332/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/number-of-command-line-parameters.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/8317480142554755332'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2523394595390906940/posts/default/8317480142554755332'/><link rel='alternate' type='text/html' href='http://ajitsnippets.blogspot.com/2010/02/number-of-command-line-parameters.html' title='Number of Command Line Parameters'/><author><name>Ajit Singh</name><uri>http://www.blogger.com/profile/17889678799981918534</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='http://photos1.blogger.com/blogger/5983/846/1600/AjitSingh.jpg'/></author><thr:total>0</thr:total></entry></feed>
