<?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-7988202699791029454</id><updated>2011-10-22T03:56:30.164-07:00</updated><category term='Obama Coiro Speech - Analysis'/><category term='Fruit juice'/><title type='text'>Everything in a single blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>33</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-5595356745914321888</id><published>2010-06-14T03:22:00.000-07:00</published><updated>2010-06-14T03:29:40.173-07:00</updated><title type='text'>upcasting and downcasting</title><content type='html'>The original aim of this article was to explain Up-casting and Down-casting. Having started writing the article, I was struggling to find an ideal way to describe these two concepts. Having thought further about it, one way I found was to introduce the concept of polymorphism to help explain up and down-casting. This has expanded the article further and when you have finished reading it, you should hopefully understand the three concepts better.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Polymorphism&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Polymorphism is a powerful aspect of object oriented programming. According to many searches on the Internet to find a definitive meaning, I have found two that seem to explain it quite nicely, these are "Having many forms" and "Having multiple forms".&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Consider the following. Ask yourself, what is a circle? Most would say a circle is a shape. A square, rectangle and a triangle are also shapes. So, what we are saying is a shape can take on many forms or has multiple forms. So how do we implement this concept in C#?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;First we need to design our base class, this will be called Shape. Our shape class will implement a constructor that will accept an X and Y co-ordinate and a method that will draw our shape. Below is the code for our shape class.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class Shape&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;protected int m_xpos;&lt;br /&gt;&lt;br /&gt;protected int m_ypos;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public Shape()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public Shape(int x, int y)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;m_xpos = x;&lt;br /&gt;&lt;br /&gt;m_ypos = y;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public virtual void Draw()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Console.WriteLine("Drawing a SHAPE at {0},{1}", m_xpos, m_ypos);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We now need to make our Draw method behave polymorphically. To do this, we declare our method with the keyword virtual in our base class. When we derive a class from shape we are able to implement a specific version of Draw by overriding the base class implementation of Draw. To do this, we use the keyword override when declaring our Draw method in our derived classes.&lt;br /&gt;&lt;br /&gt;What we will now do is implement two derived classes from our shape base class. We will implement Circle and Square. This will show how we override our base class Draw method.&lt;br /&gt;&lt;br /&gt;Circle and Square derived classes&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;One thing to note about the base class is the fact that I have used protected variables for the X and Y co-ordinates. Ideally you would use public properties and declare m_xpos and m_ypos as private.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Here are our two derived classes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class Square : Shape&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public Square()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public Square(int x, int y) : base(x, y)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public override void Draw()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Console.WriteLine("Drawing a SQUARE at {0},{1}", m_xpos, m_ypos);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;And finally Circle...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public class Circle : Shape&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;public Circle()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public Circle(int x, int y) : base(x, y)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public override void Draw()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Console.WriteLine("Drawing a CIRCLE at {0},{1}", m_xpos, m_ypos);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Notice, the highlighted code blocks. We have overridden the base class implementation of Draw in each of our derived classes. Basically override tells the compiler that we are intentionally overriding the behaviour of Draw.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We will now test the classes we have written, by putting together a simple piece of code that will create an instance of Shape, Circle and Square and call the Draw methods for each type.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;static void Main(string[] args)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Shape sh = new Shape(100, 100);&lt;br /&gt;&lt;br /&gt;sh.Draw();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Square sq = new Square(200, 200);&lt;br /&gt;&lt;br /&gt;sq.Draw();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Circle ci = new Circle(300, 300);&lt;br /&gt;&lt;br /&gt;ci.Draw();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The output generated by the test code is:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Drawing a SHAPE at 100,100&lt;br /&gt;&lt;br /&gt;Drawing a SQUARE at 200,200&lt;br /&gt;&lt;br /&gt;Drawing a CIRCLE at 300,300&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So what's happened that's polymorphic? Well, at this point absolutely nothing! Consider the code below.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;static void Main(string[] args)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Shape[] shapes = new Shape[3];&lt;br /&gt;&lt;br /&gt;shapes[0] = new Shape(100, 100);&lt;br /&gt;&lt;br /&gt;shapes[1] = new Square(200, 200);&lt;br /&gt;&lt;br /&gt;shapes[2] = new Circle(300, 300);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;foreach (Shape shape in shapes)&lt;br /&gt;&lt;br /&gt;shape.Draw();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What we have done is to create an array of the type Shape. Because Square and Circle are derived from Shape, we are able to put them in our array. What we are then doing is looping through all the elements of our array and calling Draw for each of our types. Because we have overridden the Draw method in each of our derived classes the output of our code is:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Drawing a SHAPE at 100,100&lt;br /&gt;&lt;br /&gt;Drawing a SQUARE at 200,200&lt;br /&gt;&lt;br /&gt;Drawing a CIRCLE at 300,300&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If we did not override Draw in one of our derived classes, the base class implementation of Draw would be called. For example, if we declared Draw in our Circle class as follows:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public void Draw()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Console.WriteLine("Drawing a CIRCLE at {0},{1}", m_xpos, m_ypos);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Our output would be:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Drawing a SHAPE at 100,100&lt;br /&gt;&lt;br /&gt;Drawing a SQUARE at 200,200&lt;br /&gt;&lt;br /&gt;Drawing a SHAPE at 300,300&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;By declaring the method as shown above, we will receive a compiler warning as follows:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Polymorphism.Circle.Draw() : Hides inherited member.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Polymorphism.Shape.Draw() :To make the current member override that implementation, add the override keyword. Otherwise add the new keyword.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If we do not want to override the base class method, we need to use the new keyword when declaring our method, for example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public new void Draw()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Console.WriteLine("Drawing a CIRCLE at {0},{1}", m_xpos, m_ypos);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This will remove the compiler warning. Basically we are telling the compiler that we are not overriding the base class implementation.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So what have we achieved with polymorphism? What we have been able to do is create an array of shapes and add a specific shape to each element of the array. When drawing each shape, we have not concerned ourselves with the fact that the shape could be a circle or a square. We have simply said, "here is an array of shapes, please draw them!" It is the responsibility of the compiler to discover the real type and to ensure that the correct implementation is called.&lt;br /&gt;&lt;br /&gt;Up-casting&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now we come on to one of the original goals of the article. With the simple example above of polymorphism, you should be able to quickly understand what up-casting is, in fact we have already used up-casting in our example.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The diagram below is a UML diagram for our polymorphism example.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Figure 1: UML Diagram For Shape.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Consider the following code:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Shape s = new Circle(100, 100);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We have cast Circle to the type Shape. This is perfectly legal code (as we saw in the Polymorphism example). This is possible, because Circle has been derived from Shape and you expect all methods and properties of Shape to exist in Circle. Executing the Draw method by doing s.Draw() gives the following output:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Drawing a CIRCLE at 100,100&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;If we had declared the Draw method in Circle as follows, public new void Draw() the output would have been:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Drawing a SHAPE at 100,100&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;As we have already mentioned, marking the method with new, tells the compiler that we are not overriding the base class implementation of the method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So why is this called up-casting? Consider the diagram above. From Circle, we are moving up the object hierarchy to the type Shape, so we are casting our object "upwards" to its parent type.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Up-casting is implicit and is safe. What do we mean by safe? Well, we can happily cast Circle to Shape and expect all the properties and methods of Shape to be available.&lt;br /&gt;&lt;br /&gt;Down-casting&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The flip side of the coin to up-casting is ...yes you guessed it, down-casting. Down-casting takes a little more understanding and you have to be very careful when down-casting types.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To help us better understand down-casting, we are going to add a new method to our Circle class. This will be a simple method called FillCircle.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;public void FillCircle()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Console.WriteLine("Filling CIRCLE at {0},{1}", m_xpos, m_ypos);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Using the example from up-casting, we know that we are able to write the following:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Shape s = new Circle(100, 100);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We are then free to call the Draw method. Having added the FillCircle method to our Circle class, are we able to call this method by doing the following?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;s.FillCircle ();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In short, the answer is no. Because we have cast Circle to the type Shape, we are only able to use methods found in Shape, that is, Circle has inherited all the properties and methods of Shape. If we want to call FillCircle, we need to down-cast our type to Circle. Why is it called down-casting? Quite simply, we are moving down the object hierarchy, from Shape down to Circle.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;So how do we code a down-cast from Shape to Circle? The code for doing this is quite simple:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Circle c;&lt;br /&gt;&lt;br /&gt;c = (Circle)s;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Simply, we are declaring c as the type Circle and explicitly casting s to this type. We are now able to call the FillCircle method by doing the following:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;c.FillCircle();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This gives us the following output:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Drawing a CIRCLE at 100,100&lt;br /&gt;&lt;br /&gt;Filling CIRCLE at 100,100&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We could also write ((Circle)s).FillCircle() reducing the lines of code needed to down-cast our type and call the required method.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Down-casting is potentially unsafe, because you could attempt to use a method that the derived class does not actually implement. With this in mind, down-casting is always explicit, that is, we are always specifying the type we are down-casting to.&lt;br /&gt;&lt;br /&gt;The as and is keywords&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To demonstrate as and is, lets implement a FillSquare method in our Square class. Our code could be:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Public void FillSquare()&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Console.WriteLine("Filling SQUARE at {0},{1}", m_xpos, m_ypos);&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Taking some code from our polymorphism example, as follows:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;class Program&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;static void Main(string[] args)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;Shape[] shapes = new Shape[3];&lt;br /&gt;&lt;br /&gt;shapes[0] = new Shape(100, 100);&lt;br /&gt;&lt;br /&gt;shapes[1] = new Square(200, 200);&lt;br /&gt;&lt;br /&gt;shapes[2] = new Circle(300, 300);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;foreach (Shape shape in shapes)&lt;br /&gt;&lt;br /&gt;shape.Draw();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;We have Circle and Square in our array of type Shape. How do we know what type we have to down-cast to in order to call the correct routine to fill the shape?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Within the foreach statement, we have to test the type of shape being drawn before we down-cast, we will use the is keyword to test type. We will modify the code above, to ensure the correct method is called to fill our shapes as they are drawn.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;foreach (Shape shape in shapes)&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;shape.Draw();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if (shape is Circle)&lt;br /&gt;&lt;br /&gt;((Circle)shape).FillCircle();&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;if (shape is Square)&lt;br /&gt;&lt;br /&gt;((Square)shape).FillSquare();&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Within the loop, we are performing a test to see if the type of shape is a Circle or a Square, depending on the result, we are down-casting our type in order to call the correct fill routine. Our output now is:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Drawing a SHAPE at 100,100&lt;br /&gt;Drawing a SQUARE at 200,200&lt;br /&gt;Filling SQUARE at 200,200&lt;br /&gt;&lt;br /&gt;Drawing a CIRCLE at 300,300&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Filling CIRCLE at 300,300&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I have highlighted the changes our code has made to the output. The alternative to the is keyword is as. We can write:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Circle c = shape as Circle;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The difference is that as tries to cast shape to a type (in our example Circle). If the cast fails, c is set to null. For example:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Circle c = shape as Circle;&lt;br /&gt;&lt;br /&gt;If(c!=null)&lt;br /&gt;&lt;br /&gt;c.FillCircle();&lt;br /&gt;&lt;br /&gt;Conclusion&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Quite a lot of ground has been covered in this article. Whilst the polymorphism example is very simple, it gives you an understanding of what polymorphism is and how you could implement it in your design.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The down-casting example is a little contrived. Some of you may be thinking why not just implement a base class method for filling the shapes and override it in the derived classes. The idea of implementing the fill routines as I did was to aid in the explanation of down-casting and has only been done for this reason.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-5595356745914321888?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/5595356745914321888/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/06/upcasting-and-downcasting.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/5595356745914321888'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/5595356745914321888'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/06/upcasting-and-downcasting.html' title='upcasting and downcasting'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-8664754249702584189</id><published>2010-03-04T09:21:00.000-08:00</published><updated>2010-03-04T09:31:50.208-08:00</updated><title type='text'>ICSE CBSE comparision : ICSE vs CBSE after 8th Standard and 10th standard</title><content type='html'>&lt;span style="font-style: italic;font-size:100%;" &gt;&lt;span style="font-size: 9pt; font-family: Arial;"&gt;&lt;span style="background-color: rgb(255, 255, 255);"&gt;&lt;strong&gt;&lt;p style="margin: 0in 0in 0pt 43.5pt; text-indent: -25.5pt;" class="MsoNormal"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;&lt;span&gt;&lt;span&gt;1.&lt;span style="font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; font-size: 7pt; line-height: normal; font-size-adjust: none; font-stretch: normal;"&gt;&lt;strong&gt;                     &lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;Which Board is difficult CBSE or ICSE&lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;Ans.  ICSE is difficult than          CBSE&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;...........................................................&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;&lt;span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt; text-indent: 2.25pt;" class="MsoNormal"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 43.5pt; text-indent: -25.5pt;" class="MsoNormal"&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;&lt;span&gt;2.&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;Why ICSE is difficult than          CBSE&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;Ans.           ICSE is little ahead of CBSE. The course covered by ICSE in 7th standard is done in 8th standard in   CBSE. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;...........................................................&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;&lt;span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt; text-indent: 2.25pt;" class="MsoNormal"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 43.5pt; text-indent: -25.5pt;" class="MsoNormal"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;&lt;span&gt;&lt;span&gt;3.&lt;span style=""&gt;            &lt;/span&gt;&lt;/span&gt;Which Subjects in ICSE are difficult          as compared to CBSE&lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;Ans.  In ICSE there is more emphasis on literature. The students who do not like literature          and Scoial Sciences finds it difficult. Science and Maths are almost the same in ICSE and CBSE.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;...........................................................&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;&lt;span&gt;4.      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Which board is easy for scoring?&lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;Ans. CBSE is more liberal          and students can get better marks as compared to ICSE.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;...........................................................&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;&lt;span&gt;5.      &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;Which board should I choose for my kid?&lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;&lt;span&gt;Ans.  This depends          on the caliber of the child, and his area of interest.&lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;ol style="margin-top: 0in;"&gt;&lt;ul style="margin-top: 0in;"&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;If the child is not so good at language and literature then, it          is better to go for CBSE.&lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;If  you want your child to take up management roles then, ICSE is far better then CBSE. ICSE gives a good command over language. &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;If you want your child to score more percentage in boards, go          for CBSE.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;If you want an overall better academic growth, go for ICSE          because 2% or 5% more is boards does not matter a lot in the overall career. &lt;span&gt; &lt;/span&gt;Even if the child becomes an engineer from the best institute, he might not rise in his career if he does not have an excellent command over his language.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin: 0in 0in 0pt;"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;...........................................................&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ol&gt;&lt;p style="margin: 0in 0in 0pt;" class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt;" class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt;" class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;       6.              Which board is better close to the engineering / Medical entrance exam?&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;Ans.  Both boards cover complete syllabus that is needed          for the entrance exams. CBSE being a little easier, the student gets more time to prepare for various entrance exams.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;...........................................................&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;&lt;span&gt;7.     &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;I am in CBSE board, can I switch to ICSE?&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;Ans. Technically anyone can shift from one board to the other but if you are in higher class, it is not good to change board. ICSE might be little difficult for you.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt; &lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;...........................................................&lt;/span&gt;&lt;/span&gt;           &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;&lt;span&gt;8.      I&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Arial;"&gt; want to do MBA which board should I choose?&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0in 0in 0pt 0.25in;" class="MsoNormal"&gt;&lt;span&gt;&lt;span style="background-color: rgb(255, 255, 204);"&gt;Ans.  If you are seriously planning          to do an MBA from some good B- School, you should go for ICSE. &lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-8664754249702584189?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/8664754249702584189/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/03/icse-cbse-comparision-icse-vs-cbse.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/8664754249702584189'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/8664754249702584189'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/03/icse-cbse-comparision-icse-vs-cbse.html' title='ICSE CBSE comparision : ICSE vs CBSE after 8th Standard and 10th standard'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-5299571281442870154</id><published>2010-03-02T00:38:00.000-08:00</published><updated>2010-03-02T00:39:50.503-08:00</updated><title type='text'>Powerful Leg &amp; Knee Strengthening Exercises Using Your Body Weight</title><content type='html'>&lt;p&gt;&lt;b&gt;Knee strengthening exercises&lt;/b&gt; like Knee Circles strengthen your knees and legs by &lt;b&gt;using your body weight&lt;/b&gt; as resistance. &lt;/p&gt;&lt;p&gt;Do this &lt;b&gt;simple&lt;/b&gt; yet &lt;b&gt;effective&lt;/b&gt; knee exercise in combination with other stretching and strengthening exercises for the lower body, such as the Forward Lunge, the Thigh Burner and the Forward Backward Bend (see below), and you &lt;i&gt;will&lt;/i&gt; develop &lt;b&gt;strong, flexible legs&lt;/b&gt;. &lt;/p&gt;&lt;p&gt;Having strong, flexible legs is important for upper body support and goodbalance. Doing regular leg stretching and strengthening exercises also stimulates vital nerve and energy channels from your spine to your toes. &lt;b&gt;Check with your health professional&lt;/b&gt; though before trying any new leg or knee exercises, particularly if you have a history of problems in this area. &lt;/p&gt;&lt;h3&gt;Knee Circles - Strengthen Your Knees &amp;amp; Ankles&lt;/h3&gt; &lt;img style="border: 0pt none ; margin: 8px 0pt 0pt 12px;" src="http://www.chinese-holistic-health-exercises.com/images/Knee-strengthening-exercises1.jpg" alt="" width="148" align="right" height="406" /&gt;  &lt;p&gt; &lt;/p&gt;&lt;p&gt;&lt;b&gt;How&lt;/b&gt;  &lt;/p&gt;&lt;p&gt;&lt;b&gt;1.&lt;/b&gt; Stand with your feet together.   &lt;/p&gt;&lt;p&gt;Bend your legs and squat down slightly.   &lt;/p&gt;&lt;p&gt;Put your hands on your knees so that your palms cover your kneecaps.   &lt;/p&gt;&lt;p&gt;Keep your feet firmly on the ground and your eyes focused on your toes. &lt;br /&gt;  &lt;/p&gt;&lt;hr width="100%" align="Left" size="2"&gt; &lt;img style="border: 0pt none ; margin: 8px 0pt 0pt 12px;" src="http://www.chinese-holistic-health-exercises.com/images/Knee-strengthening-exercises-2.jpg" alt="" width="147" align="right" height="415" /&gt; &lt;b&gt;2.&lt;/b&gt; &lt;i&gt;Slowly and gently&lt;/i&gt; begin moving your knees in small, clockwise circles.   &lt;p&gt;Don't make the circles too big - keep your knees above your toes.   &lt;/p&gt;&lt;p&gt;If your feet lift up, it means your knees are moving around too widely.   &lt;/p&gt;&lt;p&gt;Do 10-15 circles then repeat in the other direction.   &lt;/p&gt;&lt;p&gt;Build up to 25-30 circles in each direction, &lt;i&gt;or&lt;/i&gt; simply do the exercise for a couple of minutes 2-3 times a day.  &lt;br /&gt;  &lt;/p&gt;&lt;hr width="100%" align="Left" size="2"&gt; &lt;b&gt;Benefits&lt;/b&gt;&lt;ul&gt;&lt;li&gt; Strengthens your knees &amp;amp; ankles&lt;/li&gt;&lt;li&gt; Relieves pain &amp;amp; stiffness in your knee &amp;amp; ankle joints&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;b&gt;Tips&lt;/b&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Breathe slowly, deeply and evenly through your nose&lt;/li&gt;&lt;li&gt;Keep the exercise soft -&lt;i&gt; Don't&lt;/i&gt; force it &lt;/li&gt;&lt;li&gt;&lt;i&gt;Stop&lt;/i&gt; if you feel any pain&lt;/li&gt;&lt;/ul&gt;When done regularly, &lt;b&gt;Knee Circles&lt;/b&gt; is an &lt;b&gt;effective&lt;/b&gt; exercise to strengthen your knees &lt;i&gt;and&lt;/i&gt; ankles. No weights are required other than your body weight. Knees Circles and the other leg and knee strengthening exercises on this site are therefore &lt;b&gt;convenient&lt;/b&gt; to do any place you like. To enhance the effects of the above knee exercise, also include some (or all) of these &lt;b&gt;other leg and knee strengthening exercises&lt;/b&gt; in your routine:&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-5299571281442870154?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/5299571281442870154/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/03/powerful-leg-knee-strengthening.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/5299571281442870154'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/5299571281442870154'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/03/powerful-leg-knee-strengthening.html' title='Powerful Leg &amp; Knee Strengthening Exercises Using Your Body Weight'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-909514946271673156</id><published>2010-02-17T12:13:00.000-08:00</published><updated>2010-02-17T12:14:14.074-08:00</updated><title type='text'>C Sharp Window Forms</title><content type='html'>&lt;span style="font-size:85%;"&gt;&lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;This page contains a number of C# codes for the Amateur/Beginners in the Visual C# and .Net &lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;PlatForm Environment.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;This Tutorial will take anyone from the scratch to a good Windows Form creator  although I am still learning at my spare time.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Source Code:&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//MyForm1.cs&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//This Tutorial will Teach you how to create a Form without Caption Heading&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.Drawing;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.WinForms;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm : System.WinForms.Form&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm()&lt;br /&gt;{&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Main()&lt;br /&gt;{&lt;br /&gt;Application.Run(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;/*&lt;br /&gt;To Compile make a batch File in Dos Mode as compile.bat&lt;br /&gt;csc /r:System.dll /r:System.Drawing.dll /r:System.WinForms.dll&lt;br /&gt;/r:Microsoft.Win32.InterOp.dll /out:MyForm1.exe MyForm1.cs&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;OutPut:&lt;br /&gt;&lt;br /&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/jmukharjee/WindowsFormsTutorial111282005011245AM/Images/cstJM1.gif" align="baseline" border="0" hspace="0" /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Source Code:&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//MyForm2.cs&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//This Tutorial will Teach you how to create a Form with Caption Heading&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.Drawing;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.WinForms;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm : System.WinForms.Form&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm()&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//Text to be Displayed in the Caption-Title Bar&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Text = "Form Tutorial No.2 From JAYANT";&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Main()&lt;br /&gt;{&lt;br /&gt;Application.Run(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;/*&lt;br /&gt;To Compile make a batch File in Dos Mode as compile.bat&lt;br /&gt;csc /r:System.dll /r:System.Drawing.dll /r:System.WinForms.dll&lt;br /&gt;/r:Microsoft.Win32.InterOp.dll /out:MyForm2.exe MyForm2.cs&lt;br /&gt;*/&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;br /&gt;&lt;strong&gt;OutPut:&lt;br /&gt;&lt;br /&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/jmukharjee/WindowsFormsTutorial111282005011245AM/Images/cs2JM2.gif" align="baseline" border="0" hspace="0" /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Source Code:&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//MyForm3.cs&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//This Tutorial will Teach you how to create a Form with Added Functionality describing Size&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.Drawing;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.WinForms;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm : System.WinForms.Form&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm()&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//Text to be Displayed in the Caption-Title Bar&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Text = "Form Tutorial No.3 From JAYANT";&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.StartPosition = FormStartPosition.CenterScreen;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.AutoScaleBaseSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(5,13);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.ClientSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(400, 200); &lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//Size except the Title Bar-CaptionHeight&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.MinTrackSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(400, (200 + SystemInformation.CaptionHeight) );&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.MaximizeBox = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;false&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Main()&lt;br /&gt;{&lt;br /&gt;Application.Run(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;/*&lt;br /&gt;To Compile make a batch File in Dos Mode as compile.bat&lt;br /&gt;csc /r:System.dll /r:System.Drawing.dll /r:System.WinForms.dll&lt;br /&gt;/r:Microsoft.Win32.InterOp.dll /out:MyForm3.exe MyForm3.cs&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;OutPut:&lt;br /&gt;&lt;br /&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/jmukharjee/WindowsFormsTutorial111282005011245AM/Images/cs2JM3.gif" align="baseline" border="0" hspace="0" /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Source Code:&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//MyForm4.cs&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//This Tutorial will Teach you how to create a Form with Label on the Form&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.Drawing;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.WinForms;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm : System.WinForms.Form&lt;br /&gt;{&lt;br /&gt;Label label1;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm()&lt;br /&gt;{&lt;br /&gt;label1 = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Label();&lt;br /&gt;label1.UseMnemonic = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;label1.Text = "First &amp;amp;Name:";&lt;br /&gt;label1.Location = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Point(15,15);&lt;br /&gt;label1.BackColor = Color.Pink;&lt;br /&gt;label1.ForeColor = Color.Maroon;&lt;br /&gt;label1.BorderStyle = System.WinForms.BorderStyle.FixedSingle;&lt;br /&gt;label1.Size = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size (label1.PreferredWidth, label1.PreferredHeight + 2);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//Text to be Displayed in the Caption-Title Bar&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Text = "Form Tutorial No.4 From JAYANT";&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.StartPosition = FormStartPosition.CenterScreen;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.AutoScaleBaseSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(5,13);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.ClientSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(300, 200); &lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//Size except the Title Bar-CaptionHeight&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.MinTrackSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(300, (200 + SystemInformation.CaptionHeight) );&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.AutoScroll = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.MaximizeBox = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;false&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Controls.Add(label1);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Main()&lt;br /&gt;{&lt;br /&gt;Application.Run(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;/*&lt;br /&gt;To Compile make a batch File in Dos Mode as compile.bat&lt;br /&gt;csc /r:System.dll /r:System.Drawing.dll /r:System.WinForms.dll&lt;br /&gt;/r:Microsoft.Win32.InterOp.dll /out:MyForm4.exe MyForm4.cs&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;OutPut:&lt;br /&gt;&lt;br /&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/jmukharjee/WindowsFormsTutorial111282005011245AM/Images/cs2JM4.gif" align="baseline" border="0" hspace="0" /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Source Code:&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//MyForm5.cs&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//This Tutorial will Teach Mouse clicking Events and MessageBox(without Title_Heading) calling&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.Drawing;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.WinForms;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm : System.WinForms.Form&lt;br /&gt;{&lt;br /&gt;Label label1;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm()&lt;br /&gt;{&lt;br /&gt;label1 = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Label();&lt;br /&gt;label1.UseMnemonic = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;label1.Text = "First &amp;amp;Name:";&lt;br /&gt;label1.Location = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Point(15,15);&lt;br /&gt;label1.BackColor = Color.Pink;&lt;br /&gt;label1.ForeColor = Color.Maroon;&lt;br /&gt;label1.BorderStyle = System.WinForms.BorderStyle.FixedSingle;&lt;br /&gt;label1.Size = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size (label1.PreferredWidth, label1.PreferredHeight + 2);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//Text to be Displayed in the Caption-Title Bar&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Text = "Form Tutorial No.5 From JAYANT";&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.StartPosition = FormStartPosition.CenterScreen;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.AutoScaleBaseSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(5,13);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.ClientSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(300, 200); &lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//Size except the Title Bar-CaptionHeight&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.MinTrackSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(300, (200 + SystemInformation.CaptionHeight) );&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.AutoScroll = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.MaximizeBox = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;false&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Controls.Add(label1);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Click += &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; EventHandler(clicking);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; clicking(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;object&lt;/span&gt;&lt;span style="font-size:85%;"&gt; ob, EventArgs e)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show("You clicked on Form Area");&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Main()&lt;br /&gt;{&lt;br /&gt;Application.Run(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;/*&lt;br /&gt;To Compile make a batch File in Dos Mode as compile.bat&lt;br /&gt;csc /r:System.dll /r:System.Drawing.dll /r:System.WinForms.dll&lt;br /&gt;/r:Microsoft.Win32.InterOp.dll /out:MyForm5.exe MyForm5.cs&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;OutPut:&lt;br /&gt;&lt;br /&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/jmukharjee/WindowsFormsTutorial111282005011245AM/Images/cstJM5.gif" align="baseline" border="0" hspace="0" /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Source Code:&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//MyForm6.cs&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//This Tutorial will Teach Mouse clicking Events and MessageBox(with Title_Heading) calling&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.Drawing;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.WinForms;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm : System.WinForms.Form&lt;br /&gt;{&lt;br /&gt;Label label1;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm()&lt;br /&gt;{&lt;br /&gt;label1 = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Label();&lt;br /&gt;label1.UseMnemonic = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;label1.Text = "First &amp;amp;Name:";&lt;br /&gt;label1.Location = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Point(15,15);&lt;br /&gt;label1.BackColor = Color.Pink;&lt;br /&gt;label1.ForeColor = Color.Maroon;&lt;br /&gt;label1.BorderStyle = System.WinForms.BorderStyle.FixedSingle;&lt;br /&gt;label1.Size = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size (label1.PreferredWidth, label1.PreferredHeight + 2);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//Text to be Displayed in the Caption-Title Bar&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Text = "Form Tutorial No.6 From JAYANT";&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.StartPosition = FormStartPosition.CenterScreen;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;his&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.AutoScaleBaseSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(5,13);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.ClientSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(300, 200); &lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//Size except the Title Bar-CaptionHeight&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.MinTrackSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(300, (200 + SystemInformation.CaptionHeight) );&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.AutoScroll = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.MaximizeBox = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;false&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Controls.Add(label1);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Click += &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; EventHandler(clicking);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; clicking(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;object&lt;/span&gt;&lt;span style="font-size:85%;"&gt; ob, EventArgs e)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show("You clicked on Form Area","Title_JAYANT");&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Main()&lt;br /&gt;{&lt;br /&gt;Application.Run(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;/*&lt;br /&gt;To Compile make a batch File in Dos Mode as compile.bat&lt;br /&gt;csc /r:System.dll /r:System.Drawing.dll /r:System.WinForms.dll&lt;br /&gt;/r:Microsoft.Win32.InterOp.dll /out:MyForm6.exe MyForm6.cs&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;OutPut:&lt;br /&gt;&lt;br /&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/jmukharjee/WindowsFormsTutorial111282005011245AM/Images/cstJM6.gif" align="baseline" border="0" hspace="0" /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Source Code:&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//MyForm7.cs&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//This Tutorial will Teach Mouse clicking Events and changing the Form colour&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.Drawing;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.WinForms;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm : System.WinForms.Form&lt;br /&gt;{&lt;br /&gt;Label label1;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm()&lt;br /&gt;{&lt;br /&gt;label1 = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Label();&lt;br /&gt;label1.UseMnemonic = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;label1.Text = "First &amp;amp;Name:";&lt;br /&gt;label1.Location = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Point(15,15);&lt;br /&gt;label1.BackColor = Color.Pink;&lt;br /&gt;label1.ForeColor = Color.Maroon;&lt;br /&gt;label1.BorderStyle = System.WinForms.BorderStyle.FixedSingle;&lt;br /&gt;label1.Size = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size (label1.PreferredWidth, label1.PreferredHeight + 2);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//Text to be Displayed in the Caption-Title Bar&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Text = "Form Tutorial No.7 From JAYANT";&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.BackColor = Color.BurlyWood;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.StartPosition = FormStartPosition.CenterScreen;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.AutoScaleBaseSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(5,13);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.ClientSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(300, 200); &lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//Size except the Title Bar-CaptionHeight&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.MinTrackSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(300, (200 + SystemInformation.CaptionHeight) );&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.AutoScroll = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.MaximizeBox = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;false&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Controls.Add(label1);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Click += &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; EventHandler(clicking);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; clicking(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;object&lt;/span&gt;&lt;span style="font-size:85%;"&gt; ob, EventArgs e)&lt;br /&gt;{&lt;br /&gt;MessageBox.Show("Click will change the Form Color", "Title_JAYANT");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.BackColor = Color.Red;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Main()&lt;br /&gt;{&lt;br /&gt;Application.Run(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;/*&lt;br /&gt;To Compile make a batch File in Dos Mode as compile.bat&lt;br /&gt;csc /r:System.dll /r:System.Drawing.dll /r:System.WinForms.dll&lt;br /&gt;/r:Microsoft.Win32.InterOp.dll /out:MyForm7.exe MyForm7.cs&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;OutPut:&lt;br /&gt;&lt;br /&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/jmukharjee/WindowsFormsTutorial111282005011245AM/Images/cstJM7.gif" align="baseline" border="0" hspace="0" /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;Source Code:&lt;br /&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//MyForm8.cs&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//This Tutorial will Teach Mouse clicking Events and&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.Drawing;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="font-size:85%;"&gt; System.WinForms;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm : System.WinForms.Form&lt;br /&gt;{&lt;br /&gt;Label label1;&lt;br /&gt;TextBox txtbx1;&lt;br /&gt;Button btn1;&lt;br /&gt;Button exit;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm()&lt;br /&gt;{&lt;br /&gt;label1 = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Label();&lt;br /&gt;txtbx1 = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; TextBox();&lt;br /&gt;btn1 = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Button();&lt;br /&gt;exit = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Button();&lt;br /&gt;label1.UseMnemonic = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;label1.Text = "First &amp;amp;Name:";&lt;br /&gt;label1.Location = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Point(15,15);&lt;br /&gt;label1.BackColor = Color.Pink;&lt;br /&gt;label1.ForeColor = Color.Maroon;&lt;br /&gt;label1.BorderStyle = System.WinForms.BorderStyle.FixedSingle;&lt;br /&gt;label1.Size = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size (label1.PreferredWidth, label1.PreferredHeight + 2);&lt;br /&gt;txtbx1.Text = "Enter Your Name";&lt;br /&gt;txtbx1.Location = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Point(15+label1.PreferredWidth+5, 15);&lt;br /&gt;txtbx1.BorderStyle = System.WinForms.BorderStyle.FixedSingle;&lt;br /&gt;txtbx1.BackColor = Color.LightGray;&lt;br /&gt;txtbx1.ForeColor = Color.Maroon;&lt;br /&gt;txtbx1.Size = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size (90, 20);&lt;br /&gt;btn1.Text = "&amp;amp;OK";&lt;br /&gt;btn1.Location = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Point(15+txtbx1.Location.X+txtbx1.Size.Width,15);&lt;br /&gt;btn1.Size = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size (50, 20);&lt;br /&gt;exit.Text = "Exit";&lt;br /&gt;exit.Location = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Point(150,150);&lt;br /&gt;exit.Size = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size (90, 20);&lt;br /&gt;exit.BackColor = Color.Maroon;&lt;br /&gt;exit.ForeColor = Color.White;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//Text to be Displayed in the Caption-Title Bar&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Text = "Form Tutorial No.8 From JAYANT";&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.StartPosition = FormStartPosition.CenterScreen;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.AutoScaleBaseSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(5,13);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.ClientSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(300, 200); &lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//Size except the Title Bar-CaptionHeight&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.MinTrackSize = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Size(300, (200 + SystemInformation.CaptionHeight) );&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.AutoScroll = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;true&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.MaximizeBox = &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;false&lt;/span&gt;&lt;span style="font-size:85%;"&gt;;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Controls.Add(label1);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Controls.Add(txtbx1);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Controls.Add(btn1);&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;this&lt;/span&gt;&lt;span style="font-size:85%;"&gt;.Controls.Add(exit);&lt;br /&gt;btn1.Click += &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; EventHandler(Btn_Clicked);&lt;br /&gt;exit.Click += &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; EventHandler(Ext_Clicked);&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Btn_Clicked(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;object&lt;/span&gt;&lt;span style="font-size:85%;"&gt; ob, EventArgs e)&lt;br /&gt;{&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;if&lt;/span&gt;&lt;span style="font-size:85%;"&gt;(txtbx1.Text == "Enter Your Name")&lt;br /&gt;MessageBox.Show("You Have'nt Entered Your Name","Title_JAYANT");&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;else&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;MessageBox.Show("Hello!!! " + txtbx1.Text,"Title_JAYANT");&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Ext_Clicked(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;object&lt;/span&gt;&lt;span style="font-size:85%;"&gt; ob, EventArgs e)&lt;br /&gt;{&lt;br /&gt;Application.Exit();&lt;br /&gt;MessageBox.Show("Successfully Closed","EXIT");&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;//not Shown! Do you know Why?&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;static&lt;/span&gt;&lt;span style="font-size:85%;"&gt; &lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;void&lt;/span&gt;&lt;span style="font-size:85%;"&gt; Main()&lt;br /&gt;{&lt;br /&gt;Application.Run(&lt;/span&gt;&lt;span style="font-size:85%;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="font-size:85%;"&gt; MyForm());&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size:85%;color:#008000;"&gt;/*&lt;br /&gt;To Compile make a batch File in Dos Mode as compile.bat&lt;br /&gt;csc /r:System.dll /r:System.Drawing.dll /r:System.WinForms.dll&lt;br /&gt;/r:Microsoft.Win32.InterOp.dll /out:MyForm8.exe MyForm8.cs&lt;br /&gt;*/&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;"&gt;&lt;strong&gt;OutPut:&lt;br /&gt;&lt;br /&gt;&lt;img alt="" src="http://www.c-sharpcorner.com/UploadFile/jmukharjee/WindowsFormsTutorial111282005011245AM/Images/cstJM8.gif" align="baseline" border="0" hspace="0" /&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/span&gt;    &lt;table width="100%"&gt;     &lt;tbody&gt;&lt;tr&gt;         &lt;td&gt;                         &lt;br /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-909514946271673156?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/909514946271673156/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/c-sharp-window-forms.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/909514946271673156'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/909514946271673156'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/c-sharp-window-forms.html' title='C Sharp Window Forms'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-6007751301807571463</id><published>2010-02-17T00:59:00.001-08:00</published><updated>2010-02-17T01:11:15.786-08:00</updated><title type='text'>CSharp and Working with Data</title><content type='html'>This article introduces SQL, shows how to use ADO.NET Datasets, and connect to SQL Server and Microsoft Access databases. It introduces data binding and shows how to build your own SQL Query program that works with Access databases.  &lt;a name="Working_with_Data"&gt;&lt;/a&gt;&lt;h2&gt; Working with Data&lt;/h2&gt; &lt;p&gt;Database access is the perfect example of source code reuse. The basic operations are always the same—add, retrieve, update, and delete records. The only thing different is the structure of the data. Yet, each database system has its own native programming library that is not compatible with other databases, making it difficult to port applications to other database systems. So, it is not surprising that numerous database libraries have been developed over the years to encapsulate the implementation details of database operations. &lt;/p&gt;&lt;p&gt;In this article, we talk about how to access a database using ADO.NET—the set of classes that .NET provides for database access.&lt;br /&gt;&lt;/p&gt;&lt;h2&gt; Databases &lt;/h2&gt; &lt;p&gt;Most business applications need to access some kind of a database. That database could be a flat file, a directory of files, or it could be a server program that handles data requests from client programs. The later case is most common because database servers are optimized for managing large amounts of data and many concurrent connections. In the case of Microsoft Access, the tables are contained within a file with the MDB extension and the "server" is the JET database engine that your program communicates with using the classes that ADO.NET provides. &lt;/p&gt;&lt;p&gt;A &lt;i&gt;database&lt;/i&gt; consists of a collection of tables. Each table is defined as a set of columns and a collection of rows. Each row has a field of data for each column in its table. &lt;/p&gt;&lt;p&gt;A &lt;i&gt;relational database&lt;/i&gt; is a database that defines relationships between the tables. Consider the logical relationship between a &lt;code&gt;Customer&lt;/code&gt; table and an &lt;code&gt;Orders&lt;/code&gt; table. A customer can have many orders, but each order can belong to only one customer. This type of relationship is called &lt;i&gt;one-to-many&lt;/i&gt;.  &lt;/p&gt;&lt;p&gt;The &lt;code&gt;Customer&lt;/code&gt; record can be thought of as the parent record of each &lt;code&gt;Order&lt;/code&gt; record belonging to that customer. If you delete the &lt;code&gt;Customer&lt;/code&gt; record while it still has orders in the &lt;code&gt;Orders&lt;/code&gt; table, then those orders would be orphaned records. A relational database gives us the ability make that logical relationship a physical one by putting constraints or rules on the table, such as not allowing a &lt;code&gt;Customer&lt;/code&gt; record to be deleted if it has any &lt;code&gt;Order&lt;/code&gt; records, preserving the integrity of the database.  &lt;/p&gt;&lt;p&gt;A database table usually defines a &lt;i&gt;primary key&lt;/i&gt; to uniquely identify every record in the table. The primary key is normally a combination of one or more fields in the table. If a table contains child records that are linked back to a parent record, then the value of that parent’s primary key is usually stored in the child record. It is that field that provides the link to the parent record. When a table contains a field that stores a primary key from some other table, that field is called a &lt;i&gt;foreign key&lt;/i&gt;.  &lt;/p&gt;&lt;p&gt;Consider two tables that store &lt;code&gt;Customers&lt;/code&gt; and &lt;code&gt;Orders&lt;/code&gt;. The &lt;code&gt;Customer&lt;/code&gt; table may be defined to hold customer information and a primary key. Table 15.1 shows what a &lt;code&gt;Customer&lt;/code&gt; table might look like. &lt;/p&gt; &lt;blockquote&gt; &lt;a name="Table_15.1_-_Definition_of_the_Customer_Table"&gt;&lt;/a&gt;&lt;h3&gt;Table 15.1 - Definition of the Customer Table &lt;/h3&gt; &lt;table&gt;  &lt;tbody&gt;&lt;tr&gt; &lt;td&gt; &lt;b&gt;Field Name&lt;/b&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;b&gt;Data Type&lt;/b&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;CustomerID&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;code&gt;int, auto counter, primary key&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;Name&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;code&gt;string&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;Address&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;code&gt;string&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;Phone&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;code&gt;string&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/blockquote&gt; &lt;p&gt;The &lt;code&gt;Customer&lt;/code&gt; table is defined to store the &lt;code&gt;Name&lt;/code&gt;, &lt;code&gt;Address&lt;/code&gt;, and &lt;code&gt;Phone&lt;/code&gt; of a &lt;code&gt;Customer&lt;/code&gt;, as well as a &lt;code&gt;CustomerID&lt;/code&gt; field that will uniquely identify a record in the table. The &lt;code&gt;CustomerID&lt;/code&gt; field is the primary key. &lt;/p&gt;&lt;p&gt;The &lt;code&gt;Customer&lt;/code&gt; and &lt;code&gt;Orders&lt;/code&gt; table have a parent-child relationship, with &lt;code&gt;Customers&lt;/code&gt; being the parent table. Each &lt;code&gt;Customer&lt;/code&gt; can have one or more &lt;code&gt;Orders&lt;/code&gt;, giving the tables a one-to-many relationship. The definition of the &lt;code&gt;Orders&lt;/code&gt; table is below. &lt;/p&gt; &lt;blockquote&gt; &lt;a name="Table_15.2_-_Definition_of_the_Order_Table"&gt;&lt;/a&gt;&lt;h3&gt;Table 15.2 - Definition of the Order Table&lt;/h3&gt; &lt;table&gt;  &lt;tbody&gt;&lt;tr&gt; &lt;td&gt; &lt;b&gt;Field Name&lt;/b&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;b&gt;Data Type&lt;/b&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;OrderID&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;code&gt;int, auto counter, primary key&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;CustomerID&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;code&gt;int, foreign key&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;OrderDate&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;code&gt;DateTime&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;ShipDate&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;code&gt;DateTime&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/blockquote&gt; &lt;p&gt;The &lt;code&gt;Orders&lt;/code&gt; table definition stores the &lt;code&gt;OrderID&lt;/code&gt; as its primary key. It also stores the &lt;code&gt;CustomerID&lt;/code&gt; as the foreign key to link it back to the customer record of the customer who placed the order. &lt;/p&gt; &lt;a name="The_Northwind_Trader_Database"&gt;&lt;/a&gt;&lt;h2&gt; The Northwind Trader Database &lt;/h2&gt; &lt;p&gt;An example of a database is the Northwind Trader database, which you can install with Microsoft Access. The Northwind Trader database is a sample database that contains tables for &lt;code&gt;Customers&lt;/code&gt;, &lt;code&gt;Orders&lt;/code&gt;, &lt;code&gt;Employees&lt;/code&gt;, and other data commonly used by businesses. We will use the Northwind Trader database in the examples that follow. &lt;/p&gt; &lt;blockquote&gt; &lt;a name="Figure_15.1"&gt;&lt;/a&gt;&lt;h3&gt;Figure 15.1&lt;/h3&gt; &lt;p&gt;&lt;a href="http://en.csharp-online.net/Image:Figure15_1.jpg" class="image" title="Image:Figure15_1.jpg"&gt;&lt;img style="width: 417px; height: 296px;" src="http://en.csharp-online.net/images/b/b5/Figure15_1.jpg" alt="Image:Figure15_1.jpg" longdesc="/Image:Figure15_1.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;h2&gt; Introduction to SQL &lt;/h2&gt; &lt;p&gt;Most databases use a language called SQL, Structured Query Language, to process their commands. While SQL (commonly pronounced "sequel") is a large topic, the basics are easily grasped by looking at a few statements. The basic operations for any database are to add, retrieve, update, and delete records. The SQL language supports these operations with the following four statements. &lt;/p&gt; &lt;a name="The_INSERT_Statement"&gt;&lt;/a&gt;&lt;h2&gt;The &lt;code&gt;INSERT&lt;/code&gt; Statement&lt;/h2&gt; &lt;p&gt;The &lt;code&gt;INSERT&lt;/code&gt; statement will add new records to a table. To insert a record, you must specify the name of the table and the values for the fields. The following statement inserts a new record into the &lt;code&gt;Customers&lt;/code&gt; table of the Northwind Trader database.  &lt;/p&gt; &lt;pre class="sql"&gt;&lt;span style="color: rgb(153, 51, 51); font-weight: bold;"&gt;INSERT&lt;/span&gt; &lt;span style="color: rgb(153, 51, 51); font-weight: bold;"&gt;INTO&lt;/span&gt; Customers &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt; CustomerID, CompanyName &lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(153, 51, 51); font-weight: bold;"&gt;VALUES&lt;/span&gt; &lt;span style="color: rgb(102, 204, 102);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;'SUD100'&lt;/span&gt;, &lt;span style="color: rgb(255, 0, 0);"&gt;'Jeff Suddeth'&lt;/span&gt;&lt;span style="color: rgb(102, 204, 102);"&gt;)&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;The &lt;code&gt;INSERT&lt;/code&gt; statement takes the name of the table that you want to insert a record into. Then, in parentheses, you must specify the list of fields you are setting values to. After the &lt;code&gt;VALUES&lt;/code&gt; keyword, there is another set of parentheses that include the list of values to be assigned to the fields. The statement above creates a new &lt;code&gt;Customers&lt;/code&gt; record and sets the &lt;code&gt;CustomerID&lt;/code&gt; field to &lt;code&gt;"SUD100"&lt;/code&gt; and the &lt;code&gt;CompanyName&lt;/code&gt; field to &lt;code&gt;"Jeff Suddeth"&lt;/code&gt;. All other fields will be null unless the field has a default value defined. &lt;/p&gt; &lt;a name="The_SELECT_Statement"&gt;&lt;/a&gt;&lt;h2&gt; The &lt;code&gt;SELECT&lt;/code&gt; Statement &lt;/h2&gt; &lt;p&gt;Use the &lt;code&gt;SELECT&lt;/code&gt; statement to retrieve a set of records based on the criteria you specify. The &lt;code&gt;SELECT&lt;/code&gt; statement may return zero or more records depending on the conditions of your selection. The following statement does not specify any selection criteria. It will return the &lt;code&gt;CustomerID&lt;/code&gt; and &lt;code&gt;CompanyName&lt;/code&gt; fields from every row in the table. &lt;/p&gt; &lt;pre class="sql"&gt;&lt;span style="color: rgb(153, 51, 51); font-weight: bold;"&gt;SELECT&lt;/span&gt; CustomerID, CompanyName&lt;br /&gt;&lt;span style="color: rgb(153, 51, 51); font-weight: bold;"&gt;FROM&lt;/span&gt; Customers&lt;/pre&gt; &lt;p&gt;To add search criteria to the &lt;code&gt;SELECT&lt;/code&gt; statement, you can use the &lt;code&gt;WHERE&lt;/code&gt; clause. The &lt;code&gt;WHERE&lt;/code&gt; clause takes a comma separated list of conditions. The following select statement will select the record we added above. &lt;/p&gt; &lt;pre class="sql"&gt;&lt;span style="color: rgb(153, 51, 51); font-weight: bold;"&gt;SELECT&lt;/span&gt; CustomerID, CompanyName&lt;br /&gt;&lt;span style="color: rgb(153, 51, 51); font-weight: bold;"&gt;FROM&lt;/span&gt; Customers&lt;span style="color: rgb(255, 0, 0);"&gt;''&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;'&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;h2&gt; The ADO.NET Classes &lt;/h2&gt; &lt;p&gt;ADO.NET is the portion of the .NET library that deals with databases. Table 15.3 lists some of the common ADO.NET classes. &lt;/p&gt; &lt;a name="Table_15.3_.E2.80.93_Classes_of_ADO.NET"&gt;&lt;/a&gt;&lt;h3&gt;Table 15.3 – Classes of ADO.NET&lt;/h3&gt; &lt;table style="border-style: solid; border-width: 2px; width: 492px; height: 178px;"&gt;  &lt;tbody&gt;&lt;tr bgcolor="#e0e0e0"&gt; &lt;td&gt; &lt;b&gt;Class&lt;/b&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;b&gt;Description&lt;/b&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;DataSet&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; A set of database tables that can be filled from a database and used as a disconnected database &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;DataTable&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; A collection data rows and the columns that define their structure &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;DataRow&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; A database Record &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;DataView&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; A view of the data. Can be filtered for search criteria and sorted &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;DataRowView&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; A single row from a DataView &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;DataRelation&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; A parent-child relationship between tables &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;&lt;br /&gt;The classes in Table 15.3 organize the data into table structures. They are declared within the &lt;code&gt;System.Data&lt;/code&gt; namespace. The &lt;code&gt;DataSet&lt;/code&gt; class is one of the most useful classes in .NET; because, it encapsulates a collection of tables and the relationships between those tables. It is essentially a mini database that you can use in memory. You can also fill the &lt;code&gt;DataSet&lt;/code&gt; with tables and data from some other database, giving you a local cache of data. &lt;/p&gt;&lt;span class="plainlinks"&gt;&lt;a href="http://en.csharp-online.net/Working_with_Data%E2%80%94Introduction_to_SQL" title="http://en.csharp-online.net/Working_with_Data%E2%80%94Introduction_to_SQL" rel="nofollow"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;h2&gt; Roll Your Own Database &lt;/h2&gt; &lt;p&gt;In this section, we use the ADO.NET classes from Table 15.3 to define a database of customer information. We will define the structure of the database by adding columns to a table named &lt;code&gt;Customers&lt;/code&gt;. Then, we will load some sample data into the table and persist the data to an XML file. When the program runs again, we will load the database from the XML file and print the data that it contains. The complete listing is shown in Example15_1.cs. &lt;/p&gt; &lt;a name="Listing_15.1"&gt;&lt;/a&gt;&lt;h3&gt;Listing 15.1&lt;/h3&gt; &lt;pre class="csharp"&gt;&lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// Example15_1.cs&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;using&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;System&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;using&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;System&lt;/span&gt;.&lt;span style="color: rgb(43, 145, 175);"&gt;Text&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;using&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;System&lt;/span&gt;.&lt;span style="color: rgb(43, 145, 175);"&gt;Data&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;using&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;System&lt;/span&gt;.&lt;span style="color: rgb(43, 145, 175);"&gt;IO&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;namespace&lt;/span&gt; csbook.&lt;span style="color: rgb(0, 0, 0);"&gt;ch15&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;class&lt;/span&gt; CustomerDatabase &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(6, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;void&lt;/span&gt; MakeFile&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(43, 145, 175);"&gt;DataSet&lt;/span&gt; ds = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataSet&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       ds.&lt;span style="color: rgb(0, 0, 0);"&gt;DataSetName&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"CustomerDatabase"&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(43, 145, 175);"&gt;DataTable&lt;/span&gt; custTable = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataTable&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;TableName&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"Customers"&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// this will be the primary key&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(43, 145, 175);"&gt;DataColumn&lt;/span&gt; custId = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataColumn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"CustID"&lt;/span&gt;, &lt;span style="color: rgb(6, 0, 255);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       custId.&lt;span style="color: rgb(0, 0, 0);"&gt;AutoIncrement&lt;/span&gt; = &lt;span style="color: rgb(6, 0, 255);"&gt;true&lt;/span&gt;;&lt;br /&gt;       custId.&lt;span style="color: rgb(0, 0, 0);"&gt;AutoIncrementSeed&lt;/span&gt; = &lt;span style="color: rgb(255, 0, 0);"&gt;101&lt;/span&gt;;&lt;br /&gt;       custId.&lt;span style="color: rgb(0, 0, 0);"&gt;AutoIncrementStep&lt;/span&gt; = &lt;span style="color: rgb(255, 0, 0);"&gt;1&lt;/span&gt;;&lt;br /&gt;       custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;Columns&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;custId&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// make this the primary key&lt;/span&gt;&lt;br /&gt;       custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;PrimaryKey&lt;/span&gt; = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataColumn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt; custId &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// add some fields for customer data&lt;/span&gt;&lt;br /&gt;       custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;Columns&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataColumn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Name"&lt;/span&gt;, &lt;span style="color: rgb(6, 0, 255);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;Columns&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataColumn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Phone"&lt;/span&gt;, &lt;span style="color: rgb(6, 0, 255);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;Columns&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataColumn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Email"&lt;/span&gt;, &lt;span style="color: rgb(6, 0, 255);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// add the table to the DataSet&lt;/span&gt;&lt;br /&gt;       ds.&lt;span style="color: rgb(0, 0, 0);"&gt;Tables&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;custTable&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// add some records to the table&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(43, 145, 175);"&gt;DataRow&lt;/span&gt; row;&lt;br /&gt;       row = custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;NewRow&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Name"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"Evy"&lt;/span&gt;;&lt;br /&gt;       row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Phone"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"123-555-9876"&lt;/span&gt;;&lt;br /&gt;       row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Email"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"evy@evymail.com"&lt;/span&gt;;&lt;br /&gt;       custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;Rows&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;row&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       row = custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;NewRow&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Name"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"Jon"&lt;/span&gt;;&lt;br /&gt;       row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Phone"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"123-444-7384"&lt;/span&gt;;&lt;br /&gt;       row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Email"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"jon@jonsmail.com"&lt;/span&gt;;&lt;br /&gt;       custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;Rows&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;row&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       row = custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;NewRow&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Name"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"Eric"&lt;/span&gt;;&lt;br /&gt;       row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Phone"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"123-666-7398"&lt;/span&gt;;&lt;br /&gt;       row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Email"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"eric@ericsmail.com"&lt;/span&gt;;&lt;br /&gt;       custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;Rows&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;row&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// dump to XML&lt;/span&gt;&lt;br /&gt;       ds.&lt;span style="color: rgb(0, 0, 0);"&gt;WriteXml&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"customers.xml"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(43, 145, 175);"&gt;Console&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;WriteLine&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"The file was created"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(6, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;void&lt;/span&gt; ReadFile&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(43, 145, 175);"&gt;DataSet&lt;/span&gt; ds = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataSet&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       ds.&lt;span style="color: rgb(0, 0, 0);"&gt;ReadXml&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"customers.xml"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(6, 0, 255);"&gt;foreach&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;DataRow&lt;/span&gt; row &lt;span style="color: rgb(6, 0, 255);"&gt;in&lt;/span&gt; ds.&lt;span style="color: rgb(0, 0, 0);"&gt;Tables&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Rows&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// get the data&lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt; name = &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Name"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt; phone = &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Phone"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt; email = &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Email"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;          &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// build the string&lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(43, 145, 175);"&gt;StringBuilder&lt;/span&gt; builder = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;StringBuilder&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;          builder.&lt;span style="color: rgb(0, 0, 0);"&gt;AppendFormat&lt;/span&gt;&lt;br /&gt;             &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Name: {0}&lt;span style="color: rgb(163, 21, 21); font-weight: bold;"&gt;\t&lt;/span&gt; Phone: {1}&lt;span style="color: rgb(163, 21, 21); font-weight: bold;"&gt;\t&lt;/span&gt; Email: {2}"&lt;/span&gt;,&lt;br /&gt;               name, phone, email&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// write the string&lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(43, 145, 175);"&gt;Console&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;WriteLine&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;builder.&lt;span style="color: rgb(0, 0, 0);"&gt;ToString&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(6, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;void&lt;/span&gt; Test&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(6, 0, 255);"&gt;if&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;File.&lt;span style="color: rgb(0, 0, 0);"&gt;Exists&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"customers.xml"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;          ReadFile&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(6, 0, 255);"&gt;else&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;          MakeFile&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(6, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;void&lt;/span&gt; Main&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;       CustomerDatabase db = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; CustomerDatabase&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       db.&lt;span style="color: rgb(0, 0, 0);"&gt;Test&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;Listing 15.1 defines the Customers table to have the structure shown below. &lt;/p&gt; &lt;blockquote&gt; &lt;a name="Table_15.4_.E2.80.93_The_Customers_Table"&gt;&lt;/a&gt;&lt;h3&gt;Table 15.4 – The Customers Table&lt;/h3&gt; &lt;table style="border-style: solid; border-width: 2px;"&gt;  &lt;tbody&gt;&lt;tr bgcolor="#e0e0e0"&gt; &lt;td&gt; &lt;b&gt;Field Name&lt;/b&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;b&gt;Data Type&lt;/b&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;CustID&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;code&gt;int, auto increment, primary key&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;Name&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;code&gt;string&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;Phone&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;code&gt;string&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;Email&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;code&gt;string&lt;/code&gt; &lt;/td&gt;&lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt; &lt;/blockquote&gt; &lt;p&gt;To define the table, we create a &lt;code&gt;DataTable&lt;/code&gt; object and set its &lt;code&gt;TableName&lt;/code&gt; property to &lt;code&gt;"Customers"&lt;/code&gt;. The &lt;code&gt;DataTable&lt;/code&gt; has a property named &lt;code&gt;Columns&lt;/code&gt;, which is a collection of &lt;code&gt;DataColumn&lt;/code&gt; objects that define the columns of the table. Another important property of the &lt;code&gt;DataTable&lt;/code&gt; is the &lt;code&gt;PrimaryKey&lt;/code&gt; property. The &lt;code&gt;PrimaryKey&lt;/code&gt; property is an array of &lt;code&gt;DataColumn&lt;/code&gt; objects. You can set the primary key by creating an array of one or more &lt;code&gt;DataColumns&lt;/code&gt; from the table and assigning a reference to that array in the &lt;code&gt;PrimaryKey&lt;/code&gt; property. &lt;/p&gt;&lt;p&gt;The &lt;code&gt;DataColumn&lt;/code&gt; class has many properties, many of which you won’t care about for the examples here. However, two important properties are the &lt;code&gt;Name&lt;/code&gt; and &lt;code&gt;DataType&lt;/code&gt;.  &lt;/p&gt;&lt;p&gt;The &lt;code&gt;Name&lt;/code&gt; property is a string value that names the field. When you access a column of a &lt;code&gt;DataRow&lt;/code&gt; you can use this name as an index instead of an integer; so, you don’t have to remember the order of the columns.  &lt;/p&gt;&lt;p&gt;The &lt;code&gt;DataType&lt;/code&gt; property stores an instance of the &lt;code&gt;Type&lt;/code&gt; class containing the type of data the column will store. The data are stored in the fields as object references so you can use any C# data type. If the &lt;code&gt;DataType&lt;/code&gt; of a column is &lt;code&gt;int&lt;/code&gt;, then you can set the column’s &lt;code&gt;AutoIncrement&lt;/code&gt; property to &lt;code&gt;true&lt;/code&gt;. If the &lt;code&gt;AutoIncrement&lt;/code&gt; property is &lt;code&gt;true&lt;/code&gt;, then the column’s value will be set automatically from a counter variable that is incremented every time a new row is created. This guarantees that the field will hold a unique value for each row in the table and makes the field a good candidate to use as a primary key. &lt;/p&gt;&lt;h2&gt; Defining the Table Structure &lt;/h2&gt; &lt;p&gt;The following code segment defines the &lt;code&gt;Customer&lt;/code&gt; table structure. The &lt;code&gt;CustID&lt;/code&gt; field is defined as an &lt;code&gt;auto counter&lt;/code&gt; field and used as the primary key. &lt;/p&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataTable&lt;/span&gt; custTable = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataTable&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;TableName&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"Customers"&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// this will be the primary key&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataColumn&lt;/span&gt; custId =     &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataColumn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"CustID"&lt;/span&gt;, &lt;span style="color: rgb(6, 0, 255);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;int&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;; custId.&lt;span style="color: rgb(0, 0, 0);"&gt;AutoIncrement&lt;/span&gt; = &lt;span style="color: rgb(6, 0, 255);"&gt;true&lt;/span&gt;;&lt;br /&gt;custId.&lt;span style="color: rgb(0, 0, 0);"&gt;AutoIncrementSeed&lt;/span&gt; = &lt;span style="color: rgb(255, 0, 0);"&gt;101&lt;/span&gt;;&lt;br /&gt;custId.&lt;span style="color: rgb(0, 0, 0);"&gt;AutoIncrementStep&lt;/span&gt; = &lt;span style="color: rgb(255, 0, 0);"&gt;1&lt;/span&gt;; &lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;Columns&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;custId&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// make this the primary key&lt;/span&gt;&lt;br /&gt;custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;PrimaryKey&lt;/span&gt; = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataColumn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt; custId &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// add some fields for customer data&lt;/span&gt; custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;Columns&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;DataColumn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Name"&lt;/span&gt;, &lt;span style="color: rgb(6, 0, 255);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;Columns&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataColumn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Phone"&lt;/span&gt;, &lt;span style="color: rgb(6, 0, 255);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;; custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;Columns&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataColumn&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Email"&lt;/span&gt;, &lt;span style="color: rgb(6, 0, 255);"&gt;typeof&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;span class="plainlinks"&gt;&lt;a href="http://en.csharp-online.net/Working_with_Data%E2%80%94Roll_Your_Own_Database" title="http://en.csharp-online.net/Working_with_Data%E2%80%94Roll_Your_Own_Database" rel="nofollow"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;h2&gt; Reading Rows of Data &lt;/h2&gt; &lt;p&gt;The &lt;code&gt;DataTable&lt;/code&gt; also has a property named &lt;code&gt;Rows&lt;/code&gt; that stores the rows of data. The rows are actually objects of the &lt;code&gt;DataRow&lt;/code&gt; class. The &lt;code&gt;DataRow&lt;/code&gt; stores a collection of values that you can read or write to using an index. You can either use an integer—if you know the order of the columns—or you can use the name of the field. The following code segment loops through the table’s rows and obtains references to the &lt;code&gt;Name&lt;/code&gt;, &lt;code&gt;Phone&lt;/code&gt;, and &lt;code&gt;Email&lt;/code&gt; fields. &lt;/p&gt; &lt;pre class="csharp"&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;foreach&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;DataRow&lt;/span&gt; row &lt;span style="color: rgb(6, 0, 255);"&gt;in&lt;/span&gt; ds.&lt;span style="color: rgb(0, 0, 0);"&gt;Tables&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Rows&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// get the data&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt; name = &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Name"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;;&lt;br /&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt; phone = &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Phone"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;;&lt;br /&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt; email = &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Email"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;The &lt;code&gt;DataRow&lt;/code&gt; stores the values as object references so the data must be cast to the appropriate type before we can use it. In this case, we used strings. &lt;/p&gt;&lt;h2&gt; Adding Rows of Data &lt;/h2&gt; &lt;p&gt;We obviously need to add new rows to the table, too. To create a &lt;code&gt;DataRow&lt;/code&gt; object, we call the &lt;code&gt;Table&lt;/code&gt;’s &lt;code&gt;NewRow&lt;/code&gt; method. That method will instantiate a &lt;code&gt;DataRow&lt;/code&gt; object and set its auto increment field for the primary key. Then, we can set the other values of the record and add the row into the &lt;code&gt;Table&lt;/code&gt;’s &lt;code&gt;Rows&lt;/code&gt; collection. &lt;/p&gt; &lt;pre class="csharp"&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;DataRow&lt;/span&gt; row  = custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;NewRow&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Name"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;  = &lt;span style="color: rgb(163, 21, 21);"&gt;"Evy"&lt;/span&gt;;&lt;br /&gt;row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Phone"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"123-555-9876"&lt;/span&gt;;&lt;br /&gt;row&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Email"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"evy@evymail.com"&lt;/span&gt;;&lt;br /&gt;custTable.&lt;span style="color: rgb(0, 0, 0);"&gt;Rows&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;row&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;/pre&gt;&lt;span class="plainlinks"&gt;&lt;a href="http://en.csharp-online.net/Working_with_Data%E2%80%94Reading_Rows_of_Data" title="http://en.csharp-online.net/Working_with_Data%E2%80%94Reading_Rows_of_Data" rel="nofollow"&gt;&lt;br /&gt;&lt;/a&gt;&lt;/span&gt;&lt;h2&gt; Storing the Data as XML &lt;/h2&gt; &lt;p&gt;The &lt;code&gt;DataSet&lt;/code&gt; stores a collection of &lt;code&gt;DataTable&lt;/code&gt;s in its &lt;code&gt;Tables&lt;/code&gt; property. To dump the entire DataSet to an XML file, we need to call the &lt;code&gt;DataSet&lt;/code&gt;’s &lt;code&gt;WriteXml&lt;/code&gt; method, passing the name of the file as a string. Reading the file back in is just a matter of calling the &lt;code&gt;ReadXml&lt;/code&gt; method. &lt;/p&gt; &lt;pre class="csharp"&gt;ds.&lt;span style="color: rgb(0, 0, 0);"&gt;WriteXml&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"customers.xml"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;   &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// dump to XML&lt;/span&gt;&lt;br /&gt;ds.&lt;span style="color: rgb(0, 0, 0);"&gt;ReadXml&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"customers.xml"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;   &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// restore from XML&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;h2&gt; Filtering the Data with the DataView &lt;/h2&gt; &lt;p&gt;The &lt;code&gt;DataView&lt;/code&gt; class can be used to create a new view of the table that can be filtered or sorted without affecting the underlying table. The &lt;code&gt;DataView&lt;/code&gt; is similar to a table in that it has a collection of rows but the objects in the &lt;code&gt;DataView&lt;/code&gt;’s &lt;code&gt;Rows&lt;/code&gt; collection are of type &lt;code&gt;DataRowView&lt;/code&gt;. You use the &lt;code&gt;DataRowView&lt;/code&gt; the same as you would use a &lt;code&gt;DataRow&lt;/code&gt;. You use the name of the field as an index to get the value from the column. Once you have a &lt;code&gt;DataView&lt;/code&gt;, you can filter or sort the data without affecting the actual table.  &lt;/p&gt;&lt;p&gt;You create a &lt;code&gt;DataView&lt;/code&gt; by passing a &lt;code&gt;DataTable&lt;/code&gt; to the &lt;code&gt;DataView&lt;/code&gt; constructor.  &lt;/p&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// create a view that can be filtered and sorted&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataView&lt;/span&gt; view = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataView&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;ds.&lt;span style="color: rgb(0, 0, 0);"&gt;Tables&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;; &lt;span style="color: rgb(6, 0, 255);"&gt;foreach&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;DataRowView&lt;/span&gt; drv &lt;span style="color: rgb(6, 0, 255);"&gt;in&lt;/span&gt; view&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;    &lt;span style="color: rgb(43, 145, 175);"&gt;Console&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;WriteLine&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;drv&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Name"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;ToString&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;    &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;   &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// find the record for Rick&lt;/span&gt; view.&lt;span style="color: rgb(0, 0, 0);"&gt;RowFilter&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"Name = 'Evy'"&lt;/span&gt;; &lt;span style="color: rgb(6, 0, 255);"&gt;foreach&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;DataRowView&lt;/span&gt; drv &lt;span style="color: rgb(6, 0, 255);"&gt;in&lt;/span&gt; view&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;    &lt;span style="color: rgb(43, 145, 175);"&gt;Console&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;WriteLine&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;drv&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Name"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;ToString&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;    &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt; &lt;p&gt;In the code segment, we create a &lt;code&gt;DataView&lt;/code&gt; for the first &lt;code&gt;DataTable&lt;/code&gt; in the &lt;code&gt;DataSet&lt;/code&gt;’s &lt;code&gt;Tables&lt;/code&gt; collection. Then, we loop through the &lt;code&gt;Rows&lt;/code&gt; collection, printing out the &lt;code&gt;Name&lt;/code&gt; field as we go. Then, we filter the view so that view only contains records where the &lt;code&gt;Name&lt;/code&gt; field is &lt;code&gt;"Evy"&lt;/code&gt;. The &lt;code&gt;foreach&lt;/code&gt; loop iterates through each row in the view of &lt;code&gt;"Evy"&lt;/code&gt; records and prints out the &lt;code&gt;Name&lt;/code&gt; field. &lt;/p&gt; &lt;a name="Table_15.5_.E2.80.93_OLEDB_Database_Classes"&gt;&lt;/a&gt;&lt;h3&gt;Table 15.5 – OLEDB Database Classes&lt;/h3&gt; &lt;table style="border-style: solid; border-width: 2px;"&gt;  &lt;tbody&gt;&lt;tr bgcolor="#e0e0e0"&gt; &lt;td&gt; Class &lt;/td&gt;&lt;td&gt; Description &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;OleDbConnection&lt;/code&gt; &lt;/td&gt;&lt;td&gt; The physical database connection &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;OleDbCommand&lt;/code&gt; &lt;/td&gt;&lt;td&gt; A command to execute on the database &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;OleDbDataAdapter&lt;/code&gt; &lt;/td&gt;&lt;td&gt; Moves data between the DataSet and the physical Database using a connection and a command &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;OleDbDataReader&lt;/code&gt; &lt;/td&gt;&lt;td&gt; Can iterate results returned from a command &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;Now that you have been introduced to the ADO.NET classes, it is time to write some real code. The example in the next section connects to the Microsoft Access Northwind Traders database using the OleDb classes.&lt;br /&gt;&lt;/p&gt;&lt;h2&gt; Connecting to Access using OLE DB &lt;/h2&gt; &lt;p&gt;In this section, we will use the Northwind Trader database that installs (optionally) with Microsoft Access. The program is a Console Application that simply loads a &lt;code&gt;DataSet&lt;/code&gt; from the &lt;code&gt;Customers&lt;/code&gt; table of the database. Then, we loop through the records, printing the &lt;code&gt;CustomerName&lt;/code&gt; field to the screen. &lt;/p&gt;&lt;p&gt;&lt;b&gt;Listing 15.2&lt;/b&gt; &lt;/p&gt; &lt;pre class="csharp"&gt;&lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// Example15_2.cs&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;using&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;System&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;using&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;System&lt;/span&gt;.&lt;span style="color: rgb(43, 145, 175);"&gt;Data&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;using&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;System&lt;/span&gt;.&lt;span style="color: rgb(43, 145, 175);"&gt;Data&lt;/span&gt;.&lt;span style="color: rgb(43, 145, 175);"&gt;OleDb&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;namespace&lt;/span&gt; csbook.&lt;span style="color: rgb(0, 0, 0);"&gt;ch15&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;class&lt;/span&gt; Example15_2 &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: rgb(6, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;void&lt;/span&gt; Main&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt; conString =&lt;br /&gt;            &lt;span style="color: rgb(163, 21, 21);"&gt;@"Provider=Microsoft.JET.OLEDB.4.0;"&lt;/span&gt;&lt;br /&gt;          + &lt;span style="color: rgb(163, 21, 21);"&gt;@"data source=c:\data\Northwind.mdb"&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;        &lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// create an open the connection          &lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(43, 145, 175);"&gt;OleDbConnection&lt;/span&gt; conn = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;OleDbConnection&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;conString&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       conn.&lt;span style="color: rgb(0, 0, 0);"&gt;Open&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// create the DataSet&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(43, 145, 175);"&gt;DataSet&lt;/span&gt; ds = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataSet&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// create the adapter and fill the DataSet&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(43, 145, 175);"&gt;OleDbDataAdapter&lt;/span&gt; adapter =&lt;br /&gt;          &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;OleDbDataAdapter&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Select * from Customers"&lt;/span&gt;, conn&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       adapter.&lt;span style="color: rgb(0, 0, 0);"&gt;Fill&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;ds&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// close the connection&lt;/span&gt;&lt;br /&gt;       conn.&lt;span style="color: rgb(0, 0, 0);"&gt;Close&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(43, 145, 175);"&gt;DataTable&lt;/span&gt; dt = ds.&lt;span style="color: rgb(0, 0, 0);"&gt;Tables&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(6, 0, 255);"&gt;foreach&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(43, 145, 175);"&gt;DataRow&lt;/span&gt; dr &lt;span style="color: rgb(6, 0, 255);"&gt;in&lt;/span&gt; dt.&lt;span style="color: rgb(0, 0, 0);"&gt;Rows&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(43, 145, 175);"&gt;Console&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;WriteLine&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;dr&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"CompanyName"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;ToString&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;The listing first creates a connection string that provides information to the &lt;code&gt;OleDbConnection&lt;/code&gt; class. Specifically, the connection string contains the provider for the database engine that we want to connect to and the data source, which in this case is a Microsoft Access file. If the file were password protected, we would also specify a User ID and Password in the connection string. After creating the connection string, the program creates an &lt;code&gt;OleDbConnection&lt;/code&gt; object, passing the connection string as the argument. &lt;/p&gt;&lt;p&gt;Next, the listing opens the database connection by calling the connection’s &lt;code&gt;Open&lt;/code&gt; method. It also creates an empty &lt;code&gt;DataSet&lt;/code&gt; that will later be filled from the database.  &lt;/p&gt;&lt;p&gt;The &lt;code&gt;OleDbAdapter&lt;/code&gt; class encapsulates the command to fill the &lt;code&gt;DataSet&lt;/code&gt;. We create the adapter by passing a SQL query string and the database connection to its constructor. This query string will select all fields of all rows from the &lt;code&gt;Customers&lt;/code&gt; table. The adapter’s &lt;code&gt;Fill&lt;/code&gt; method will execute the query through the connection and load the results into the &lt;code&gt;DataSet&lt;/code&gt; that we pass to it. The results include the data from the query as well as the metadata, defining its structure. When the call is complete, the &lt;code&gt;DataSet&lt;/code&gt; will contain a table with all the &lt;code&gt;Customer&lt;/code&gt; records from the database. At that point, we can close the database connection so that it can be used by some other application. &lt;/p&gt;&lt;p&gt;The tables within the &lt;code&gt;DataSet&lt;/code&gt; are represented by the &lt;code&gt;DataTable&lt;/code&gt; class. Each &lt;code&gt;DataTable&lt;/code&gt; has a collection of &lt;code&gt;DataRow&lt;/code&gt; objects storing the rows from the query. The &lt;code&gt;foreach&lt;/code&gt; loop iterates through the &lt;code&gt;DataRow&lt;/code&gt;s, displaying the &lt;code&gt;CompanyName&lt;/code&gt; field. The &lt;code&gt;DataRow&lt;/code&gt; object uses the string &lt;code&gt;"CompanyName"&lt;/code&gt; as an index to find the field of that name and retrieve its value. The value is returned as an &lt;code&gt;object&lt;/code&gt; type. Calling the virtual &lt;code&gt;ToString&lt;/code&gt; method will result in displaying the string value of the field. &lt;/p&gt;&lt;h2&gt; Connecting to a SQL Server Database &lt;/h2&gt; &lt;p&gt;The SQL Server versions of the connection, command, and adapter classes are listed below in Table 15.6. They are defined in the &lt;code&gt;System.Data.SqlClient&lt;/code&gt; namespace. &lt;/p&gt; &lt;a name="Table_15.6_.E2.80.93_SQL_Server_Database_Classes"&gt;&lt;/a&gt;&lt;h3&gt;Table 15.6 – SQL Server Database Classes&lt;/h3&gt; &lt;table style="border-style: solid; border-width: 2px;"&gt;  &lt;tbody&gt;&lt;tr bgcolor="#e0e0e0"&gt; &lt;td&gt; &lt;b&gt;Class&lt;/b&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; &lt;b&gt;Description&lt;/b&gt; &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;SqlConnection&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; The physical database connection &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;SqlDataCommand&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; A command to execute on the database &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;SqlDataAdapter&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; Moves data between the DataSet and the physical Database using a connection and a command &lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;code&gt;SqlDataReader&lt;/code&gt; &lt;/td&gt;&lt;td&gt;  &lt;br /&gt;&lt;/td&gt;&lt;td&gt; Can iterate results returned from a command &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt; &lt;p&gt;SQL Server also installs a copy of the Northwind Trader database. The next example is similar to the previous except that it uses the SQL Server versions of the connection and adapter. &lt;/p&gt;&lt;p&gt;While the previous listing used an adapter to execute a command internally and fill a &lt;code&gt;DataSet&lt;/code&gt;, this example uses the command object directly. The program calls the &lt;code&gt;SqlCommand&lt;/code&gt; object’s &lt;code&gt;ExecuteReader&lt;/code&gt; method, which returns a &lt;code&gt;SqlReader&lt;/code&gt; object. Then, it uses the &lt;code&gt;SqlReader&lt;/code&gt; to loop through the records that have been returned. &lt;/p&gt; &lt;a name="Listing_15.3"&gt;&lt;/a&gt;&lt;h3&gt;Listing 15.3&lt;/h3&gt; &lt;pre class="csharp"&gt;&lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// Example15_3.cs&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;using&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;System&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;using&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;System&lt;/span&gt;.&lt;span style="color: rgb(43, 145, 175);"&gt;Data&lt;/span&gt;;&lt;br /&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;using&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;System&lt;/span&gt;.&lt;span style="color: rgb(43, 145, 175);"&gt;Data&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;SqlClient&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;namespace&lt;/span&gt; csbook.&lt;span style="color: rgb(0, 0, 0);"&gt;ch15&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;class&lt;/span&gt; Example15_3 &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(6, 0, 255);"&gt;static&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;void&lt;/span&gt; Main&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; args&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// create an open the connection&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(43, 145, 175);"&gt;SqlConnection&lt;/span&gt; conn =&lt;br /&gt;          &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;SqlConnection&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Data Source=DESKTOP;"&lt;/span&gt;&lt;br /&gt;             + &lt;span style="color: rgb(163, 21, 21);"&gt;"Initial Catalog=Northwind;"&lt;/span&gt;&lt;br /&gt;             + &lt;span style="color: rgb(163, 21, 21);"&gt;"Persist Security Info=True;"&lt;/span&gt;&lt;br /&gt;             + &lt;span style="color: rgb(163, 21, 21);"&gt;"User ID=jeff;Password=password"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       conn.&lt;span style="color: rgb(0, 0, 0);"&gt;Open&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// create a SqlCommand object for this connection&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(43, 145, 175);"&gt;SqlCommand&lt;/span&gt; command = conn.&lt;span style="color: rgb(0, 0, 0);"&gt;CreateCommand&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       command.&lt;span style="color: rgb(0, 0, 0);"&gt;CommandText&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"Select * from Customers"&lt;/span&gt;;&lt;br /&gt;       command.&lt;span style="color: rgb(0, 0, 0);"&gt;CommandType&lt;/span&gt; = CommandType.&lt;span style="color: rgb(43, 145, 175);"&gt;Text&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// execute the command that returns a SqlDataReader&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(43, 145, 175);"&gt;SqlDataReader&lt;/span&gt; reader = command.&lt;span style="color: rgb(0, 0, 0);"&gt;ExecuteReader&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// display the results&lt;/span&gt;&lt;br /&gt;       &lt;span style="color: rgb(6, 0, 255);"&gt;while&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;reader.&lt;span style="color: rgb(0, 0, 0);"&gt;Read&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt;          &lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt; output = reader&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"CompanyName"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;ToString&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: rgb(43, 145, 175);"&gt;Console&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;WriteLine&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;output&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;          &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;       &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// close the connection&lt;/span&gt;&lt;br /&gt;       reader.&lt;span style="color: rgb(0, 0, 0);"&gt;Close&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       conn.&lt;span style="color: rgb(0, 0, 0);"&gt;Close&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;       &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt;    &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;h2&gt; Data Binding &lt;/h2&gt; &lt;p&gt;Window controls have the ability to bind their properties to the properties of other objects. When two properties are bound, a change in one is reflected in the other. &lt;/p&gt;&lt;p&gt;For example, consider the following listing for the &lt;code&gt;Student&lt;/code&gt; class. The &lt;code&gt;Student&lt;/code&gt; has two properties—the string value &lt;code&gt;Name&lt;/code&gt; and the double value &lt;code&gt;Gpa&lt;/code&gt;.  &lt;/p&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;class&lt;/span&gt; Student &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;    &lt;span style="color: rgb(6, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt; name;    &lt;span style="color: rgb(6, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;double&lt;/span&gt; gpa;      &lt;span style="color: rgb(6, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt; Name &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;       get &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;return&lt;/span&gt; name; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;       set &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt; name = value; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;      &lt;span style="color: rgb(6, 0, 255);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;double&lt;/span&gt; Gpa &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;       get &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;return&lt;/span&gt; gpa; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;       set &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt; gpa = value; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;       &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;    &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt; &lt;p&gt;If we declare an instance of the &lt;code&gt;Student&lt;/code&gt; as a member of a Windows &lt;code&gt;Form&lt;/code&gt;, we can bind the &lt;code&gt;Name&lt;/code&gt; and &lt;code&gt;Gpa&lt;/code&gt; properties to the &lt;code&gt;Text&lt;/code&gt; properties of a pair of &lt;code&gt;TextBox&lt;/code&gt;es.  &lt;/p&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// create the student&lt;/span&gt; student = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; Student&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;; student.&lt;span style="color: rgb(0, 0, 0);"&gt;Name&lt;/span&gt; = &lt;span style="color: rgb(163, 21, 21);"&gt;"Jeff"&lt;/span&gt;; student.&lt;span style="color: rgb(0, 0, 0);"&gt;Gpa&lt;/span&gt; = &lt;span style="color: rgb(255, 0, 0);"&gt;4.0&lt;/span&gt;;   &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// bind the properties&lt;/span&gt; textBox1.&lt;span style="color: rgb(0, 0, 0);"&gt;DataBindings&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; Binding&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Text"&lt;/span&gt;, student, &lt;span style="color: rgb(163, 21, 21);"&gt;"Name"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;; textBox2.&lt;span style="color: rgb(0, 0, 0);"&gt;DataBindings&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Add&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; Binding&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Text"&lt;/span&gt;, student, &lt;span style="color: rgb(163, 21, 21);"&gt;"Gpa"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;; &lt;p&gt;We can also put a &lt;code&gt;Button&lt;/code&gt; on the &lt;code&gt;Form&lt;/code&gt; that displays the current values of the student’s &lt;code&gt;Name&lt;/code&gt; and &lt;code&gt;Gpa&lt;/code&gt;. This allows us to view the changes made to the object after we change the text in the &lt;code&gt;TextBox&lt;/code&gt;. &lt;/p&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;void&lt;/span&gt; testButton_Click&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt; e&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;    &lt;span style="color: rgb(43, 145, 175);"&gt;MessageBox&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Show&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"Name: "&lt;/span&gt; + student.&lt;span style="color: rgb(0, 0, 0);"&gt;Name&lt;/span&gt;        + &lt;span style="color: rgb(163, 21, 21);"&gt;" GPA: "&lt;/span&gt; + student.&lt;span style="color: rgb(0, 0, 0);"&gt;Gpa&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;    &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt; &lt;p&gt;Running the example, we can see that when the form first opens the initial values are displayed. &lt;/p&gt; &lt;blockquote&gt; &lt;a name="Figure_15.2"&gt;&lt;/a&gt;&lt;h3&gt;Figure 15.2&lt;/h3&gt; &lt;p&gt;&lt;a href="http://en.csharp-online.net/Image:Figure15_2.jpg" class="image" title="Image:Figure15_2.jpg"&gt;&lt;img src="http://en.csharp-online.net/images/c/c9/Figure15_2.jpg" alt="Image:Figure15_2.jpg" longdesc="/Image:Figure15_2.jpg" width="262" height="167" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;Then, we can change the text in the text boxes and click the &lt;code&gt;Test Button&lt;/code&gt;. The message box displays the values of the student object, which have been changed to the new values in the &lt;code&gt;TextBox&lt;/code&gt;es. &lt;/p&gt; &lt;/blockquote&gt; &lt;blockquote&gt; &lt;a name="Figure_15.3"&gt;&lt;/a&gt;&lt;h3&gt;Figure 15.3&lt;/h3&gt; &lt;p&gt;&lt;a href="http://en.csharp-online.net/Image:Figure15_3.jpg" class="image" title="Image:Figure15_3.jpg"&gt;&lt;img src="http://en.csharp-online.net/images/c/c6/Figure15_3.jpg" alt="Image:Figure15_3.jpg" longdesc="/Image:Figure15_3.jpg" width="265" height="180" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt; &lt;p&gt;This type of data binding is called &lt;i&gt;simple data binding&lt;/i&gt;. We can also bind a &lt;code&gt;ListBox&lt;/code&gt; control to an array or collection of data. Binding to a collection of data is called &lt;i&gt;complex data binding&lt;/i&gt;. To bind the &lt;code&gt;ListBox&lt;/code&gt; to a collection you set the &lt;code&gt;ListBox&lt;/code&gt;’s &lt;code&gt;DataSource&lt;/code&gt; property. The &lt;code&gt;ListBox&lt;/code&gt; will display the first public property of each item in the collection in its list. The next example binds an array of strings to a &lt;code&gt;ListBox&lt;/code&gt;. &lt;/p&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;public&lt;/span&gt; partial &lt;span style="color: rgb(6, 0, 255);"&gt;class&lt;/span&gt; Form1 : &lt;span style="color: rgb(43, 145, 175);"&gt;Form&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;    &lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt; names = &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt; &lt;span style="color: rgb(163, 21, 21);"&gt;"Jeff"&lt;/span&gt;, &lt;span style="color: rgb(163, 21, 21);"&gt;"Rachel"&lt;/span&gt;, &lt;span style="color: rgb(163, 21, 21);"&gt;"Katy"&lt;/span&gt;, &lt;span style="color: rgb(163, 21, 21);"&gt;"Evy"&lt;/span&gt;, &lt;span style="color: rgb(163, 21, 21);"&gt;"Ben"&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;;      &lt;span style="color: rgb(6, 0, 255);"&gt;public&lt;/span&gt; Form1&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;       InitializeComponent&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;       &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;      &lt;span style="color: rgb(6, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;void&lt;/span&gt; Form1_Load&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt; e&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;       listBox1.&lt;span style="color: rgb(0, 0, 0);"&gt;DataSource&lt;/span&gt; = names;       &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;    &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt; &lt;p&gt;When the form is displayed, the names in the string array appear in the &lt;code&gt;ListBox&lt;/code&gt;. &lt;/p&gt; &lt;blockquote&gt; &lt;a name="Figure_15.4"&gt;&lt;/a&gt;&lt;h3&gt;Figure 15.4&lt;/h3&gt; &lt;p&gt;&lt;a href="http://en.csharp-online.net/Image:Figure15_4.jpg" class="image" title="Image:Figure15_4.jpg"&gt;&lt;img src="http://en.csharp-online.net/images/b/b4/Figure15_4.jpg" alt="Image:Figure15_4.jpg" longdesc="/Image:Figure15_4.jpg" width="183" height="188" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt; &lt;p&gt;&lt;br /&gt;&lt;/p&gt;     &lt;a href="http://en.csharp-online.net/Working_with_Data%E2%80%94Connecting_to_a_SQL_Server_Database" title="http://en.csharp-online.net/Working_with_Data%E2%80%94Connecting_to_a_SQL_Server_Database" rel="nofollow"&gt;&lt;br /&gt;&lt;/a&gt;&lt;h2&gt; Using the &lt;code&gt;DataGridView&lt;/code&gt;&lt;/h2&gt; &lt;p&gt;The &lt;code&gt;DataGridView&lt;/code&gt; is a control designed to be bound to database tables. You will find the &lt;code&gt;DataGridView&lt;/code&gt; in the Data group on your Toolbox. In this section, we will use the &lt;code&gt;DataGridView&lt;/code&gt; to build a SQL interface for the Northwind Trader database. This application is surprisingly simple using the classes provided by ADO.NET. &lt;/p&gt; &lt;a name="Figure_15.5"&gt;&lt;/a&gt;&lt;h3&gt;Figure 15.5&lt;/h3&gt; &lt;p&gt;&lt;a href="http://en.csharp-online.net/Image:Figure15_5.jpg" class="image" title="Image:Figure15_5.jpg"&gt;&lt;img src="http://en.csharp-online.net/images/9/9a/Figure15_5.jpg" alt="Image:Figure15_5.jpg" longdesc="/Image:Figure15_5.jpg" width="452" height="204" /&gt;&lt;/a&gt; &lt;/p&gt;&lt;p&gt;To create the user interface, place a &lt;code&gt;TextBox&lt;/code&gt; on the form and set its &lt;code&gt;Multiline&lt;/code&gt; property to &lt;code&gt;true&lt;/code&gt;. Then, add two buttons, setting their &lt;code&gt;Text&lt;/code&gt; properties to &lt;code&gt;Query&lt;/code&gt; and &lt;code&gt;Update&lt;/code&gt;. Finally, place a &lt;code&gt;DataGridView&lt;/code&gt; component on the form. Your form might look something like the one in Figure 15.5. &lt;/p&gt;&lt;p&gt;Since we are going to connect to a Microsoft Access database, we need to use the &lt;code&gt;OleDb&lt;/code&gt; classes. At the top of the file, you should add the following &lt;code&gt;using&lt;/code&gt; statement to gain access to the &lt;code&gt;System.Data.OleDb&lt;/code&gt; namespace. &lt;/p&gt; &lt;pre class="csharp"&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;using&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;System&lt;/span&gt;.&lt;span style="color: rgb(43, 145, 175);"&gt;Data&lt;/span&gt;.&lt;span style="color: rgb(43, 145, 175);"&gt;OleDb&lt;/span&gt;;&lt;/pre&gt; &lt;p&gt;The &lt;code&gt;Form&lt;/code&gt;’s &lt;code&gt;Load&lt;/code&gt; event should create an &lt;code&gt;OleDbConnection&lt;/code&gt; object, an &lt;code&gt;OleDbCommand&lt;/code&gt; object, and a &lt;code&gt;DataSet&lt;/code&gt; object. Each of these objects should be stored as members of your &lt;code&gt;Form&lt;/code&gt; class. &lt;/p&gt; &lt;pre class="csharp"&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;void&lt;/span&gt; Form1_Load&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt; e&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// connect to the database&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;string&lt;/span&gt; conString =&lt;br /&gt;    &lt;span style="color: rgb(163, 21, 21);"&gt;@"Provider=Microsoft.JET.OLEDB.4.0;"&lt;/span&gt;&lt;br /&gt;    + &lt;span style="color: rgb(163, 21, 21);"&gt;@"data source=c:\data\Northwind.mdb"&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// create an open the connection          &lt;/span&gt;&lt;br /&gt; conn = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;OleDbConnection&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;conString&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt; command = conn.&lt;span style="color: rgb(0, 0, 0);"&gt;CreateCommand&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// create the DataSet&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataSet&lt;/span&gt; ds = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataSet&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;Next, you need to implement the select button’s &lt;code&gt;Click&lt;/code&gt; handler. The method should start by clearing the &lt;code&gt;DataSource&lt;/code&gt; property of the &lt;code&gt;DataViewGrid&lt;/code&gt; and creating a fresh &lt;code&gt;DataSet&lt;/code&gt;. Then, it should reopen the connection. Set the &lt;code&gt;Command&lt;/code&gt; object’s &lt;code&gt;CommandText&lt;/code&gt; property to the &lt;code&gt;Text&lt;/code&gt; from the &lt;code&gt;TextBox&lt;/code&gt; control. Then, create an adapter with the command and fill the new &lt;code&gt;DataSet&lt;/code&gt;. Finally, set the &lt;code&gt;DataGridView&lt;/code&gt;’s &lt;code&gt;DataSource&lt;/code&gt; property to the first table in the &lt;code&gt;DataSet&lt;/code&gt;’s &lt;code&gt;Table&lt;/code&gt; collection. &lt;/p&gt; &lt;pre class="csharp"&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;void&lt;/span&gt; button1_Click&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt; e&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// clear the grids data source&lt;/span&gt;&lt;br /&gt; dataGridView1.&lt;span style="color: rgb(0, 0, 0);"&gt;DataSource&lt;/span&gt; = &lt;span style="color: rgb(6, 0, 255);"&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// create a new DataSet&lt;/span&gt;&lt;br /&gt; ds = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;DataSet&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// open the connection&lt;/span&gt;&lt;br /&gt; conn.&lt;span style="color: rgb(0, 0, 0);"&gt;Open&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// run the query&lt;/span&gt;&lt;br /&gt; command.&lt;span style="color: rgb(0, 0, 0);"&gt;CommandText&lt;/span&gt; = textBox1.&lt;span style="color: rgb(43, 145, 175);"&gt;Text&lt;/span&gt;;&lt;br /&gt; adapter = &lt;span style="color: rgb(6, 0, 255);"&gt;new&lt;/span&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;OleDbDataAdapter&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;command&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt; adapter.&lt;span style="color: rgb(0, 0, 0);"&gt;Fill&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;ds&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// close the connection&lt;/span&gt;&lt;br /&gt; conn.&lt;span style="color: rgb(0, 0, 0);"&gt;Close&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// set the grid's data source&lt;/span&gt;&lt;br /&gt; dataGridView1.&lt;span style="color: rgb(0, 0, 0);"&gt;DataSource&lt;/span&gt; = ds.&lt;span style="color: rgb(0, 0, 0);"&gt;Tables&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;0&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;The last step is to implement the &lt;code&gt;Click&lt;/code&gt; event handler for the &lt;code&gt;Update&lt;/code&gt; button.  &lt;/p&gt; &lt;pre class="csharp"&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;void&lt;/span&gt; button2_Click&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(6, 0, 255);"&gt;object&lt;/span&gt; sender, &lt;span style="color: rgb(43, 145, 175);"&gt;EventArgs&lt;/span&gt; e&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;{&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// clear the grids data source&lt;/span&gt;&lt;br /&gt; dataGridView1.&lt;span style="color: rgb(0, 0, 0);"&gt;DataSource&lt;/span&gt; = &lt;span style="color: rgb(6, 0, 255);"&gt;null&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// open the connection&lt;/span&gt;&lt;br /&gt; conn.&lt;span style="color: rgb(0, 0, 0);"&gt;Open&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// run the query&lt;/span&gt;&lt;br /&gt; command.&lt;span style="color: rgb(0, 0, 0);"&gt;CommandText&lt;/span&gt; = textBox1.&lt;span style="color: rgb(43, 145, 175);"&gt;Text&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(6, 0, 255);"&gt;int&lt;/span&gt; affected = command.&lt;span style="color: rgb(0, 0, 0);"&gt;ExecuteNonQuery&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt; &lt;span style="color: rgb(43, 145, 175);"&gt;MessageBox&lt;/span&gt;.&lt;span style="color: rgb(0, 0, 0);"&gt;Show&lt;/span&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(163, 21, 21);"&gt;"There were "&lt;/span&gt; + affected + &lt;span style="color: rgb(163, 21, 21);"&gt;" rows affected"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt; &lt;span style="color: rgb(0, 128, 128); font-style: italic;"&gt;// close the connection&lt;/span&gt;&lt;br /&gt; conn.&lt;span style="color: rgb(0, 0, 0);"&gt;Close&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;(&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;)&lt;/span&gt;;&lt;br /&gt; &lt;span style="color: rgb(0, 0, 0);"&gt;}&lt;/span&gt;&lt;/pre&gt; &lt;p&gt;The update button sets the &lt;code&gt;DataGridView&lt;/code&gt;’s &lt;code&gt;DataSource&lt;/code&gt; property to &lt;code&gt;null&lt;/code&gt; to clear the grid. Then, it reopens the connection and sets the command object’s &lt;code&gt;CommandText&lt;/code&gt; property to whatever text is in the &lt;code&gt;TextBox&lt;/code&gt;. This time the command is executed by the &lt;code&gt;ExecuteNonQuery&lt;/code&gt; method. The &lt;code&gt;ExecuteNonQuery&lt;/code&gt; method runs a command that updates or deletes records. It returns the number of rows affected by the command. Finally, the method displays a message box showing the number of rows affected and then closes the connection. Figure 15.6 shows a &lt;code&gt;SELECT&lt;/code&gt; statement being executed on the database. &lt;/p&gt; &lt;blockquote&gt;  &lt;a name="Figure_15.6"&gt;&lt;/a&gt;&lt;h3&gt;Figure 15.6&lt;/h3&gt; &lt;p&gt;&lt;a href="http://en.csharp-online.net/Image:Figure15_6.jpg" class="image" title="Image:Figure15_6.jpg"&gt;&lt;img src="http://en.csharp-online.net/images/3/3b/Figure15_6.jpg" alt="Image:Figure15_6.jpg" longdesc="/Image:Figure15_6.jpg" width="532" height="300" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt; &lt;p&gt;Figure 15.7 shows the update button being used to change the &lt;code&gt;ContactTitle&lt;/code&gt; from &lt;code&gt;Guru&lt;/code&gt; to &lt;code&gt;Fool&lt;/code&gt;. &lt;/p&gt; &lt;blockquote&gt; &lt;a name="Figure_15.7"&gt;&lt;/a&gt;&lt;h3&gt;Figure 15.7&lt;/h3&gt; &lt;p&gt;&lt;a href="http://en.csharp-online.net/Image:Figure15_7.jpg" class="image" title="Image:Figure15_7.jpg"&gt;&lt;img src="http://en.csharp-online.net/images/0/06/Figure15_7.jpg" alt="Image:Figure15_7.jpg" longdesc="/Image:Figure15_7.jpg" width="414" height="234" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt; &lt;p&gt;To verify that our update actually worked, we can run the query again. &lt;/p&gt; &lt;blockquote&gt; &lt;a name="Figure_15.8"&gt;&lt;/a&gt;&lt;h3&gt;Figure 15.8&lt;/h3&gt; &lt;p&gt;&lt;a href="http://en.csharp-online.net/Image:Figure15_8.jpg" class="image" title="Image:Figure15_8.jpg"&gt;&lt;img src="http://en.csharp-online.net/images/f/f2/Figure15_8.jpg" alt="Image:Figure15_8.jpg" longdesc="/Image:Figure15_8.jpg" width="532" height="300" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;/blockquote&gt;&lt;pre class="csharp"&gt;&lt;br /&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;p&gt; &lt;/p&gt;&lt;p&gt; &lt;/p&gt; &lt;/blockquote&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-6007751301807571463?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/6007751301807571463/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/csharp-and-working-with-data.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/6007751301807571463'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/6007751301807571463'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/csharp-and-working-with-data.html' title='CSharp and Working with Data'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-8505422677607987559</id><published>2010-02-16T03:50:00.000-08:00</published><updated>2010-02-16T03:51:32.691-08:00</updated><title type='text'>C# – Static Members</title><content type='html'>&lt;p&gt;&lt;span style="font-size: xx-small;"&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/span&gt;&lt;span class="smallblack"&gt;&lt;/span&gt;&lt;span id="more-146"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;   INTRODUCTION:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;The object oriented programming will give the impression very unnatural to a programmer with a lot of procedural programming experience. In Object Oriented programming Encapsulation is the first pace. Encapsulation is the procedure of covering up of data and functions into a single unit (called class). An encapsulated object is often called an abstract data type. In this article let us see about it in a detailed manner. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;NEED FOR ENCAPSULATION:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;The need of encapsulation is to protect or prevent the code (data) from accidental corruption due to the sillylittle errors that we are all prone to make. In Object oriented programming data is treated as a critical element in the program development and data is packed closely to the functions that operate on it and protects it from accidental modification from outside functions.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Encapsulation provides a way to protect data from accidental corruption. Rather than defining the data in the form of public, we can declare those fields as private. The Private data are manipulated indirectly by two ways. Let us see some example programs inC# to demonstrate Encapsulation by those two methods. The first methodis using a pair of conventional accessor and mutator methods. Another one method is using a named property. Whatever be the method our aim is to use the data with out any damage or change.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;ENCAPSULATION USING ACCESSORS AND MUTATORS:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Let us see an example of Department class. Tomanipulate the data in that class (String departname) we define anaccessor (get method) and mutator (set method).&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;using system;&lt;br /&gt;public class Department&lt;br /&gt;{&lt;br /&gt;private string departname;&lt;br /&gt;…….&lt;/span&gt;&lt;/p&gt; &lt;p&gt;// Accessor.&lt;br /&gt;public string GetDepartname()&lt;br /&gt;{&lt;br /&gt;return departname;&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;// Mutator.&lt;br /&gt;public void SetDepartname( string a)&lt;br /&gt;{&lt;br /&gt;departname=a;&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;Like the above way we can protect the privatedata from the outside world. Here we use two separate methods to assignand get the required data.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;public static int Main(string[] args)&lt;br /&gt;{&lt;br /&gt;Department d = new Department();&lt;br /&gt;d.SetDepartname("ELECTRONICS");&lt;br /&gt;Console.WriteLine("The Department is :"+d.GetDepartname());&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;In the above example we can't access theprivate data departname from an object instance. We manipulate the dataonly using those two methods.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;ENCAPSULATION USING PROPERTIES:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Properties are a new language featureintroduced with C#. Only a few languages support this property.Properties in C# helps in protect a field in a class by reading andwriting to it. The first method itself is good but Encapsulation can beaccomplished much smoother with properties.Now let's see an example.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;using system;&lt;br /&gt;public class Department&lt;br /&gt;{&lt;br /&gt;private string departname;&lt;br /&gt;public string Departname&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;return departname;&lt;br /&gt;}&lt;br /&gt;set&lt;br /&gt;{&lt;br /&gt;departname=value;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public class Departmentmain&lt;br /&gt;{&lt;br /&gt;public static int Main(string[] args)&lt;br /&gt;{&lt;br /&gt;Department d= new Department();&lt;br /&gt;d.departname="Communication";&lt;br /&gt;Console.WriteLine("The Department is :{0}",d.Departname);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;From the above example we see the usage ofEncapsulation by using properties. The property has two accessor getand set. The get accessor returns the value of the some property field.The set accessor sets the value of the some property field with thecontents of "value�. Properties can be made read-only. This isaccomplished by having only a get accessor in the propertyimplementation.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;READ ONLY PROPERTY:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;using system;&lt;br /&gt;public class ReadDepartment&lt;br /&gt;{&lt;br /&gt;private string departname;&lt;br /&gt;public ReadDepartment(string avalue)&lt;br /&gt;{&lt;br /&gt;departname=avalue;&lt;br /&gt;}&lt;br /&gt;public string Departname&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;return departname;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public class ReadDepartmain&lt;br /&gt;{&lt;br /&gt;public static int Main(string[] args)&lt;br /&gt;{&lt;br /&gt;ReadDepartment d= new ReadDepartment("COMPUTERSCIENCE");&lt;br /&gt;Console.WriteLine("The Department is: {0}",d.Departname);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;In the above example we see how to implement aread-only property. The class ReadDepartment has a Departname propertythat only implements a get accessor. It leaves out the set accessor.This particular class has a constructor, which accepts a stringparameter. The Main method of the ReadDepartmain class creates a newobject named d. The instantiation of the d object uses the constructorof the ReadDepartment that takes a string parameter. Since the aboveprogram is read-only, we cannot set the value to the field departnameand we only read or get the value of the data from the field.Properties can be made also Write-only. This is accomplished by havingonly a set accessor in the property implementation.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;WRITE ONLY PROPERTY:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;using system;&lt;br /&gt;public class WriteDepartment&lt;br /&gt;{&lt;br /&gt;private string departname;&lt;/span&gt;&lt;/p&gt; &lt;p&gt; public string Departname&lt;br /&gt;{&lt;br /&gt;set&lt;br /&gt;{&lt;br /&gt;departname=value;&lt;br /&gt;Console.WriteLine("The Department is :{0}",departname);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public class WriteDepartmain&lt;br /&gt;{&lt;br /&gt;public static int Main(string[] args)&lt;br /&gt;{&lt;br /&gt;WriteDepartment d= new WriteDepartment();&lt;br /&gt;d.departname="COMPUTERSCIENCE";&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;In the above example we see how to implement aWrite-only property. The class WriteDepartment has now has a Departnameproperty that only implements a set accessor. It leaves out the getaccessor. The set accessor method is varied a little by it prints thevalue of the departname after it is assigned.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Conclusion:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;The Encapsulation is the first footsteptowards the object-oriented programming. This article gives you alittle bit information about Encapsulation. Using accessor and mutatormethods we can make encapsulation. Another one method is using a namedproperty. The benefit of properties is that the users of your objectsare able to manipulate the internal data point using a single nameditem.&lt;/span&gt;&lt;/p&gt; &lt;h2 class="related_post_title"&gt;Related Articles :&lt;/h2&gt;&lt;ul class="related_post"&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/08/explaining-c-abstraction-inheritence-and-polymorphism/" title="Explaining C# Abstraction, Inheritence and Polymorphism"&gt;Explaining C# Abstraction, Inheritence and Polymorphism&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/07/c-class-inheritance/" title="C# Class Inheritance"&gt;C# Class Inheritance&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/03/objects-classes-in-c/" title="Objects &amp;amp; Classes in C#"&gt;Objects &amp;amp; Classes in C#&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/02/is-object-class-the-root-of-all-hierarchies/" title="Is Object Class, the root of all hierarchies?"&gt;Is Object Class, the root of all hierarchies?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/05/c-interface-implementation/" title="C# Interface Implementation"&gt;C# Interface Implementation&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/05/c-inheritence/" title="C# Inheritence"&gt;C# Inheritence&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-8505422677607987559?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/8505422677607987559/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/c-static-members.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/8505422677607987559'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/8505422677607987559'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/c-static-members.html' title='C# – Static Members'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-573675147082987951</id><published>2010-02-16T03:48:00.001-08:00</published><updated>2010-02-16T03:48:54.513-08:00</updated><title type='text'>C# Encapsulation</title><content type='html'>&lt;p&gt;&lt;span class="smallblack"&gt;   INTRODUCTION:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;The object oriented programming will give theimpression very unnatural to a programmer with a lot of proceduralprogramming experience. In Object Oriented programming Encapsulation isthe first pace. Encapsulation is the procedure of covering up of dataand functions into a single unit (called class). An encapsulated objectis often called an abstract data type. In this article let us see aboutit in a detailed manner. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;NEED FOR ENCAPSULATION:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;The need of encapsulation is to protect orprevent the code (data) from accidental corruption due to the sillylittle errors that we are all prone to make. In Object orientedprogramming data is treated as a critical element in the programdevelopment and data is packed closely to the functions that operate onit and protects it from accidental modification from outside functions.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Encapsulation provides a way to protect datafrom accidental corruption. Rather than defining the data in the formof public, we can declare those fields as private. The Private data aremanipulated indirectly by two ways. Let us see some example programs inC# to demonstrate Encapsulation by those two methods. The first methodis using a pair of conventional accessor and mutator methods. Anotherone method is using a named property. Whatever be the method our aim isto use the data with out any damage or change.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;ENCAPSULATION USING ACCESSORS AND MUTATORS:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Let us see an example of Department class. Tomanipulate the data in that class (String departname) we define anaccessor (get method) and mutator (set method).&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;using system;&lt;br /&gt;public class Department&lt;br /&gt;{&lt;br /&gt;private string departname;&lt;br /&gt;…….&lt;/span&gt;&lt;/p&gt; &lt;p&gt;// Accessor.&lt;br /&gt;public string GetDepartname()&lt;br /&gt;{&lt;br /&gt;return departname;&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;// Mutator.&lt;br /&gt;public void SetDepartname( string a)&lt;br /&gt;{&lt;br /&gt;departname=a;&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;Like the above way we can protect the privatedata from the outside world. Here we use two separate methods to assignand get the required data.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;public static int Main(string[] args)&lt;br /&gt;{&lt;br /&gt;Department d = new Department();&lt;br /&gt;d.SetDepartname("ELECTRONICS");&lt;br /&gt;Console.WriteLine("The Department is :"+d.GetDepartname());&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;In the above example we can't access theprivate data departname from an object instance. We manipulate the dataonly using those two methods.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;ENCAPSULATION USING PROPERTIES:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Properties are a new language featureintroduced with C#. Only a few languages support this property.Properties in C# helps in protect a field in a class by reading andwriting to it. The first method itself is good but Encapsulation can beaccomplished much smoother with properties.Now let's see an example.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;using system;&lt;br /&gt;public class Department&lt;br /&gt;{&lt;br /&gt;private string departname;&lt;br /&gt;public string Departname&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;return departname;&lt;br /&gt;}&lt;br /&gt;set&lt;br /&gt;{&lt;br /&gt;departname=value;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public class Departmentmain&lt;br /&gt;{&lt;br /&gt;public static int Main(string[] args)&lt;br /&gt;{&lt;br /&gt;Department d= new Department();&lt;br /&gt;d.departname="Communication";&lt;br /&gt;Console.WriteLine("The Department is :{0}",d.Departname);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;From the above example we see the usage ofEncapsulation by using properties. The property has two accessor getand set. The get accessor returns the value of the some property field.The set accessor sets the value of the some property field with thecontents of "value�. Properties can be made read-only. This isaccomplished by having only a get accessor in the propertyimplementation.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;READ ONLY PROPERTY:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;using system;&lt;br /&gt;public class ReadDepartment&lt;br /&gt;{&lt;br /&gt;private string departname;&lt;br /&gt;public ReadDepartment(string avalue)&lt;br /&gt;{&lt;br /&gt;departname=avalue;&lt;br /&gt;}&lt;br /&gt;public string Departname&lt;br /&gt;{&lt;br /&gt;get&lt;br /&gt;{&lt;br /&gt;return departname;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public class ReadDepartmain&lt;br /&gt;{&lt;br /&gt;public static int Main(string[] args)&lt;br /&gt;{&lt;br /&gt;ReadDepartment d= new ReadDepartment("COMPUTERSCIENCE");&lt;br /&gt;Console.WriteLine("The Department is: {0}",d.Departname);&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;In the above example we see how to implement aread-only property. The class ReadDepartment has a Departname propertythat only implements a get accessor. It leaves out the set accessor.This particular class has a constructor, which accepts a stringparameter. The Main method of the ReadDepartmain class creates a newobject named d. The instantiation of the d object uses the constructorof the ReadDepartment that takes a string parameter. Since the aboveprogram is read-only, we cannot set the value to the field departnameand we only read or get the value of the data from the field.Properties can be made also Write-only. This is accomplished by havingonly a set accessor in the property implementation.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;WRITE ONLY PROPERTY:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;using system;&lt;br /&gt;public class WriteDepartment&lt;br /&gt;{&lt;br /&gt;private string departname;&lt;/span&gt;&lt;/p&gt; &lt;p&gt; public string Departname&lt;br /&gt;{&lt;br /&gt;set&lt;br /&gt;{&lt;br /&gt;departname=value;&lt;br /&gt;Console.WriteLine("The Department is :{0}",departname);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;public class WriteDepartmain&lt;br /&gt;{&lt;br /&gt;public static int Main(string[] args)&lt;br /&gt;{&lt;br /&gt;WriteDepartment d= new WriteDepartment();&lt;br /&gt;d.departname="COMPUTERSCIENCE";&lt;br /&gt;return 0;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;In the above example we see how to implement aWrite-only property. The class WriteDepartment has now has a Departnameproperty that only implements a set accessor. It leaves out the getaccessor. The set accessor method is varied a little by it prints thevalue of the departname after it is assigned.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Conclusion:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;The Encapsulation is the first footsteptowards the object-oriented programming. This article gives you alittle bit information about Encapsulation. Using accessor and mutatormethods we can make encapsulation. Another one method is using a namedproperty. The benefit of properties is that the users of your objectsare able to manipulate the internal data point using a single nameditem.&lt;/span&gt;&lt;/p&gt; &lt;h2 class="related_post_title"&gt;Related Articles :&lt;/h2&gt;&lt;ul class="related_post"&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/08/explaining-c-abstraction-inheritence-and-polymorphism/" title="Explaining C# Abstraction, Inheritence and Polymorphism"&gt;Explaining C# Abstraction, Inheritence and Polymorphism&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/07/c-class-inheritance/" title="C# Class Inheritance"&gt;C# Class Inheritance&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/03/objects-classes-in-c/" title="Objects &amp;amp; Classes in C#"&gt;Objects &amp;amp; Classes in C#&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/02/is-object-class-the-root-of-all-hierarchies/" title="Is Object Class, the root of all hierarchies?"&gt;Is Object Class, the root of all hierarchies?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/05/c-interface-implementation/" title="C# Interface Implementation"&gt;C# Interface Implementation&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/05/c-inheritence/" title="C# Inheritence"&gt;C# Inheritence&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-573675147082987951?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/573675147082987951/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/c-encapsulation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/573675147082987951'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/573675147082987951'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/c-encapsulation.html' title='C# Encapsulation'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-1493465992082742172</id><published>2010-02-16T03:46:00.001-08:00</published><updated>2010-02-16T03:46:45.091-08:00</updated><title type='text'>C# Interface Implementation</title><content type='html'>&lt;p&gt;&lt;span class="smallblack"&gt;Interface implementation can be confusing…&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;I see a feature in C# that can be very confusing. In theexample below we have a class (Test) that implements 2 interfaces(I1 and I2). So the logic says that we should have implementations in the classTest for both MyFunction() methods from I1 and I2. BUT!As you see in the example below everything works fine with only 1 implementation.This is not as correct as we expect, because we can't be sure which of the two interfacesis implemented in the MyFunction method in class Test.So the solution is in another example (EXAMPLE2).In Example2 MyFunction() is implemented in class Test for each interface, by using a different method. (I1.MyFunction() -&gt; for I1, I2.MyFunction() -&gt; for I2).So now everything is clear, isn't it?&lt;/span&gt;&lt;span id="more-167"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;//EXAMPLE 1&lt;br /&gt;using System;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;namespace PavelTsekov&lt;br /&gt;{&lt;br /&gt; interface I1&lt;br /&gt; {&lt;br /&gt;  void MyFunction();&lt;br /&gt; }&lt;br /&gt; interface I2&lt;br /&gt; {&lt;br /&gt;  void MyFunction();&lt;br /&gt; }&lt;br /&gt; class Test : I1,I2&lt;br /&gt; {&lt;br /&gt;  public void MyFunction()&lt;br /&gt;  {&lt;br /&gt;   Console.WriteLine("Guess which interface I represent???!");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; class AppClass&lt;br /&gt; {&lt;br /&gt;  public static void Main(string[] args)&lt;br /&gt;  {&lt;br /&gt;   Test t=new Test();&lt;br /&gt;   I1 i1=(I1)t;&lt;br /&gt;   i1.MyFunction();&lt;br /&gt;   I2 i2=(I2)t;&lt;br /&gt;   i2.MyFunction();&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;//EXAMPLE 2&lt;br /&gt;using System;&lt;/p&gt; &lt;p&gt;namespace PavelTsekov&lt;br /&gt;{&lt;br /&gt; interface I1&lt;br /&gt; {&lt;br /&gt;  void MyFunction();&lt;br /&gt; }&lt;br /&gt; interface I2&lt;br /&gt; {&lt;br /&gt;  void MyFunction();&lt;br /&gt; }&lt;br /&gt; class Test : I1,I2&lt;br /&gt; {&lt;br /&gt;  void I1.MyFunction()&lt;br /&gt;  {&lt;br /&gt;   Console.WriteLine("Now I can say this here is I1 implemented!");&lt;br /&gt;  }&lt;br /&gt;  void I2.MyFunction()&lt;br /&gt;  {&lt;br /&gt;   Console.WriteLine("Now I can say this here is I2 implemented!");&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt; class AppClass&lt;br /&gt; {&lt;br /&gt;  public static void Main(string[] args)&lt;br /&gt;  {&lt;br /&gt;   Test t=new Test();&lt;br /&gt;   I1 i1=(I1)t;&lt;br /&gt;   i1.MyFunction();&lt;br /&gt;   I2 i2=(I2)t;&lt;br /&gt;   i2.MyFunction();&lt;br /&gt;  }&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/p&gt; &lt;h2 class="related_post_title"&gt;Related Articles :&lt;/h2&gt;&lt;ul class="related_post"&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/08/explaining-c-abstraction-inheritence-and-polymorphism/" title="Explaining C# Abstraction, Inheritence and Polymorphism"&gt;Explaining C# Abstraction, Inheritence and Polymorphism&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/07/c-class-inheritance/" title="C# Class Inheritance"&gt;C# Class Inheritance&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/03/objects-classes-in-c/" title="Objects &amp;amp; Classes in C#"&gt;Objects &amp;amp; Classes in C#&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/02/is-object-class-the-root-of-all-hierarchies/" title="Is Object Class, the root of all hierarchies?"&gt;Is Object Class, the root of all hierarchies?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/05/c-inheritence/" title="C# Inheritence"&gt;C# Inheritence&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/04/c-encapsulation/" title="C# Encapsulation"&gt;C# Encapsulation&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-1493465992082742172?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/1493465992082742172/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/c-interface-implementation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/1493465992082742172'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/1493465992082742172'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/c-interface-implementation.html' title='C# Interface Implementation'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-1618245385304103536</id><published>2010-02-16T03:44:00.001-08:00</published><updated>2010-02-16T03:44:25.579-08:00</updated><title type='text'>Is Object Class, the root of all hierarchies?</title><content type='html'>&lt;p&gt;&lt;span class="smallblack"&gt;Introduction&lt;br /&gt;This might come as a surprise for many, to see me doubting theinformation presented in almost .NET books even MSDN library but as wedelve deeper into this topic, you will find yourself in the samepredicament as I am now.&lt;/span&gt;&lt;span id="more-445"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;What is an Object class?&lt;br /&gt;For those who arenew to .NET, according to MSDN library – "Object is the ultimatesuperclass of all classes in the .NET Framework; it is the root of thetype hierarchy."&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;This is the class declaration of the object class&lt;br /&gt;[Serializable]&lt;br /&gt;[ClassInterface(ClassInterfaceType.AutoDual)]&lt;br /&gt;public class object&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;All the classes are required to inherit fromthis Object class but they need not declare inheritance from itexplicitly as it is taken care internally. While all classes inheritfrom it, it doesn't inherit from any super class or interface.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;So what's the problem?&lt;br /&gt;This I will explain with a help of an example.&lt;br /&gt;Let's define a class called Foo&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Class Foo&lt;br /&gt;{&lt;br /&gt;void show() {}&lt;br /&gt;static void main(string[] args)&lt;br /&gt;{&lt;br /&gt;Foo f=new Foo();&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;If you have Visual Studio IDE or any othereditor which supports intellisense, when you type f. you will get thefollowing methods&lt;br /&gt;1. Equals&lt;br /&gt;2. GetHashCode&lt;br /&gt;3. ToString&lt;br /&gt;4. GetType&lt;br /&gt;5. show&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Even though you have defined only one method show since Foo implicitly inherits from Object it gets the other four methods.Let's now define an interface called IFoo and make Foo class inherit from it.&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Interface IFoo&lt;br /&gt;{&lt;br /&gt;void Ishow();&lt;br /&gt;}&lt;br /&gt;class Foo:IFoo&lt;br /&gt;{&lt;br /&gt;void show(){}&lt;br /&gt;void IFoo.Ishow(){}&lt;br /&gt;static void main(string[] args)&lt;br /&gt;{&lt;br /&gt;Foo f=new Foo();&lt;br /&gt;IFoo ifoo=f;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;Since we have inherited from IFoo, we need toimplement the Ishow method. When we type ifoo.show(), we get a compiletime error saying that the interface doesn't contain a definition forshow method. This is correct since an interface is allowed to accessonly methods declared by it even though the object it might bereferring has other methods.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;The problem arises now when we typeifoo.equals(f), ideally this should give a compile time error (notruntime error) it is not declared by IFoo interface or none of itssuper interface but it doesn't. Nor does it give a compile time errorfor using any of the methods of Object class.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;This is definitely a discrepancy from the factthat an interface is allowed to access only methods declared by it. Aninterface for sure can't inherit from a class so how then can weexplain for the four methods of Object which are available to anyinterface. The only possible solution can be that there must be a superinterface like IObject as declared below:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Interface IObject&lt;br /&gt;{&lt;br /&gt;public virtual bool equals(object);&lt;br /&gt;public virtual int getHashCode();&lt;br /&gt;public Type getType();&lt;br /&gt;public virtual string toString();&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;and the Object class must have inherited fromthis interface and also that this IObject must be the super interfaceof all the interfaces just like Object is to other classes.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Conclusion&lt;br /&gt;This is one of the issues whichMicrosoft should clarify so that the programmers can have a betterunderstanding of the language. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Name:C.Prashanth&lt;br /&gt;Email Id:seeprash@hotmail.com&lt;br /&gt;I am a MSc Software Engg student doing my final semester project atIntel Technologies, India. I am a fanatic follower of Indian cricketteam and try not to miss any match even if it means bunking college andoffice. I love reading War novels and listening to A.R.Rahman music.&lt;/span&gt;&lt;/p&gt; &lt;h2 class="related_post_title"&gt;Related Articles :&lt;/h2&gt;&lt;ul class="related_post"&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/08/explaining-c-abstraction-inheritence-and-polymorphism/" title="Explaining C# Abstraction, Inheritence and Polymorphism"&gt;Explaining C# Abstraction, Inheritence and Polymorphism&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/07/c-class-inheritance/" title="C# Class Inheritance"&gt;C# Class Inheritance&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/03/objects-classes-in-c/" title="Objects &amp;amp; Classes in C#"&gt;Objects &amp;amp; Classes in C#&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/05/c-interface-implementation/" title="C# Interface Implementation"&gt;C# Interface Implementation&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/05/c-inheritence/" title="C# Inheritence"&gt;C# Inheritence&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/04/c-encapsulation/" title="C# Encapsulation"&gt;C# Encapsulation&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-1618245385304103536?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/1618245385304103536/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/is-object-class-root-of-all-hierarchies.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/1618245385304103536'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/1618245385304103536'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/is-object-class-root-of-all-hierarchies.html' title='Is Object Class, the root of all hierarchies?'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-6832142026437608332</id><published>2010-02-16T03:43:00.001-08:00</published><updated>2010-02-16T03:48:01.787-08:00</updated><title type='text'>C# Class Inheritance</title><content type='html'>&lt;span class="smallblack"&gt;This Console-based C# code calculates theArea, perimeter, surface area and volume of the following polygons:square, rechtangle, parellelogram, trapezoid, triangle, circle, cube,prism (both rechtangular and triangular base), cylinder, cone, sphere,pyramid and rhombus. All the user does is to input the polygon'sdimensions and the code will produce the polygon's attributes.&lt;br /&gt;&lt;/span&gt;&lt;p&gt;&lt;span class="smallblack"&gt;&lt;a href="http://www.csharphelp.com/archives4/files/archive615/polygons.cs"&gt;polygons.cs&lt;/a&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2 class="related_post_title"&gt;&lt;span class="smallblack"&gt; author : Martin Raphael.K&lt;br /&gt;// email : mrkraj@officetiger.com&lt;br /&gt;// Date : November 02, 2001&lt;span id="more-166"&gt;&lt;/span&gt;&lt;/span&gt; &lt;/h2&gt;&lt;p&gt;// This is the sample code for inheritence&lt;/p&gt; &lt;p&gt;// new is the keyword which is used to override the base(Parent) class&lt;br /&gt;//members base is the keyword whichs is equal to super in java&lt;br /&gt;using System;&lt;br /&gt;public class Base&lt;br /&gt;{&lt;br /&gt; public string str;&lt;br /&gt; public Base()&lt;br /&gt; {&lt;br /&gt;  Console.WriteLine("Base class Constructor");&lt;br /&gt; }&lt;br /&gt; ~Base()&lt;br /&gt; {&lt;br /&gt;  Console.WriteLine("Base class Destructor");&lt;br /&gt; }&lt;br /&gt; public void getData()&lt;br /&gt; {&lt;br /&gt;  Console.WriteLine("Base class GetData");&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;public class Derived:Base&lt;br /&gt;{&lt;br /&gt; public new string str;&lt;/p&gt; &lt;p&gt; public Derived()&lt;br /&gt; {&lt;br /&gt;  Console.WriteLine("Derived class Constructor");&lt;br /&gt; }&lt;br /&gt; ~Derived()&lt;br /&gt; {&lt;br /&gt;  Console.WriteLine("Derived class Destructor");&lt;br /&gt; }&lt;br /&gt; public new void getData()&lt;br /&gt; {&lt;br /&gt;  base.getData();&lt;br /&gt;  Console.WriteLine("Derived class GetData");&lt;br /&gt; }&lt;br /&gt; public void getValues()&lt;br /&gt; {&lt;br /&gt;  base.str=Console.ReadLine();&lt;br /&gt;  this.str=Console.ReadLine();&lt;br /&gt; }&lt;br /&gt; public void printValues()&lt;br /&gt; {&lt;br /&gt;  Console.WriteLine("Base class Str "+base.str);&lt;br /&gt;  Console.WriteLine("Derived class Str "+this.str);&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;class InheritenceDemo&lt;br /&gt;{&lt;br /&gt; public static void Main(string[] a)&lt;br /&gt; {&lt;br /&gt;  Derived d=new Derived();&lt;br /&gt;  d.getData();&lt;br /&gt;  d.getValues();&lt;br /&gt;  d.printValues();&lt;br /&gt;  Console.WriteLine("———–");&lt;br /&gt;  // this is used to get the Base class getData Method&lt;br /&gt;  ((Base)d).getData();&lt;br /&gt; }&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;// send a feedback to mrkraj@officetiger.com&lt;/p&gt;&lt;br /&gt;&lt;h2 class="related_post_title"&gt;Related Articles :&lt;/h2&gt;&lt;ul class="related_post"&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/08/explaining-c-abstraction-inheritence-and-polymorphism/" title="Explaining C# Abstraction, Inheritence and Polymorphism"&gt;Explaining C# Abstraction, Inheritence and Polymorphism&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/03/objects-classes-in-c/" title="Objects &amp;amp; Classes in C#"&gt;Objects &amp;amp; Classes in C#&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/02/is-object-class-the-root-of-all-hierarchies/" title="Is Object Class, the root of all hierarchies?"&gt;Is Object Class, the root of all hierarchies?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/05/c-interface-implementation/" title="C# Interface Implementation"&gt;C# Interface Implementation&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/05/c-inheritence/" title="C# Inheritence"&gt;C# Inheritence&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/04/c-encapsulation/" title="C# Encapsulation"&gt;C# Encapsulation&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-6832142026437608332?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/6832142026437608332/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/c-class-inheritance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/6832142026437608332'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/6832142026437608332'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/c-class-inheritance.html' title='C# Class Inheritance'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-625398779975607504</id><published>2010-02-16T03:41:00.000-08:00</published><updated>2010-02-16T03:42:13.483-08:00</updated><title type='text'>Explaining C# Abstraction, Inheritence and Polymorphism</title><content type='html'>&lt;p&gt;&lt;span class="smallblack"&gt;Far too often, fundamental programming concepts like inheritance and polymorphism are taught using vague examples, like class "AA" and class "BB". Let's get away from that; they're far too abstract to offer a proper explanation. We'll use a workshop as our example instead.&lt;/span&gt;&lt;span id="more-631"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Say you have a program to simulate a workshop, and you want to create a class for each possible tool you can use… hammers, power saws, screwdrivers, etc. Pretty much every tool class you create is going to have common methods, like Use() and PutAway(), regardless of what it actually is. Inheritance allows you to enforce this common ground between tools, and reap some very useful benefits in the process. Take the following "base" class:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;public abstract class Tool()&lt;br /&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p&gt;private double _price;&lt;br /&gt;public double GetPrice()&lt;br /&gt;{&lt;br /&gt;return _price;&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;public abstract void Use();&lt;br /&gt;public abstract void PutAway();&lt;/p&gt; &lt;p&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;This class doesn't do much of anything on it's own, but it provides a common interface for all of the other tools you create.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Every class that inherits from Tool will automatically have a _price, a method called "GetPrice()", and two other methods called Use() and PutAway(). Because we've already written code for GetPrice(), any other Tool class we write can take advantage of it right away.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Use() and PutAway() are a little different. Because we've declared Use() and PutAway() as abstract methods, any class we write that inherits from Tool [i]must[/i] have its own Use() and PutAway() methods. You might ask, "then why bother putting them in the base Tool class in the first place, if you have to rewrite them in all the inherited classes, anyway"? The reason is because these abstract methods [i]guarantee[/i] to our program that any tool it ever deals with will have these methods, 100% certain. We'll see the benefits of this in a minute, but first let's take a quick look at two classes that inherit from Tool (in place of specific code, I'll just add some comments):&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;public class ScrewDriver: Tool&lt;br /&gt;{&lt;/span&gt;&lt;/p&gt; &lt;p&gt;public override void Use()&lt;br /&gt;{&lt;br /&gt;// Insert into screw head and rotate&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;public override void PutAway()&lt;br /&gt;{&lt;br /&gt;// Find correct drawer in toolbench and place inside&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;}&lt;/p&gt; &lt;p&gt;public class PowerSaw: Tool&lt;br /&gt;{&lt;/p&gt; &lt;p&gt;public override void Use()&lt;br /&gt;{&lt;br /&gt;// Flip "on" switch and apply blade to wood surface&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;public override void PutAway()&lt;br /&gt;{&lt;br /&gt;// Flip "off" switch and place on shelf&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;public void ReplaceBatteries()&lt;br /&gt;{&lt;br /&gt;// Remove old batteries, and insert new ones&lt;br /&gt;}&lt;/p&gt; &lt;p&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;Both ScrewDriver and PowerSaw inherit the Use() and PutAway() methods from Tool, but in addition to this they can implement their own unique methods, as well. For example, PowerSaw has a ReplaceBatteries() method, which would be pointless on a screwdriver, but important on a power tool. And that's a critical point: that's why we didn't put a ReplaceBatteries() method in the tool class… because not [i]every[/i] tool needs a ReplaceBatteries() method. Instead, we placed it in the class that would actually need it. Use() and PutAway(), however, are needed by every tool, and so those methods are in the base class.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Note also that, although you can't see it, both ScrewDriver and PowerSaw also have _price and GetPrice(), because they inherited it from "Tool". For example, the following code is, in theory, perfectly legal:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;ScrewDriver myScrewDriver;&lt;br /&gt;myScrewDriver.GetPrice();&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;What about Use() and PutAway()? Those are actually written in ScrewDriver and PowerSaw, so why do we even care that they're included in Tool? For one thing, it guarantees that you won't forget to add those methods to your inherited classes. For another thing, you can do stuff like this:&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;Tool[] myArrayOfTools = new Tool[2];&lt;br /&gt;tool[0] = new ScrewDriver();&lt;br /&gt;tool[1] = new PowerSaw();&lt;/span&gt;&lt;/p&gt; &lt;p&gt;foreach( Tool myTool in myArrayOfTools )&lt;br /&gt;{&lt;br /&gt;myTool.Use();&lt;br /&gt;myTool.PutAway();&lt;br /&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;And that will be perfectly legal, even though element 0 and element 1 in that array are totally different types! One is a ScrewDriver, and one is a PowerSaw, but because they are both tools, we can call their Use() and PutAway() methods regardless of their specific type.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;A few closing points…&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;1) The "abstract" in "public abstract class Tool()" just means that we can't create instances of our Tool class… which is good, because the actual base Tool class doesn't do anything. We don't want people creating copies of it by accident, they should stick to ScrewDrivers and PowerSaws that can actually do stuff.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;2) If we want to write code for Use() in the base class, but still allow it to be overridden by an inheritence class, use "virtual" instead of "abstract":&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;public virtual void Use()&lt;br /&gt;{&lt;br /&gt;// Generic instructions for using a tool&lt;br /&gt;}&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt;Be aware that, although all inherited classes still have access to virtual methods, they are not required to override them.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;3) You don't have to use only one base class. You could create two additional base classes, PowerTool and HandTool that inherit from Tool, and then have your specific tools inherit from either PowerTool or HandTool. PowerTool would have specific methods that all power tools need, and HandTool would have specific methods that all hand tools need. Think of inheritance as a family tree, where in this case, "Tool" is the trunk, "PowerTool" and "HandTool" are both branches, and "ScrewDriver" and "PowerSaw" are twigs.&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;4) For the record, the ability to use all inherited tools as a normal tool (ie, using a ScrewDriver as a Tool), is called "polymorphism".&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt;5) There are also some really neat things called "Interfaces", which you may want to look into once you're comfortable with inheritance.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-625398779975607504?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/625398779975607504/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/explaining-c-abstraction-inheritence.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/625398779975607504'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/625398779975607504'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/explaining-c-abstraction-inheritence.html' title='Explaining C# Abstraction, Inheritence and Polymorphism'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-8014950633432830158</id><published>2010-02-16T03:34:00.001-08:00</published><updated>2010-02-16T03:34:45.104-08:00</updated><title type='text'>Objects &amp; Classes in C#</title><content type='html'>&lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;In this article we will understand some of the concepts of object-oriented programming in C# like objects and classes. To read this article you must have C# programming basics.&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span id="more-479"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: red;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;NOTE: read the whole article because there aresome concepts you may will not get the best of it until you finish the article.And we will revisit all the concepts more than one time when I see it’sappropriate in future articles so don’t worry at all.&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span class="smallblack"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;Introduction:&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;OOP stands for Object-Oriented Programming. OOP isrelatively a new way to program computer applications. Before OOP programmersused to creating computer applications using procedural-programming (orstructure-programming) but when OOP solved a lot of the problems of theprocedural-programming so almost all of the programmers and developers beganusing OOP languages. In procedural- programming all the program functionalitywritten in a few modules of code or maybe one module (depending on the program)and these modules depend on one another and maybe if you change a line of codeyou will have to rewrite the whole module again and maybe the whole program butin Object-Oriented Programming programmers write independent parts of a programcalled classes each class represent a part of the program functionality andthese classes can be assembled to form a program and when you need to changesome of the program functionality all what you have to do is to replace thetarget class which may contain a problem. So in OOP applications create by theuse of classes and these applications can contain any number of classes. Thatwill get us to discuss the Class and Object concept.&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span class="smallblack"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;Classes and objects:&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;You may find it not easy to understand the class and objectstory but I will try to do my best explaining it. Actually the class and objectconcept is related to each other and some beginners don’t care aboutunderstanding it clear so I think they will have a hard times learning C#.&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;Object-Oriented concept takes the most of its functionalityfrom the real-life concepts. For example, I will discuss the concept of Classesand Objects of the world first and then you will understand the computer’sClasses and Objects before I even write anything about it.&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span class="smallblack"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;World’s Classes and Objects:&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;In our world we have a classes and objects for thoseclasses. Everything in our world considered to be an object. For example,people are objects, animals are objects too, minerals are objects, everythingin the world are objects. Easy right ? but what about classes. In our world wehave to differentiate between objects that we are living with. So we mustunderstand that there are &lt;strong&gt;a classifications (this is how they get the nameand the concepts of the Class)&lt;/strong&gt; for all of those objects. For example, I’man object, David is object too, Maria is another object so we are from &lt;strong&gt;apeople class (or type)&lt;/strong&gt;. I have a dog called Ricky so it’s an object, Myfriend’s dog called Doby is also an object so they are from &lt;strong&gt;a Dogs class (ortype)&lt;/strong&gt;. A third example, I have a computer Pentium III this is object, Myfriend have a computer Pentium IIII so this is another object and they are from&lt;strong&gt;a Computers class (or type)&lt;/strong&gt;. Now I think you got the concept of theClass and Object but let me crystallize it for you. In our world we have aclassifications for objects and every object must be from some classification.so a Class is a way for describing some properties and functionalities orbehaviors of a group of objects. In other words, The class considered to be atemplate for some objects. So maybe I will create a class called person so thisis a template of the functionality and the properties of persons. I explainedit by more than a way so wait until you see the first example and I think youwill grasp it completely.&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span class="smallblack"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;Computer’s Classes and Objects:&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;Computer’s Classes discussion is similar to what you graspfrom the last section with some modifications to become computerized.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;A C# Class Considered being the primary building block ofthe language. What I mean by the primary building block of the language is thatevery time you work with C# you will create Classes to form a program. We useClasses as a template to put the properties and functionalities or behaviors inone building block for some group of  objects and after that we use thattemplate to create the objects we need. For example, We need to have personsobjects in our program so the first thing to do here is to create a Classcalled Person that contains all the functionalities or behaviors and propertiesof any person and after that we will use that Class or template to create asmany objects as we need. Creating object of a specific class type called”instance of the class”. Don’t worry if you didn’t grasp it 100% anddon’t worry if you don’t know what’s the Class and Object’s properties andfunctionalities or behaviors because we still in the beginning and until now Ididn’t give any code examples. So let’s take a brief of what’s the Class andwhat’s an object ?&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span class="smallblack"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;The Class :&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt; Is abuilding block that contains the properties and functionalities that&lt;br /&gt;describesome group of objects, We can create a class Person that contains:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;1- The properties of any normal person on the earth like :Hair Color, Age, Height, Weight, Eyes Color.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;2- The functionalities or behaviors of any normal person onthe earth like : Drink water, Eat, Go to the work and later we will see how wecan implement the functionalities or behaviors and properties.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;There are 2 kinds of classes : The built-it classes thatcome with the .NET Framework and called Framework Class Library. And theprogrammer defined-classes which we create it.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;The class contains data (in the form of variables andproperties) and behaviors (in the form of methods to process these data). Wewill understand this concept more later in the article.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;When we declare a variable in a class we call it membervariables or instance variables. The name instance come from the fact that whenwe create an object we instance a class to create that object so instance of aclass means object of that class and instance variable means variable thatexists in that class.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span class="smallblack"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;The Object :&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt; It’s objectof some classification (or class, or type. All means the same thing) and whenyou create the object you can specify the properties of that object. What Imean here is me as an object can have a different properties (Hair Color, Age,Height, Weight) of you as another object. For example, I have a brown eyes andyou have a green eyes so when I create  2 objects I will specify a browncolor for my object’s Eyes Color property and I will specify a green color foryour object’s Eyes Color property.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;So to complete my introduction to Classes we must discussProperties and Variables.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span class="smallblack"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;Properties and Variables:&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;Variables declared in a class store the data for eachinstance, What that means ? means that when you instantiate this class (thatis, When you create an object of this class) the object will allocate a memorylocations to store the data of its variables. Let’s take an example tounderstand it well.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt; Person&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: blue;"&gt; public&lt;/span&gt; &lt;span style="color: blue;"&gt;int&lt;/span&gt; Age;&lt;br /&gt;&lt;span style="color: blue;"&gt; public&lt;/span&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; HairColor;&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;This is our simple class which contains 2 variables. Don’tworry about &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;public&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt; keyword now because we willtalk about it later . Now we will instantiate this class (that is, When youcreate an object of this class).&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;static&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Main(&lt;span style="color: blue;"&gt;string&lt;/span&gt;[]args)&lt;br /&gt;{&lt;br /&gt;Person Michael = &lt;span style="color: blue;"&gt;new&lt;/span&gt;Person();&lt;br /&gt;Person Mary = &lt;span style="color: blue;"&gt;new&lt;/span&gt; Person();&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: green;" lang="EN-US"&gt;&lt;span class="smallblack"&gt; // Specify some values for the instance variables&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt;&lt;br /&gt;Michael.Age = 20;&lt;br /&gt;Michael.HairColor = “Brown”;&lt;br /&gt;Mary.Age = 25;&lt;br /&gt;Mary.HairColor = “Black”;&lt;br /&gt;&lt;span style="color: green;"&gt; // print the console’s screen someof the variable’s values&lt;/span&gt;&lt;br /&gt;Console.WriteLine(“Michael’s age = {0}, and Mary’s age= {1}”,Michael.Age,&lt;br /&gt;Mary.Age);&lt;br /&gt;Console.ReadLine();&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;So we begin our Main method by creating 2 objects of Persontype. After creating the 2 objects we initialize the instance variables forobject Michael and then for object Mary. Finally we print some values to theconsole. here when you create Michael object C# compiler allocate a memorylocation for the 2 instance variables to put the values there. Also the samething with Mary object the compiler will create 2 variables in the memory forMary object. So each object now contains a different data. Note that wedirectly accessed the variables and we put any values we want, Right ? so maybesomeone doesn’t like me will put in my object’s variable Age value of 120 yearsso I will not get any kind of jobs. But wait there are a solution for thisproblem. We will use properties.&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span class="smallblack"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;Properties:&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;Properties is a way to access the variables of the class ina secure manner. Let’s see the same example using properties.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt; Person&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: blue;"&gt; private&lt;/span&gt; &lt;span style="color: blue;"&gt;int&lt;/span&gt; age;&lt;br /&gt;&lt;span style="color: blue;"&gt; private&lt;/span&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; hairColor;&lt;br /&gt;&lt;span style="color: blue;"&gt; public&lt;/span&gt; &lt;span style="color: blue;"&gt;int&lt;/span&gt; Age&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: blue;"&gt; get&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: blue;"&gt; return&lt;/span&gt;age;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: blue;"&gt; set&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: blue;"&gt; if&lt;/span&gt;(&lt;span style="color: blue;"&gt;value&lt;/span&gt; &lt;= 65 &amp;amp;&amp;amp; &lt;span style="color: blue;"&gt;value&lt;/span&gt; &gt;= 18)&lt;br /&gt;{&lt;br /&gt;age = &lt;span style="color: blue;"&gt;value&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: blue;"&gt; else&lt;/span&gt;&lt;br /&gt;age = 18;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: blue;"&gt; public&lt;/span&gt; &lt;span style="color: blue;"&gt;string&lt;/span&gt; HairColor&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: blue;"&gt; get&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: blue;"&gt; return&lt;/span&gt; hairColor;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: blue;"&gt; set&lt;/span&gt;&lt;br /&gt;{&lt;br /&gt;hairColor = &lt;span style="color: blue;"&gt;value&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;I made some modifications but please just care about the new2 properties that I created it here. So the property consists of 2 accessor.The &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;get &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;accessor which is responsibleof retrieving the variable value, And the &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;set &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;accessor which is responsible of modifying the variable’svalue. So The &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;get &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;accessor code is very simple wejust use the keyword &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;withthe variable name to return its value. so the following code:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt; get&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt;&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: blue;"&gt; return&lt;/span&gt; hairColor;&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;return the value stored in hairColor.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;Note :the keyword &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;value &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;isa reserved keyword by C# (that is, reserved keywords means that these keywordsown only by C# and you can’t create it for other purpose. For example, Youcan’t create a variable called &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;value &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;.Ifyou did that C# compiler will generate an error and to make things easierVisual Studio.NET will color the reserved keywords to blue.)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;Let’s put this code at work and after that discuss  the&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;set &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;accessor.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;static&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt; &lt;span style="color: blue;"&gt;void&lt;/span&gt; Main(&lt;span style="color: blue;"&gt;string&lt;/span&gt;[]args)&lt;br /&gt;{&lt;br /&gt;Person Michael = &lt;span style="color: blue;"&gt;new&lt;/span&gt;Person();&lt;br /&gt;Person Mary = &lt;span style="color: blue;"&gt;new&lt;/span&gt; Person()&lt;br /&gt;;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: green;" lang="EN-US"&gt;&lt;span class="smallblack"&gt; // Specify some values for the instance variables&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt;&lt;br /&gt;Michael.Age = 20;&lt;br /&gt;Michael.HairColor = “Brown”;&lt;br /&gt;Mary.Age = 25;&lt;br /&gt;Mary.HairColor = “Black”;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: green;" lang="EN-US"&gt;&lt;span class="smallblack"&gt; // print the console’s screen some of the variable’s values&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt;&lt;br /&gt;Console.WriteLine(“Michael’s age = {0}, and Mary’s age= {1}”,Michael.Age,&lt;br /&gt;Mary.Age);&lt;br /&gt;Console.ReadLine();&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;Here I created the same objects from last example themodifications that I used only properties to access the variable instead ofaccess it directly. Look at the following line of code&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt;Michael.Age = 20;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;When you assign a value to the property like that C# willuse the &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;set &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;accessor. The great thing withthe &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;set &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;accessor is that we can controlthe assigned value and test it and maybe change to in some cases. When youassign a value to a property C# change the value in a variable and you canaccess the variable’s value using the reserved keyword &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;value &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;exactly as I did in the example. Let’s see it again here.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;set&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt;&lt;br /&gt;{&lt;br /&gt;&lt;span style="color: blue;"&gt; if&lt;/span&gt;(&lt;span style="color: blue;"&gt;value&lt;/span&gt; &lt;= 65 &amp;amp;&amp;amp; &lt;span style="color: blue;"&gt;value&lt;/span&gt; &gt;= 18)&lt;br /&gt;{&lt;br /&gt;age = &lt;span style="color: blue;"&gt;value&lt;/span&gt;;&lt;br /&gt;}&lt;br /&gt;&lt;span style="color: blue;"&gt; else&lt;/span&gt;&lt;br /&gt;age = 18;&lt;br /&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;Here in the code I used &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;if &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;statement to test the assigned value because for some reasonI want any object of type Person to be in age between 18 and 65. Here I testthe value and if it in the range then simply I will store it in the variableage and it it’s not in the range I will put 18 as a value to age. It was just asimple example for the properties but there is a complete article about propertiessoon.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span class="smallblack"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;How we create objects and classes ?&lt;/span&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;We create classes by define it like that:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;using the keyword &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;followedby the class name like that&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;class&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt; Person&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;then we open a left brace “{” and after we writeour methods and properties we close it by a right brace “}”. That’show we create a class. Let’s see how we create an instance of that class.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;In the same way as we declare a variable of type &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;int &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;we create an object variable of Person type with some modifications:&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;int&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt; age;&lt;br /&gt;Person Michael = &lt;span style="color: blue;"&gt;new&lt;/span&gt; Person();&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;In the first line of code we specified integer variablecalled age. In the second line we specified first the type of Object we need tocreate followed by the object’s name followed by a reserved operator called &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New'; color: blue;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;and we end by typing the class name again followed byparenthesis “()”.&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;Let’s understand it step-by-step. Specifying the class nameat the beginning tell the C# Compiler to allocate a memory location for thattype (C# compiler knows all the variables and properties and methods of theclass so it will allocate the right amount of memory). Then we followed theclass name by out object variable name that we want it. The rest of the code”&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt;=&lt;span style="color: blue;"&gt;new&lt;/span&gt; Person();” &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;callthe object’s constructor. We will talk about constructor later but for nowunderstand that the constructor is a way to initialize your object’s variablewhile you are creating it not after you create it. For example, The Michaelobject we created it in the last section can be written as following : &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: 'Courier New';" lang="EN-US"&gt;&lt;span class="smallblack"&gt;Person Michael = &lt;span style="color: blue;"&gt;new&lt;/span&gt; Person(20, “Brown”);&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;here I specified the variable’s values in the parameter listso I initialized the variables while I’m creating the object. But for this codeto work we will need to specify the constructor in the Person class and I willnot do that here because constructor section will come in later articles. Ithink you got a good introduction about Classes and Objects not I will completein in my next article and I will talk about constructors and building blockscoping. I hope you got a new thing from my article. &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: 'Times New Roman';" lang="EN-US"&gt;&lt;/span&gt;&lt;/p&gt; &lt;div class="MsoNormal" style="text-align: center;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;br /&gt;&lt;hr /&gt;&lt;/span&gt;&lt;/div&gt; &lt;p class="MsoNormal"&gt;&lt;span class="smallblack"&gt;&lt;strong&gt;&lt;span style="text-decoration: underline;"&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 51, 102);" lang="EN-US"&gt;About the Author:&lt;/span&gt;&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 51, 102);" lang="EN-US"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Verdana; color: rgb(0, 51, 102);" lang="EN-US"&gt;&lt;span class="smallblack"&gt;Michael Youssef is 20 years old and he’sworking with Microsoft technologies since he was 17. He is working with VB,VB.NET, C#,ASP, ASP. NET, XML Web services, COM+, SQL Server 2000, Windows 2000Server, Active Directory, Networks design. He is MCSD.NET, MCDBA, MCSE, MCSAand he’s working now as a .NET Trainer in Egypt. Michael can be reached atmichaellabibat@hotmail.com .&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Verdana;" lang="EN-US"&gt;&lt;span class="smallblack"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;h2 class="related_post_title"&gt;Related Articles :&lt;/h2&gt;&lt;ul class="related_post"&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/08/explaining-c-abstraction-inheritence-and-polymorphism/" title="Explaining C# Abstraction, Inheritence and Polymorphism"&gt;Explaining C# Abstraction, Inheritence and Polymorphism&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/07/c-class-inheritance/" title="C# Class Inheritance"&gt;C# Class Inheritance&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/02/is-object-class-the-root-of-all-hierarchies/" title="Is Object Class, the root of all hierarchies?"&gt;Is Object Class, the root of all hierarchies?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/05/c-interface-implementation/" title="C# Interface Implementation"&gt;C# Interface Implementation&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/05/c-inheritence/" title="C# Inheritence"&gt;C# Inheritence&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/04/c-encapsulation/" title="C# Encapsulation"&gt;C# Encapsulation&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-8014950633432830158?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/8014950633432830158/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/objects-classes-in-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/8014950633432830158'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/8014950633432830158'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/objects-classes-in-c.html' title='Objects &amp; Classes in C#'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-7031174443290879364</id><published>2010-02-16T03:26:00.000-08:00</published><updated>2010-02-16T03:27:02.830-08:00</updated><title type='text'>C# Tutorial For Beginners</title><content type='html'>&lt;span class="smallblack"&gt;So you just install &lt;a target="_new" href="http://msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/000/976/msdncompositedoc.xml" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/downloads/default.asp?URL=/code/sample.asp?url=/msdn-files/027/000/976/msdncompositedoc.xml&amp;amp;referer=http%3A%2F%2Fwww.google.de%2Fsearch%3Fq%3Dc-sharp%2Bbeginning%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dorg.mozilla%3Ade%3Aofficial%26client%3Dfirefox-a');"&gt;.NET framework&lt;/a&gt; and want to start using C# but you don't know where to start ? well…&lt;/span&gt; &lt;p&gt; First you could download this complete tutorial &lt;a href="http://www.csharphelp.com/archives2/files/archive402/CSForDummy.zip"&gt;here&lt;/a&gt;. There is a directory for each tutorial with a &lt;b&gt;build.bat&lt;/b&gt; to build the tutorial and a &lt;b&gt;run.bat&lt;/b&gt; to run the program. And every example is already compiled, just in case… &lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; &lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span class="smallblack"&gt;First tutorial&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;&lt;span class="smallblack"&gt; You should first open a DOS command shell. &lt;i&gt;(If you don't know what it is, clic on the &lt;b&gt;Start menu&lt;/b&gt; then &lt;b&gt;run&lt;/b&gt; (at the bottom) and type, in the text field: "cmd".&lt;br /&gt;exercise: there is an easiest way to do that, try to find it.)&lt;/i&gt;&lt;br /&gt;You should begin to work in an empty directory for this. let call it "C:\learncs". Type in the shell: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; &gt; md C:\learncs&lt;br /&gt;&gt; cd C:\learncs&lt;br /&gt;&gt; C:&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt; Now you should create your first C# program, type "&lt;tt&gt;notepad hello.cs&lt;/tt&gt;" and type (in the notepad) &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; using System;&lt;/span&gt;&lt;/p&gt; &lt;p&gt; public class Hello&lt;br /&gt;{&lt;br /&gt;public static void Main()&lt;br /&gt;{&lt;br /&gt;Console.WriteLine("Hello C# World &lt;img src="http://www.csharphelp.com/wp-includes/images/smilies/icon_smile.gif" alt=":-)" class="wp-smiley" /&gt; ");&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt; the &lt;tt&gt;using&lt;/tt&gt; keyword just let you write &lt;tt&gt;Console&lt;/tt&gt; at line 7, instead of &lt;tt&gt;System.Console&lt;/tt&gt;. It's very usefull shortcut when you use a lot of "class" define in System.&lt;br /&gt;Save the file.&lt;br /&gt;Now you could compile. Type in the DOS Shell again and type:&lt;br /&gt;  &lt;tt&gt;csc /nologo /out:hello.exe hello.cs&lt;/tt&gt;&lt;br /&gt;You probaly have some errors, correct them, compile again, and now you have a working &lt;b&gt;hello.exe&lt;/b&gt; program… type &lt;tt&gt;hello&lt;/tt&gt;, see… &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; &lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span class="smallblack"&gt;Second tutorial&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;&lt;span class="smallblack"&gt;   Congratulation you've done the most difficult, let increase the difficulty. and create an object instance. in the DOS shell create a new directory: &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; &gt; md ..\learncs2&lt;br /&gt;&gt; cd ..\learncs2&lt;br /&gt;&gt; notepad hello.cs&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt; and then type, in the notepad &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; using System;&lt;/span&gt;&lt;/p&gt; &lt;p&gt; public class Echo&lt;br /&gt;{&lt;br /&gt;string myString;&lt;/p&gt; &lt;p&gt; public Echo(string aString)&lt;br /&gt;{&lt;br /&gt;myString = aString;&lt;br /&gt;}&lt;/p&gt; &lt;p&gt; public void Tell()&lt;br /&gt;{&lt;br /&gt;Console.WriteLine(myString);&lt;br /&gt;}&lt;br /&gt;}&lt;/p&gt; &lt;p&gt; public class Hello&lt;br /&gt;{&lt;br /&gt; public static void Main()&lt;br /&gt; {&lt;br /&gt;Echo h = new Echo("Hello my 1st C# object !");&lt;br /&gt;h.Tell();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt; Wouah, 25 lines! That's a program! Save it, compile it, run it…&lt;br /&gt;What happened? csc look for a &lt;b&gt;Main()&lt;/b&gt; function in your program, it should find one (and only one) and it will be the entry point of your program.&lt;br /&gt;In this tutorial we create 2 classes: Echo &amp;amp; Hello. In the Main() method you create an Echo object (an instance of the Echo class) with the keyword &lt;b&gt;new&lt;/b&gt;&lt;br /&gt;Then we called the instance method "Tell()".&lt;br /&gt;the upper case letter on class or Method is just a MS convention, do as it pleased you.&lt;br /&gt;public is a visibility access, method wich are not public could not be seen from outside, there is also other visibility keywords, to learn more, clic on &lt;b&gt;Start menu&lt;/b&gt;-&gt; &lt;b&gt;Programs&lt;/b&gt; -&gt; &lt;b&gt;Microsoft .NET Framework SDK&lt;/b&gt; -&gt; &lt;b&gt;Documentation&lt;/b&gt; there is a search window, an index window, etc… try to learn more about &lt;b&gt;public private protected&lt;/b&gt;. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; &lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span class="smallblack"&gt;Third tutorial&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;&lt;span class="smallblack"&gt; Now you become to be pretty confident, I guess, so we could start using multiple file, and even a dll ? go into an other directory (or stay in this one, I won't mind) and create 2 file:&lt;/span&gt;&lt;/p&gt; &lt;p&gt; &lt;b&gt;hello.cs&lt;/b&gt; &lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; using System;&lt;/span&gt;&lt;/p&gt; &lt;p&gt; public class Hello&lt;br /&gt;{&lt;br /&gt; public static void Main()&lt;br /&gt; {&lt;br /&gt;  HelloUtil.Echo h = new HelloUtil.Echo("Hello my 1st C# object !");&lt;br /&gt;h.Tell();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt; &lt;b&gt;echo.cs&lt;/b&gt; &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; using System;&lt;/span&gt;&lt;/p&gt; &lt;p&gt; namespace HelloUtil&lt;br /&gt;{&lt;br /&gt;public class Echo&lt;br /&gt;{&lt;br /&gt;string myString;&lt;/p&gt; &lt;p&gt; public Echo(string aString)&lt;br /&gt;{&lt;br /&gt;myString = aString;&lt;br /&gt;}&lt;/p&gt; &lt;p&gt; public void Tell()&lt;br /&gt;{&lt;br /&gt;Console.WriteLine(myString);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt; Note in hello.cs I have used the syntax "HelloUtil.Echo" it's because &lt;tt&gt;Echo&lt;/tt&gt; is in the namespace &lt;tt&gt;HelloUtil&lt;/tt&gt;, you could have typed (at he start of the file) &lt;tt&gt;using HelloUtil&lt;/tt&gt; and avoid &lt;tt&gt;HelloUtil.&lt;/tt&gt;, that's the way namespace work. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; Now you could compile both in one .exe with&lt;br /&gt;  &lt;tt&gt;&gt; csc /nologo /out:hello.exe *.cs&lt;/tt&gt;&lt;br /&gt;But it's not my intention, no.&lt;br /&gt;Well.&lt;br /&gt;(Have you tried?)&lt;br /&gt;Let's go building a DLL:&lt;br /&gt;  &lt;tt&gt;&gt; csc /nologo /t:library /out:echo.dll echo.cs&lt;/tt&gt;&lt;br /&gt;that's it (&lt;tt&gt;dir&lt;/tt&gt; will confirm).&lt;br /&gt;Now we could use it …&lt;br /&gt;  &lt;tt&gt;&gt; csc /out:hello.exe /r:echo.dll hello.cs&lt;/tt&gt;&lt;br /&gt;if you typed "hello" it will worked as usual…, but if you delete "echo.dll" the program will now crash: it use the DLL. You could also change Echo.cs, rebuild the DLL and see… that's the advantage of DLL! &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; You could also put your DLL in the global assembly cache (GAC), and any program would be able to access it, even if the DLL is not in its directory!&lt;br /&gt;to put it in the GAC, I sugest you read MS doc but here are the unexplained step: &lt;/span&gt;&lt;/p&gt; &lt;ol&gt;&lt;span class="smallblack"&gt; &lt;li&gt; create your assembly key, create it once and use it for every version. you create it with:&lt;br /&gt;  &lt;tt&gt;sn -k myKeyName.snk&lt;/tt&gt;&lt;br /&gt;the .snk file should be in your compilation directory (the one where your run csc) &lt;/li&gt; &lt;li&gt;create a strong asssembly title by adding in any .cs source file the following directive at top level: using System.Reflection; &lt;br /&gt;using System.Runtime.CompilerServices;&lt;br /&gt;[assembly: AssemblyTitle("My Lib Title")]&lt;br /&gt;[assembly: AssemblyVersion("1.2.3.4")]&lt;br /&gt;[assembly: AssemblyKeyFile("myKeyName.snk")] &lt;/li&gt; &lt;li&gt; now add it to the GAC:&lt;br /&gt;  &lt;tt&gt;&gt; gacutil.exe /if myLib.dll&lt;/tt&gt; &lt;/li&gt; &lt;/span&gt;&lt;/ol&gt; &lt;p&gt;&lt;span class="smallblack"&gt; &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; By the way, did I tell you ? when I referenced the hello.dll while compiling, remember? &lt;tt&gt;csc /out:hello.exe &lt;b&gt;/r:echo.dll&lt;/b&gt; hello.cs&lt;/tt&gt;, it could have been any assembly, even a .exe !!! &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; &lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span class="smallblack"&gt;Fourth tutorial&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;&lt;span class="smallblack"&gt;   Congratulation you would soon be able to hack &lt;a href="http://csgl.sourceforge.net/" onclick="pageTracker._trackPageview('/outgoing/csgl.sourceforge.net/?referer=http%3A%2F%2Fwww.google.de%2Fsearch%3Fq%3Dc-sharp%2Bbeginning%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dorg.mozilla%3Ade%3Aofficial%26client%3Dfirefox-a');"&gt;CsGL&lt;/a&gt; but there is one last step you should understand : interop (with C code).&lt;br /&gt;You will need a C compiler, I advise gcc for windows called &lt;a href="http://www.mingw.org/" onclick="pageTracker._trackPageview('/outgoing/www.mingw.org/?referer=http%3A%2F%2Fwww.google.de%2Fsearch%3Fq%3Dc-sharp%2Bbeginning%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dorg.mozilla%3Ade%3Aofficial%26client%3Dfirefox-a');"&gt;MinGW&lt;/a&gt;, it's free, it's good, it's GCC!&lt;br /&gt;We will create 3 file:&lt;br /&gt;&lt;b&gt;echo.c&lt;/b&gt; &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; #include &lt;stdio.h&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt; #define DLLOBJECT __declspec(dllexport)&lt;/p&gt; &lt;p&gt; DLLOBJECT void writeln(char* s)&lt;br /&gt;{&lt;br /&gt;printf("%s\&lt;br /&gt;n", s);&lt;br /&gt;}&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt; &lt;b&gt;echo.cs&lt;/b&gt; &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; using System;&lt;br /&gt;using System.Runtime.InteropServices;&lt;/span&gt;&lt;/p&gt; &lt;p&gt; namespace HelloUtil&lt;br /&gt;{&lt;br /&gt;public class Echo&lt;br /&gt;{&lt;br /&gt;[DllImport("echo.native.dll", CallingConvention=CallingConvention.Cdecl)]&lt;br /&gt;static extern void writeln(string s);&lt;/p&gt; &lt;p&gt; string myString;&lt;/p&gt; &lt;p&gt; public Echo(string aString)&lt;br /&gt;{&lt;br /&gt;myString = aString;&lt;br /&gt;}&lt;/p&gt; &lt;p&gt; public void Tell()&lt;br /&gt;{&lt;br /&gt;writeln(myString);&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt; &lt;b&gt;hello.cs&lt;/b&gt; &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; using System;&lt;br /&gt;using HelloUtil;&lt;/span&gt;&lt;/p&gt; &lt;p&gt; public class Hello&lt;br /&gt;{&lt;br /&gt; public static void Main()&lt;br /&gt; {&lt;br /&gt;  Echo h = new Echo("Hello my 1st interop code !");&lt;br /&gt;  h.Tell();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt; Hehe, here you discover a completly new thing, Attribute.&lt;br /&gt;"&lt;b&gt;[DllImport(..&lt;/b&gt;" is an attribute.&lt;br /&gt;You could tag any method/field/class with any number of attribute.&lt;br /&gt;They generate extra information that could be used by anyone who could understand them.&lt;br /&gt;This DllImport attribute is understand by the compiler and told him that the function below is in fact in a DLL whose name is "echo.native.dll". I add a calling convention parameter as the default .NET calling convention is __stdcall whereas, in C, it's __cdecl.&lt;br /&gt;By the way, if you look for DllImport in the documentation, look for &lt;b&gt;DllImportAttribute&lt;/b&gt;, because you remove "Attribute" to attribute classname when using them, it's like this. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; And now let's compile this!&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; &gt; csc /nologo /t:library /out:echo.dll echo.cs&lt;br /&gt;&gt; csc /nologo /out:hello.exe /r:echo.dll hello.cs&lt;br /&gt;&gt;&lt;br /&gt;&gt; &lt;span style="color: green;"&gt;rem "if the following line don't work, read bellow.."&lt;/span&gt;&lt;br /&gt;&gt; gcc -shared -o echo.native.dll echo.c&lt;br /&gt;&gt; strip echo.native.dll&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;&lt;p&gt;&lt;span class="smallblack"&gt; the 2 last line (the &lt;tt&gt;gcc &amp;amp; strip&lt;/tt&gt; command) are for building the "C-DLL".&lt;br /&gt;If they don't work maybe gcc is not in a directory listed in your path environment variable ? check with:&lt;br /&gt;  &lt;tt&gt;%lt; echo %PATH%&lt;/tt&gt;&lt;br /&gt;Well it's probably not,anyway, so type, assumin mingc is in C:\MinGW:&lt;br /&gt;  &lt;tt&gt;set PATH=C:\MinGW;%PATH%&lt;/tt&gt;&lt;br /&gt;And try again… you sure it's not a syntax error ?&lt;br /&gt;If it compile test it now: &lt;tt&gt;hello&lt;/tt&gt;&lt;br /&gt;Great isn't it ? &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; Now I should admit I didn't tell you all the truth. &lt;tt&gt;echo.dll&lt;/tt&gt; and &lt;tt&gt;echo.native.dll&lt;/tt&gt; are not the same kind of DLL. It's not just the language (C / C#) the C one is a plain executable full of, probably, x86 instruction, whereas the C# one is what MS call a portable executable.. anyway they are different.&lt;br /&gt;If you install echo.dll in the GAC it wont work because it won't find echo.native.dll except if you put in into the PATH (like C:\Windows\System32).&lt;br /&gt;In the same manner when you add the reference in VS.NET echo.native.dll is overlooked and your program won't work….&lt;br /&gt;So either put the native one in your path or copy it in the debug/release directory of VS.NET.&lt;br /&gt;Or do everything by hand (makefile? build.bat?) and put all your dll in you build directory, and everything work fine.. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; &lt;/span&gt;&lt;/p&gt; &lt;h3&gt;&lt;span class="smallblack"&gt;And now..&lt;/span&gt;&lt;/h3&gt; &lt;p&gt;&lt;span class="smallblack"&gt; Well, first forget about notepad. It's good to learn, but so painfull to use regularly.., try to find real developer friendly small text editor (like &lt;a href="http://home.t-online.de/home/Jens.Altmann/jfe_eng.htm" onclick="pageTracker._trackPageview('/outgoing/home.t-online.de/home/Jens.Altmann/jfe_eng.htm?referer=http%3A%2F%2Fwww.google.de%2Fsearch%3Fq%3Dc-sharp%2Bbeginning%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dorg.mozilla%3Ade%3Aofficial%26client%3Dfirefox-a');"&gt;JFE&lt;/a&gt;) or a complete IDE like &lt;a href="http://www.icsharpcode.net/opensource/sd/" onclick="pageTracker._trackPageview('/outgoing/www.icsharpcode.net/opensource/sd/?referer=http%3A%2F%2Fwww.google.de%2Fsearch%3Fq%3Dc-sharp%2Bbeginning%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dorg.mozilla%3Ade%3Aofficial%26client%3Dfirefox-a');"&gt;SharpDevelop&lt;/a&gt;. &lt;/span&gt;&lt;/p&gt; &lt;p&gt;&lt;span class="smallblack"&gt; Now you are ready to understand, I could tell you all the truth:&lt;br /&gt;&lt;tt&gt;csgl.dll&lt;/tt&gt; is a C# assembly and &lt;tt&gt;csgl.native.dll&lt;/tt&gt; is just a dll compiled by GCC, upon which &lt;tt&gt;csgl.dll&lt;/tt&gt; depends…&lt;/span&gt;&lt;/p&gt; &lt;h2 class="related_post_title"&gt;Most Commented Articles :&lt;/h2&gt;&lt;ul class="related_post"&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/12/c-tutorial-for-beginners/" title="C# Tutorial For Beginners"&gt;C# Tutorial For Beginners&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/10/c-editable-listview/" title="C# Editable ListView"&gt;C# Editable ListView&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/03/objects-classes-in-c/" title="Objects &amp;amp; Classes in C#"&gt;Objects &amp;amp; Classes in C#&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.sharepointmonitor.com/2007/01/sharepoint-web-service/" title="Talk to SharePoint Through its Web Services" onclick="pageTracker._trackPageview('/outgoing/www.sharepointmonitor.com/2007/01/sharepoint-web-service/?referer=http%3A%2F%2Fwww.google.de%2Fsearch%3Fq%3Dc-sharp%2Bbeginning%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dorg.mozilla%3Ade%3Aofficial%26client%3Dfirefox-a');"&gt;Talk to SharePoint Through its Web Services&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/08/combobox-with-images/" title="ComboBox With Images"&gt;ComboBox With Images&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2007/06/gdi-a-higher-level-api/" title="GDI+ A Higher Level API"&gt;GDI+ A Higher Level API&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/01/what-why-properties-in-c-part-1/" title="What &amp;amp; Why : Properties in C#:: Part 1"&gt;What &amp;amp; Why : Properties in C#:: Part 1&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/04/c-static-members/" title="C# – Static Members"&gt;C# – Static Members&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2006/10/drag-and-drop-files-with-c/" title="Drag and Drop Files with C#"&gt;Drag and Drop Files with C#&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.csharphelp.com/2005/12/introduction-to-datatables-part-i/" title="Introduction to DataTables: Part I"&gt;Introduction to DataTables: Part I&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-7031174443290879364?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/7031174443290879364/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/c-tutorial-for-beginners.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/7031174443290879364'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/7031174443290879364'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/c-tutorial-for-beginners.html' title='C# Tutorial For Beginners'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-2340003262498079440</id><published>2010-02-14T09:45:00.001-08:00</published><updated>2010-02-14T09:45:30.445-08:00</updated><title type='text'>TCS Interviews</title><content type='html'> &lt;br /&gt;February 04, 2010             Category : Training &amp;amp; Placements&lt;br /&gt;&lt;br /&gt;After the online written test, the next day was the technical round.My friends and I prepared hard for it. Actually, I would like to thank my friends Sonam and Prachi to help me brush up the things i studied in my past semisters. We all reached the venue by 1pm and I got the chance to be interviewed around 7:45 in the evening. Whole day we all were revising the subjects we mentioned in our resumee. But this only dosent work you hav to be done with all your core subjects!!!!&lt;br /&gt;&lt;br /&gt;In the technical round i was asked questions on my training both major and minor. Then on C and C++.Also on the subject I mentioned, especially, on Dtata Structure. Major Projects questions were also asked  like how would u approach to it.&lt;br /&gt;&lt;br /&gt;The technical results were out after some 2 hrs and uptill then i was completely stressed out on seeing the vast no. of rejections in the technical round!! But when i heard my name in the next round qualifying candidates list, all my apprehensions were lost.&lt;br /&gt;&lt;br /&gt;Next day we had to report at 9am, it was more stressful,u sleep at 12:30 in the night n report at 9 in the morning. But we all had to do that!! That day wewere scheduled with 2 rounds 1st the managerial round and on qualifying that the next n final was the HR round.&lt;br /&gt;&lt;br /&gt;In MR the panel, which i was assigned on, got the record of maximum no. of rejections. This increased my tensions more but i tried to be calm.When my no. came to go in I made myself very very confident. The interviewer made me comfortable in a minute and it increased my confidence level even more. Then he gave me my 1st situation and saw my approach on it. The next question was on my hobbies, to which i replied Dancing and Writing. I was elaborating my Dancing when he asked me to show few steps. I was bit surprised but he went on saying that people generally claim the hobbies which arent there's. I didnt showed any surprised expressions and i stood up to dance. He then urged that if i m not comfortable then no need to do it. But i refused to accept that and danced on Beedi Jalaile. He was impressed by this and also on learning tht i prepared it from TV!!! Then he gave me another situation where i am dancing on the stage on same song and suddenly a group of people in the backside of the audience start throwing eggs on me, how would i handle that situation.To this I answered and he framed questions on my answers, At the end he was very much impressed on my approach.&lt;br /&gt;&lt;br /&gt;MR was the round i enjoyed very much!!! There were group of 7 people,who I know, incuding me, out of which only 3 gotselected and i was 1 of them!!! :)&lt;br /&gt;&lt;br /&gt;Next was the HR round and in that also i was full of confidence. He asked me about my MR and i gave the appropriate answers  and then some general HR questions.&lt;br /&gt;&lt;br /&gt;After the final HR round We all were waiting for our results. This was again stressful. But uptill 9:30 we were told our results and I landed in TCS!!! :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-2340003262498079440?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/2340003262498079440/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/tcs-interviews.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/2340003262498079440'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/2340003262498079440'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/tcs-interviews.html' title='TCS Interviews'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-8784106681585506083</id><published>2010-02-14T09:36:00.000-08:00</published><updated>2010-02-14T09:38:18.180-08:00</updated><title type='text'>HR Interview Questions For Freshers</title><content type='html'>1. Tell me about yourself?&lt;br /&gt;I am down-to-earth, sweet, smart, creative, industrious, and thorough.&lt;br /&gt;&lt;br /&gt;2. How has your experience prepared you for your career?&lt;br /&gt;Coursework:&lt;br /&gt;Aside from the discipline and engineering foundation learning that I have gained from my courses, I think the design projects, reports, and presentations have prepared me most for my career.&lt;br /&gt;Work Experience:&lt;br /&gt;Through internships, I have gained self-esteem, confidence, and problem-solving skills. I also refined my technical writing and learned to prepare professional documents for clients.&lt;br /&gt;Student Organizations:&lt;br /&gt;By working on multiple projects for different student organizations while keeping up my grades, I've built time management and efficiency skills. Additionally, I've developed leadership, communication, and teamwork abilities.&lt;br /&gt;Life Experience:&lt;br /&gt;In general, life has taught me determination and the importance of maintaining my ethical standards.&lt;br /&gt;&lt;br /&gt;3. Describe the ideal job.&lt;br /&gt;Ideally, I would like to work in a fun, warm environment with individuals working independently towards team goals or individual goals. I am not concerned about minor elements, such as dress codes, cubicles, and the level of formality. Most important to me is an atmosphere that fosters attention to quality, honesty, and integrity.&lt;br /&gt;&lt;br /&gt;4. What type of supervisor have you found to be the best?&lt;br /&gt;I have been fortunate enough to work under wonderful supervisors who have provided limited supervision, while answering thoughtful questions and guiding learning. In my experience, the best supervisors give positive feedback and tactful criticism.&lt;br /&gt;&lt;br /&gt;5. What do you plan to be doing in five years' time?&lt;br /&gt;Taking the PE exam and serving in supervisory/leadership roles both at work and in professional/community organization(s).&lt;br /&gt;&lt;br /&gt;6. What contributions could you make in this organization that would help you to stand out from other applicants?&lt;br /&gt;In previous internships, my industriousness and ability to teach myself have been valuable assets to the company. My self-teaching abilities will minimize overhead costs, and my industriousness at targeting needs without prompting will set me apart from others. Additionally, one thing that has always set me apart from my scientific/engineering peers are my broad interests and strong writing abilities. I am not your typical "left-brained" engineer, and with my broad talents, I am likely to provide diverse viewpoints.&lt;br /&gt;&lt;br /&gt;7. What sort of criteria are you using to decide the organization you will work for?&lt;br /&gt;Most importantly, I am looking for a company that values quality, ethics, and teamwork. I would like to work for a company that hires overachievers.&lt;br /&gt;&lt;br /&gt;8. What made you choose your major?&lt;br /&gt;My academic interests are broad, so I sought civil engineering to achieve a great balance of mathematics, chemistry, biology, physics, and writing.&lt;br /&gt;&lt;br /&gt;9. Have your university and major met your expectations?&lt;br /&gt;The College of Engineering at MSU has exceeded my expectations by providing group activities, career resources, individual attention, and professors with genuine interest in teaching.&lt;br /&gt;My major has met my expectations by about 90%. I would have enjoyed more choices in environmental courses, and would have preferred more calculus-based learning.&lt;br /&gt;&lt;br /&gt;10. What made you choose this college?&lt;br /&gt;&lt;p&gt;I chose this college for the following reasons: my budget limited me to in-state schools, I was seeking an area with dog-friendly apartments, the MSU web site impressed me, I saw active student groups, and the people were very friendly.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;11. List 2-3 of your greatest achievements since you've been in college and why? Receiving the SWE Outstanding Member Award and College of Engineering Student Service Award&lt;br /&gt;I got involved with student activities to overcome my debilitating shyness. Receiving these awards signified that I had accomplished a transition from dragging myself to participate to feeling energized by it.&lt;br /&gt;Receiving the SWE Web Site Award&lt;br /&gt;Without training in web design, I competed against not only the other student sections, but professional sections around the nation. Despite competing with more HTML-experienced people, I brought this award to my section. After getting so much from SWE, I was able to give something back.&lt;br /&gt;Earning the highest grade in an organic chemistry class of ~200 people&lt;br /&gt;I worked very hard for this grade and loved the subject, so it was a great feeling to see that the hard work paid off.&lt;br /&gt;&lt;br /&gt;12. Which subjects have you enjoyed studying the most and why?&lt;br /&gt;I have enjoyed hydrology, fluids, solid &amp;amp; hazardous waste management, water and wastewater treatment, and oceanography because I love water and environmental topics.&lt;br /&gt;Calculus and linear algebra excite me because I love logic.&lt;br /&gt;I enjoyed the writing and analysis in economic history.&lt;br /&gt;Business law thrilled me because I have a strong interest in legal matters.&lt;br /&gt;&lt;br /&gt;13. Which subjects did you dislike and why?&lt;br /&gt;Introductory soil elicited little interest in me, most likely because the professor was inexperienced, the book was ineffective, and I had little spare time that semester to look into other resources.&lt;br /&gt;&lt;br /&gt;14. Do you have plans to continue your education?&lt;br /&gt;Yes, but not immediately. I plan to continue part time with either an MBA or an environmental engineering masters, depending on which will be more beneficial to my work.&lt;br /&gt;&lt;br /&gt;15. How would a professor who knows you well describe you? One who does not know you well?&lt;br /&gt;A professor who knows me well would likely describe my personal qualities: sweet, down-to-earth, smart, hard-working, and conscientious.&lt;br /&gt;As specific examples of those who did not know me well, my soils professor and soils teaching assistant each considered me smart and respectful, and both thought that I must have enjoyed the class a lot, due to my performance.&lt;br /&gt;&lt;br /&gt;16. Given the chance, how would you alter your education?&lt;br /&gt;Knowing now what I like the most, I would have used my electives for extra math and psychology classes, since I tend to be well-rounded enough that a variety of classes are unnecessary; my personal reading is diverse enough. I have found that mathematics and psychology are helpful to all career and life paths.&lt;br /&gt;&lt;br /&gt;17. Which part-time job did you enjoy the most and why?&lt;br /&gt;Working for PM Environmental was most enjoyable to me, since I felt like I was significantly contributing to the company, and I enjoyed learning on my own.&lt;br /&gt;&lt;br /&gt;18. Interests:&lt;br /&gt;Some of my interests include dogs, hiking, snow-shoeing, water sports, writing, reading (especially Charles Dickens' novels), skiing, drawing, crafts, and computers.&lt;br /&gt;&lt;br /&gt;19. What are your strengths?&lt;br /&gt;My strongest strength is the ability to teach myself difficult material, regardless of the subject (with the exception of theater and drawing blood from dogs, which I have no talent for). Additionally, I have always excelled verbally and look forward to writing opportunities.&lt;br /&gt;&lt;br /&gt;20. What are your weaknesses?&lt;br /&gt;I tend to try to do too many things, leaving little time for myself. I have worked on balancing myself for the last several months. I am also working on improving my public speaking skills.&lt;br /&gt;&lt;br /&gt;21. What sort of serious problems have you experienced, and how have you handled them?&lt;br /&gt;My apartment building burned down at the end of January during one of my semesters at MSU. Before the fire got too bad, I was able to rescue my pets and the neighbor's dog, as well as my textbooks and backpack, but I lost most of my mementos and possessions. While the firemen were preparing their hoses, I drove to school (with the animals in the car) to meet my lab partners, who were waiting for me. I explained the situation, emailed my professors, and rushed back to the apartment.&lt;br /&gt;Fortunately, I had renter's insurance. I missed about a week of school to deal with the insurance matters and find a new place to live. In order to salvage my grades and sanity, I dropped a course and honored my existing student group and research commitments. Staying active socially and keeping myself well-rounded were the best healing tools for me. Within a few weeks, I was caught up and had recovered reasonably from the loss of sentimental items.&lt;br /&gt;&lt;br /&gt;22. Do you or have you in the past experimented with illegal drugs?&lt;br /&gt;No. My only addictions are caffeine and sugar.&lt;br /&gt;&lt;br /&gt;23. Would you be willing to take a drug test?&lt;br /&gt;Of course.&lt;br /&gt;&lt;br /&gt;24. Do you drink alcohol socially?&lt;br /&gt;No, but I enjoy Shirley Temples quite a bit.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-8784106681585506083?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/8784106681585506083/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/hr-interview-questions-for-freshers.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/8784106681585506083'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/8784106681585506083'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/hr-interview-questions-for-freshers.html' title='HR Interview Questions For Freshers'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-3291013875921499228</id><published>2010-02-14T09:30:00.000-08:00</published><updated>2010-02-14T09:35:45.217-08:00</updated><title type='text'>Human Resource Interview Tips</title><content type='html'>Human Resource Interview Tips&lt;br /&gt;&lt;br /&gt;The interview is an opportunity for both, the interviewer and the candidate to market themselves. The employer is selling the organization to you, and you are marketing your skills, knowledge, and personality to the employer. Remember that interviews are varied and so they cannot therefore be easily categorized.&lt;br /&gt;Following are some human resource interview tips:&lt;br /&gt;&lt;br /&gt;Be prepared&lt;br /&gt;Preparation increases confidence. Practice with your friends or relatives. Remember that everyone who is interviewing is not necessarily a good interviewer.&lt;br /&gt;You may prepare by reviewing magazine and newspaper articles. You may check out their web site. Read your resume before your interview. It will keep your answers fresh.&lt;br /&gt;&lt;br /&gt;Location and punctuality&lt;br /&gt;Find out the location of organization. Make sure you have a map or directions as well as information of the nearest railway station.&lt;br /&gt;Arrive 5-10 minutes early. Arriving early will give you the opportunity to read some information on the company in the reception area.&lt;br /&gt;&lt;br /&gt;Be professional&lt;br /&gt;Professional look always helps for good impression. Be careful about your dressing. Be aware of the company culture and ensure you dress to impress. Decide what you are going to wear the night before to avoid making the wrong choices.&lt;br /&gt;&lt;br /&gt;Be polite&lt;br /&gt;Don't interrupt to the interviewer. Listen very carefully. Poor listening skills are responsible for the bad impression.&lt;br /&gt;If the interview is being conducted in a restaurant, mind your table manners. If the interviewers are serious and soft-spoken, then you should be same as interviewer. Avoid loud laughter during the interviewer.&lt;br /&gt;&lt;br /&gt;Be positive&lt;br /&gt;Keep in mind that there is only one chance to make a first impression. Every company wants employees who are goal-oriented, career-driven, enthusiastic and motivated. Be the employee as they want. End the interview on a positive note. The hiring official needs to know that you are interested, enthusiastic and excited about the position and the company.&lt;br /&gt;&lt;br /&gt;Be practical&lt;br /&gt;If you are experienced then the interviewer already knows your current salary and benefits package. When the topic of salary comes up state that you know they will make a fair offer.&lt;br /&gt;If you are offered the position during the interviewing process and you want the job then accept it. If the offer is not acceptable for any reason, ask for time to consider the offer.&lt;br /&gt;&lt;br /&gt;Human resource interview tips - Do's&lt;br /&gt;&lt;br /&gt;Have a firm handshake.&lt;br /&gt;&lt;br /&gt;Be sincere and direct.&lt;br /&gt;&lt;br /&gt;Introduce yourself in a courteous manner.&lt;br /&gt;&lt;br /&gt;Read company materials while you wait.&lt;br /&gt;&lt;br /&gt;You have to prepare for questions and listen carefully to the interviewer.&lt;br /&gt;&lt;br /&gt;Ask about the next step in the process.&lt;br /&gt;&lt;br /&gt;Thank the interviewer.&lt;br /&gt;&lt;br /&gt;Learn about the Human Resources Analyst Program and understand the different facets of human resources.&lt;br /&gt;&lt;br /&gt;You never know what the interviewer will ask you about, so be prepared to talk about anything you have included on your resume. You should be truthful about your experiences and skills.&lt;br /&gt;&lt;br /&gt;Human resource interview tips - Don'ts&lt;br /&gt;&lt;br /&gt;Don't show depression or discouragement.&lt;br /&gt;&lt;br /&gt;Don't start the topics like salary, benefits or working hours.&lt;br /&gt;&lt;br /&gt;Don't look at your watch.&lt;br /&gt;&lt;br /&gt;Don't take extensive notes.&lt;br /&gt;&lt;br /&gt;Don't be too serious.&lt;br /&gt;&lt;br /&gt;Follow up&lt;br /&gt;Always write a thank you note immediately after the interview. If there are number of interviewers then send a copy of thank you letter to each person. Summarize your qualifications and how they meet the expectations of the position.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-3291013875921499228?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/3291013875921499228/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/human-resource-interview-tips.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/3291013875921499228'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/3291013875921499228'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/human-resource-interview-tips.html' title='Human Resource Interview Tips'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-1307427580970488666</id><published>2010-02-04T23:18:00.000-08:00</published><updated>2010-02-04T23:19:41.787-08:00</updated><title type='text'>Design Pattern</title><content type='html'>&lt;meta equiv="Content-Type" content="text/html; charset=utf-8"&gt;&lt;meta name="ProgId" content="Word.Document"&gt;&lt;meta name="Generator" content="Microsoft Word 12"&gt;&lt;meta name="Originator" content="Microsoft Word 12"&gt;&lt;link rel="File-List" href="file:///C:%5CDOCUME%7E1%5Cz063380%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml"&gt;&lt;link rel="Edit-Time-Data" href="file:///C:%5CDOCUME%7E1%5Cz063380%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_editdata.mso"&gt;&lt;!--[if !mso]&gt; &lt;style&gt; v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} &lt;/style&gt; &lt;![endif]--&gt;&lt;link rel="themeData" href="file:///C:%5CDOCUME%7E1%5Cz063380%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx"&gt;&lt;link rel="colorSchemeMapping" href="file:///C:%5CDOCUME%7E1%5Cz063380%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml"&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:trackmoves&gt;false&lt;/w:TrackMoves&gt;   &lt;w:trackformatting/&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:donotpromoteqf/&gt;   &lt;w:lidthemeother&gt;EN-US&lt;/w:LidThemeOther&gt;   &lt;w:lidthemeasian&gt;X-NONE&lt;/w:LidThemeAsian&gt;   &lt;w:lidthemecomplexscript&gt;X-NONE&lt;/w:LidThemeComplexScript&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;    &lt;w:splitpgbreakandparamark/&gt;    &lt;w:dontvertaligncellwithsp/&gt;    &lt;w:dontbreakconstrainedforcedtables/&gt;    &lt;w:dontvertalignintxbx/&gt;    &lt;w:word11kerningpairs/&gt;    &lt;w:cachedcolbalance/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;   &lt;m:mathpr&gt;    &lt;m:mathfont val="Cambria Math"&gt;    &lt;m:brkbin val="before"&gt;    &lt;m:brkbinsub val="&amp;#45;-"&gt;    &lt;m:smallfrac val="off"&gt;    &lt;m:dispdef/&gt;    &lt;m:lmargin val="0"&gt;    &lt;m:rmargin val="0"&gt;    &lt;m:defjc val="centerGroup"&gt;    &lt;m:wrapindent val="1440"&gt;    &lt;m:intlim val="subSup"&gt;    &lt;m:narylim val="undOvr"&gt;   &lt;/m:mathPr&gt;&lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" defunhidewhenused="true" defsemihidden="true" defqformat="false" defpriority="99" latentstylecount="267"&gt;   &lt;w:lsdexception locked="false" priority="0" semihidden="false" unhidewhenused="false" qformat="true" name="Normal"&gt;   &lt;w:lsdexception locked="false" priority="9" semihidden="false" unhidewhenused="false" qformat="true" name="heading 1"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 2"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 3"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 4"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 5"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 6"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 7"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 8"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 9"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 1"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 2"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 3"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 4"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 5"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 6"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 7"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 8"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 9"&gt;   &lt;w:lsdexception locked="false" priority="35" qformat="true" name="caption"&gt;   &lt;w:lsdexception locked="false" priority="10" semihidden="false" unhidewhenused="false" qformat="true" name="Title"&gt;   &lt;w:lsdexception locked="false" priority="1" name="Default Paragraph Font"&gt;   &lt;w:lsdexception locked="false" priority="11" semihidden="false" unhidewhenused="false" qformat="true" name="Subtitle"&gt;   &lt;w:lsdexception locked="false" priority="22" semihidden="false" unhidewhenused="false" qformat="true" name="Strong"&gt;   &lt;w:lsdexception locked="false" priority="20" semihidden="false" unhidewhenused="false" qformat="true" name="Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="59" semihidden="false" unhidewhenused="false" name="Table Grid"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Placeholder Text"&gt;   &lt;w:lsdexception locked="false" priority="1" semihidden="false" unhidewhenused="false" qformat="true" name="No Spacing"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Revision"&gt;   &lt;w:lsdexception locked="false" priority="34" semihidden="false" unhidewhenused="false" qformat="true" name="List Paragraph"&gt;   &lt;w:lsdexception locked="false" priority="29" semihidden="false" unhidewhenused="false" qformat="true" name="Quote"&gt;   &lt;w:lsdexception locked="false" priority="30" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Quote"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="19" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="21" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="31" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Reference"&gt;   &lt;w:lsdexception locked="false" priority="32" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Reference"&gt;   &lt;w:lsdexception locked="false" priority="33" semihidden="false" unhidewhenused="false" qformat="true" name="Book Title"&gt;   &lt;w:lsdexception locked="false" priority="37" name="Bibliography"&gt;   &lt;w:lsdexception locked="false" priority="39" qformat="true" name="TOC Heading"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt; &lt;!--  /* Font Definitions */  @font-face 	{font-family:Wingdings; 	panose-1:5 0 0 0 0 0 0 0 0 0; 	mso-font-charset:2; 	mso-generic-font-family:auto; 	mso-font-pitch:variable; 	mso-font-signature:0 268435456 0 0 -2147483648 0;} @font-face 	{font-family:"Cambria Math"; 	panose-1:2 4 5 3 5 4 6 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:roman; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face 	{font-family:Calibri; 	panose-1:2 15 5 2 2 2 4 3 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face 	{font-family:Verdana; 	panose-1:2 11 6 4 3 5 4 4 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:536871559 0 0 0 415 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-parent:""; 	margin-top:0in; 	margin-right:0in; 	margin-bottom:10.0pt; 	margin-left:0in; 	line-height:115%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:minor-bidi;} .MsoChpDefault 	{mso-style-type:export-only; 	mso-default-props:yes; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:minor-bidi;} .MsoPapDefault 	{mso-style-type:export-only; 	margin-bottom:10.0pt; 	line-height:115%;} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.0in 1.0in 1.0in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;}  /* List Definitions */  @list l0 	{mso-list-id:602032864; 	mso-list-template-ids:1241533670;} @list l1 	{mso-list-id:1915041663; 	mso-list-template-ids:1960078880;} @list l1:level1 	{mso-level-number-format:bullet; 	mso-level-text:; 	mso-level-tab-stop:.5in; 	mso-level-number-position:left; 	text-indent:-.25in; 	mso-ansi-font-size:10.0pt; 	font-family:Symbol;} ol 	{margin-bottom:0in;} ul 	{margin-bottom:0in;} --&gt; &lt;/style&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-priority:99; 	mso-style-qformat:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin-top:0in; 	mso-para-margin-right:0in; 	mso-para-margin-bottom:10.0pt; 	mso-para-margin-left:0in; 	line-height:115%; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin;} &lt;/style&gt; &lt;![endif]--&gt;  &lt;p class="MsoNormal" style="line-height: normal;"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;Introduction&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;&lt;br /&gt;Hi friends, please do not think you get an architecture position by reading interview questions. But yes there should be some kind of reference which will help you quickly revise what are the definition. Just by reading these answers you get to a position where you are aware of the fundamentals. But if you have not really worked you will surely fail with scenario based questions. So use this as a quick revision rather than a shot cut.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;(B) What are design patterns ?&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;a href="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/DP1.aspx" target="_blank"&gt;&lt;span style="color: blue;"&gt;Design patterns&lt;/span&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Calibri&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: windowtext; text-decoration: none;"&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shapetype id="_x0000_t75" coordsize="21600,21600" spt="75" preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;  &lt;v:stroke joinstyle="miter"&gt;  &lt;v:formulas&gt;   &lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;   &lt;v:f eqn="sum @0 1 0"&gt;   &lt;v:f eqn="sum 0 0 @1"&gt;   &lt;v:f eqn="prod @2 1 2"&gt;   &lt;v:f eqn="prod @3 21600 pixelWidth"&gt;   &lt;v:f eqn="prod @3 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @0 0 1"&gt;   &lt;v:f eqn="prod @6 1 2"&gt;   &lt;v:f eqn="prod @7 21600 pixelWidth"&gt;   &lt;v:f eqn="sum @8 21600 0"&gt;   &lt;v:f eqn="prod @7 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @10 21600 0"&gt;  &lt;/v:formulas&gt;  &lt;v:path extrusionok="f" gradientshapeok="t" connecttype="rect"&gt;  &lt;o:lock ext="edit" aspectratio="t"&gt; &lt;/v:shapetype&gt;&lt;v:shape id="Picture_x0020_1" spid="_x0000_i1053" type="#_x0000_t75" alt="http://images.intellitxt.com/ast/adTypes/2_bing.gif" href="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/DP1.aspx" target="&amp;quot;_blank&amp;quot;" style="'width:7.5pt;height:7.5pt;visibility:visible;" button="t"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image001.gif" title="2_bing"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;span style=""&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image001.gif" alt="http://images.intellitxt.com/ast/adTypes/2_bing.gif" shapes="Picture_x0020_1" width="10" border="0" height="10" /&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; are documented tried and tested solutions for recurring problems in a given context. So basically you have a problem context and the proposed solution for the same. Design patterns existed in some or other form right from the inception stage of software development. Let's say if you want to implement a sorting algorithm the first thing comes to mind is bubble sort. So the problem is sorting and solution is bubble sort. Same holds true for design patterns.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;(I) Which are the three main categories of design patterns ?&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;There are three basic classifications of patterns Creational, Structural, and Behavioral patterns.&lt;br /&gt;&lt;i&gt;&lt;br /&gt;&lt;b&gt;Creational Patterns&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Abstract Factory &lt;/i&gt;: Creates an instance of several families of classes&lt;br /&gt;&lt;i&gt;Builder&lt;/i&gt; : Separates object construction from its representation&lt;br /&gt;&lt;i&gt;Factory Method &lt;/i&gt;: Creates an instance of several derived classes&lt;br /&gt;&lt;i&gt;Prototype &lt;/i&gt;: A fully initialized instance to be copied or cloned&lt;br /&gt;&lt;i&gt;Singleton&lt;/i&gt; : A class in which only a single instance can exist&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;u&gt;Note&lt;/u&gt;&lt;/b&gt; : The best way to remember Creational pattern is by remembering ABFPS (Abraham Became First President of States).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;Structural Patterns&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;i&gt;Adapter &lt;/i&gt;: Match interfaces of different classes .&lt;br /&gt;&lt;i&gt;Bridge &lt;/i&gt;: Separates an object's abstraction from its implementation.&lt;br /&gt;&lt;i&gt;Composite &lt;/i&gt;: A tree structure of simple and composite objects.&lt;br /&gt;&lt;i&gt;Decorator &lt;/i&gt;: Add responsibilities to objects dynamically.&lt;br /&gt;&lt;i&gt;Flyweight &lt;/i&gt;: A fine-grained instance used for efficient sharing.&lt;br /&gt;&lt;i&gt;Proxy &lt;/i&gt;: An object representing another object.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Note&lt;/u&gt; &lt;/b&gt;: To remember structural pattern best is (ABCDFFP)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;Behavioral Patterns&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;i&gt;Mediator &lt;/i&gt;: Defines simplified communication between classes.&lt;br /&gt;&lt;i&gt;Memento &lt;/i&gt;: Capture and restore an object's internal state.&lt;br /&gt;&lt;i&gt;Interpreter &lt;/i&gt;: A way to include language elements in a program.&lt;br /&gt;&lt;i&gt;Iterator &lt;/i&gt;: Sequentially access the elements of a collection.&lt;br /&gt;&lt;i&gt;Chain of Resp &lt;/i&gt;: A way of passing a request between a chain of objects.&lt;br /&gt;&lt;i&gt;Command &lt;/i&gt;: Encapsulate a command request as an object.&lt;br /&gt;&lt;i&gt;State &lt;/i&gt;: Alter an object's behavior when its state changes.&lt;br /&gt;&lt;i&gt;Strategy &lt;/i&gt;: Encapsulates an algorithm inside a class.&lt;br /&gt;&lt;i&gt;Observer &lt;/i&gt;: A way of notifying change to a number of classes.&lt;br /&gt;&lt;i&gt;Template Method &lt;/i&gt;: Defer the exact steps of an algorithm to a subclass.&lt;br /&gt;&lt;i&gt;Visitor &lt;/i&gt;: Defines a new operation to a class without change.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt;: Just remember Music....... 2 MICS On TV (MMIICCSSOTV).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; : In the further section we will be covering all the above design patterns in a more detail manner.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;(A) Can you explain factory pattern ?&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;Factory pattern is one of the types of creational patterns. You can make out from the name factory itself it's meant to construct and create something. In software architecture world factory pattern is meant to centralize creation of objects. Below is a code snippet of a client which has different types of invoices. These invoices are created depending on the invoice type specified by the client. There are two issues with the code below :&lt;br /&gt;&lt;br /&gt;First we have lots of 'new' keyword scattered in the client. In other ways the client is loaded with lot of object creational activities which can make the client logic very complicated.&lt;br /&gt;&lt;br /&gt;Second issue is that the client needs to be aware of all types of invoices. So if we are adding one more invoice class type called as 'InvoiceWithFooter' we need to reference the new class in the client and recompile the client also.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_2" spid="_x0000_i1052" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/InvoiceTypes.jpg" style="'width:289.5pt;height:119.25pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image002.jpg" title="InvoiceTypes"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image002.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/InvoiceTypes.jpg" shapes="Picture_x0020_2" width="386" border="0" height="159" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 1. Different types of invoice&lt;br /&gt;&lt;br /&gt;Taking these issues as our base we will now look in to how factory pattern can help us solve the same. Below figure 'Factory Pattern' shows two concrete classes 'ClsInvoiceWithHeader' and 'ClsInvoiceWithOutHeader'.&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;first issue&lt;/i&gt; was that these classes are in direct contact with client which leads to lot of 'new' keyword scattered in the client code. This is removed by introducing a new class 'ClsFactoryInvoice' which does all the creation of objects.&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;second issue&lt;/i&gt; was that the client code is aware of both the concrete classes i.e. 'ClsInvoiceWithHeader' and 'ClsInvoiceWithOutHeader'. This leads to recompiling of the client code when we add new invoice types. For instance if we add 'ClsInvoiceWithFooter' client code needs to be changed and recompiled accordingly. To remove this issue we have introduced a common interface 'IInvoice'. Both the concrete classes 'ClsInvoiceWithHeader' and 'ClsInvoiceWithOutHeader' inherit and implement the 'IInvoice' interface.&lt;br /&gt;&lt;br /&gt;The client references only the 'IInvoice' interface which results in zero connection between client and the concrete classes ( 'ClsInvoiceWithHeader' and 'ClsInvoiceWithOutHeader'). So now if we add new concrete invoice class we do not need to change any thing at the client side.&lt;br /&gt;&lt;br /&gt;In one line the creation of objects is taken care by 'ClsFactoryInvoice' and the client disconnection from the concrete classes is taken care by 'IInvoice' interface.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_3" spid="_x0000_i1051" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/FactoryPattern.jpg" style="'width:456.75pt;height:280.5pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image003.jpg" title="FactoryPattern"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image004.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/FactoryPattern.jpg" shapes="Picture_x0020_3" width="609" border="0" height="374" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 2. Factory pattern&lt;br /&gt;&lt;br /&gt;Below are the code snippets of how actually factory pattern can be implemented in C#. In order to avoid recompiling the client we have introduced the invoice interface 'IInvoice'. Both the concrete classes 'ClsInvoiceWithOutHeaders' and 'ClsInvoiceWithHeader' inherit and implement the 'IInvoice' interface.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_4" spid="_x0000_i1050" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/InterfaceAndConcrete.jpg" style="'width:459pt;height:313.5pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image005.jpg" title="InterfaceAndConcrete"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image005.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/InterfaceAndConcrete.jpg" shapes="Picture_x0020_4" width="612" border="0" height="418" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 3. Interface and concrete classes&lt;br /&gt;&lt;br /&gt;We have also introduced an extra class 'ClsFactoryInvoice' with a function 'getInvoice()' which will generate objects of both the invoices depending on 'intInvoiceType' value. In short we have centralized the logic of object creation in the 'ClsFactoryInvoice'. The client calls the 'getInvoice' function to generate the invoice classes. One of the most important points to be noted is that client only refers to 'IInvoice' type and the factory class 'ClsFactoryInvoice' also gives the same type of reference. This helps the client to be complete detached from the concrete classes, so now when we add new classes and invoice types we do not need to recompile the client.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_5" spid="_x0000_i1049" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/FactoryClass.jpg" style="'width:469.5pt;height:429.75pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image006.jpg" title="FactoryClass"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image006.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/FactoryClass.jpg" shapes="Picture_x0020_5" width="626" border="0" height="573" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 4. Factory class which generates objects&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note : &lt;/b&gt;The above example is given in C# . Even if you are from some other technology you can still map the concept accordingly. You can get source code from the CD in 'FactoryPattern' folder.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;Can you explain abstract factory pattern ?&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Abstract factory expands on the basic factory pattern. Abstract factory helps us to unite similar factory pattern classes in to one unified interface. So basically all the common factory patterns now inherit from a common abstract factory class which unifies them in a common class. All other things related to factory pattern remain same as discussed in the previous question.&lt;br /&gt;&lt;br /&gt;A factory class helps us to centralize the creation of classes and types. Abstract factory helps us to bring uniformity between related factory patterns which leads more simplified interface for the client.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_6" spid="_x0000_i1048" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/AbstractFActory.jpg" style="'width:303pt;height:117pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image007.jpg" title="AbstractFActory"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image007.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/AbstractFActory.jpg" shapes="Picture_x0020_6" width="404" border="0" height="156" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 5. Abstract factory unifies related factory patterns&lt;br /&gt;&lt;br /&gt;Now that we know the basic lets try to understand the details of how abstract factory patterns are actually implemented. As said previously we have the factory pattern classes (factory1 and factory2) tied up to a common abstract factory (AbstractFactory Interface) via inheritance. Factory classes stand on the top of concrete classes which are again derived from common interface. For instance in figure 'Implementation of abstract factory' both the concrete classes 'product1' and 'product2' inherits from one interface i.e. 'common'. The client who wants to use the concrete class will only interact with the abstract factory and the common interface from which the concrete classes inherit.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_7" spid="_x0000_i1047" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Implementation.jpg" style="'width:387pt;height:186.75pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image008.jpg" title="Implementation"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image008.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Implementation.jpg" shapes="Picture_x0020_7" width="516" border="0" height="249" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 6. Implementation of abstract factory&lt;br /&gt;&lt;br /&gt;Now let's have a look at how we can practically implement abstract factory in actual code. We have scenario where we have UI creational activities for textboxes and buttons through their own centralized factory classes 'ClsFactoryButton' and 'ClsFactoryText'. Both these classes inherit from common interface 'InterfaceRender'. Both the factories 'ClsFactoryButton' and 'ClsFactoryText' inherits from the common factory 'ClsAbstractFactory'. Figure 'Example for AbstractFactory' shows how these classes are arranged and the client code for the same. One of the important points to be noted about the client code is that it does not interact with the concrete classes. For object creation it uses the abstract factory ( ClsAbstractFactory ) and for calling the concrete class implementation it calls the methods via the interface 'InterfaceRender'. So the 'ClsAbstractFactory' class provides a common interface for both factories 'ClsFactoryButton' and 'ClsFactoryText'.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_8" spid="_x0000_i1046" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Exampleforabstract.jpg" style="'width:412.5pt;height:401.25pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image009.jpg" title="Exampleforabstract"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image010.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Exampleforabstract.jpg" shapes="Picture_x0020_8" width="550" border="0" height="535" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 7. Example for abstract factory&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt;: We have provided a code sample in C# in the 'AbstractFactory' folder. People who are from different technology can compare easily the implementation in their own language.&lt;br /&gt;&lt;br /&gt;We will just run through the sample code for abstract factory. Below code snippet 'Abstract factory and factory code snippet' shows how the factory pattern classes inherit from abstract factory.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_9" spid="_x0000_i1045" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Abstractfactoryandfactorycode.jpg" style="'width:478.5pt;height:363.75pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image011.jpg" title="Abstractfactoryandfactorycode"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image012.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Abstractfactoryandfactorycode.jpg" shapes="Picture_x0020_9" width="638" border="0" height="485" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 8. Abstract factory and factory code snippet&lt;br /&gt;&lt;br /&gt;Figure 'Common Interface for concrete classes' how the concrete classes inherits from a common interface 'InterFaceRender' which enforces the method 'render' in all the concrete classes.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_10" spid="_x0000_i1044" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Commoninterface.jpg" style="'width:426.75pt;height:215.25pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image013.jpg" title="Commoninterface"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image014.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Commoninterface.jpg" shapes="Picture_x0020_10" width="569" border="0" height="287" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 9. Common interface for concrete classes&lt;br /&gt;&lt;br /&gt;The final thing is the client code which uses the interface 'InterfaceRender' and abstract factory 'ClsAbstractFactory' to call and create the objects. One of the important points about the code is that it is completely isolated from the concrete classes. Due to this any changes in concrete classes like adding and removing concrete classes does not need client level changes.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_11" spid="_x0000_i1043" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Clientinterface.jpg" style="'width:404.25pt;height:181.5pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image015.jpg" title="Clientinterface"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image015.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Clientinterface.jpg" shapes="Picture_x0020_11" width="539" border="0" height="242" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 10. Client, interface and abstract factory&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Can you explain builder pattern?&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Builder falls under the type of creational pattern category. Builder pattern helps us to separate the construction of a complex object from its representation so that the same construction process can create different representations. Builder pattern is useful when the construction of the object is very complex. The main objective is to separate the construction of objects and their representations. If we are able to separate the construction and representation, we can then get many representations from the same construction.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_12" spid="_x0000_i1042" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Builderconcept.jpg" style="'width:262.5pt;height:90pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image016.jpg" title="Builderconcept"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image016.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Builderconcept.jpg" shapes="Picture_x0020_12" width="350" border="0" height="120" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 11. Builder concept&lt;br /&gt;&lt;br /&gt;To understand what we mean by construction and representation lets take the example of the below 'Tea preparation' sequence.&lt;br /&gt;&lt;br /&gt;You can see from the figure 'Tea preparation' from the same preparation steps we can get three representation of tea's (i.e. Tea with out sugar, tea with sugar / milk and tea with out milk).&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_13" spid="_x0000_i1041" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Teapreparation.jpg" style="'width:373.5pt;height:338.25pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image017.jpg" title="Teapreparation"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image017.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Teapreparation.jpg" shapes="Picture_x0020_13" width="498" border="0" height="451" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 12. Tea preparation&lt;br /&gt;&lt;br /&gt;Now let's take a real time example in software world to see how builder can separate the complex creation and its representation. Consider we have application where we need the same report to be displayed in either 'PDF' or 'EXCEL' format. Figure 'Request a report' shows the series of steps to achieve the same. Depending on report type a new report is created, report type is set, headers and footers of the report are set and finally we get the report for display.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_14" spid="_x0000_i1040" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Requestreport.jpg" style="'width:217.5pt;height:318pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image018.jpg" title="Requestreport"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image018.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Requestreport.jpg" shapes="Picture_x0020_14" width="290" border="0" height="424" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 13. Request a report&lt;br /&gt;&lt;br /&gt;Now let's take a different view of the problem as shown in figure 'Different View'. The same flow defined in 'Request a report' is now analyzed in representations and common construction. The construction process is same for both the types of reports but they result in different representations.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_15" spid="_x0000_i1039" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/DifferentView.jpg" style="'width:347.25pt;height:280.5pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image019.jpg" title="DifferentView"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image019.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/DifferentView.jpg" shapes="Picture_x0020_15" width="463" border="0" height="374" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 14. Different View&lt;br /&gt;&lt;br /&gt;We will take the same report problem and try to solve the same using builder patterns. There are three main parts when you want to implement builder patterns.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Builder &lt;/i&gt;: Builder is responsible for defining the construction process for individual parts. Builder has those individual processes to initialize and configure the product.&lt;br /&gt;&lt;i&gt;Director &lt;/i&gt;: Director takes those individual processes from the builder and defines the sequence to build the product.&lt;br /&gt;&lt;i&gt;Product&lt;/i&gt; : Product is the final object which is produced from the builder and director coordination.&lt;br /&gt;&lt;br /&gt;First let's have a look at the builder class hierarchy. We have a abstract class called as 'ReportBuilder' from which custom builders like 'ReportPDF' builder and 'ReportEXCEL' builder will be built.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_16" spid="_x0000_i1038" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Builderclasshierarchy.jpg" style="'width:255.75pt;height:139.5pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image020.jpg" title="Builderclasshierarchy"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image020.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Builderclasshierarchy.jpg" shapes="Picture_x0020_16" width="341" border="0" height="186" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 15. Builder class hierarchy&lt;br /&gt;&lt;br /&gt;Figure 'Builder classes in actual code' shows the methods of the classes. To generate report we need to first Create a new report, set the report type (to EXCEL or PDF) , set report headers , set the report footers and finally get the report. We have defined two custom builders one for 'PDF' (ReportPDF) and other for 'EXCEL' (ReportExcel). These two custom builders define there own process according to the report type.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_17" spid="_x0000_i1037" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Builderclassesinactualcode.jpg" style="'width:426.75pt;height:310.5pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image021.jpg" title="Builderclassesinactualcode"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image022.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Builderclassesinactualcode.jpg" shapes="Picture_x0020_17" width="569" border="0" height="414" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 16. Builder classes in actual code&lt;br /&gt;&lt;br /&gt;Now let's understand how director will work. Class 'clsDirector' takes the builder and calls the individual method process in a sequential manner. So director is like a driver who takes all the individual processes and calls them in sequential manner to generate the final product, which is the report in this case. Figure 'Director in action' shows how the method 'MakeReport' calls the individual process to generate the report product by PDF or EXCEL.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_18" spid="_x0000_i1036" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Directorinaction.jpg" style="'width:425.25pt;height:189pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image023.jpg" title="Directorinaction"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image024.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Directorinaction.jpg" shapes="Picture_x0020_18" width="567" border="0" height="252" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 17. Director in action&lt;br /&gt;&lt;br /&gt;The third component in the builder is the product which is nothing but the report class in this case.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_19" spid="_x0000_i1035" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Thereportclass.jpg" style="'width:326.25pt;height:131.25pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image025.jpg" title="Thereportclass"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image025.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Thereportclass.jpg" shapes="Picture_x0020_19" width="435" border="0" height="175" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 18. The report class&lt;br /&gt;&lt;br /&gt;Now let's take a top view of the builder project. Figure 'Client,builder,director and product' shows how they work to achieve the builder pattern. Client creates the object of the director class and passes the appropriate builder to initialize the product. Depending on the builder the product is initialized/created and finally sent to the client.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_20" spid="_x0000_i1034" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Clientbuilderdirector.jpg" style="'width:445.5pt;height:438.75pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image026.jpg" title="Clientbuilderdirector"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image027.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Clientbuilderdirector.jpg" shapes="Picture_x0020_20" width="594" border="0" height="585" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 19. Client, builder, director and product&lt;br /&gt;&lt;br /&gt;The output is something like this. We can see two report types displayed with their headers according to the builder.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_21" spid="_x0000_i1033" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Finaloutputofbuilder.jpg" style="'width:266.25pt;height:160.5pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image028.jpg" title="Finaloutputofbuilder"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image028.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Finaloutputofbuilder.jpg" shapes="Picture_x0020_21" width="355" border="0" height="214" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 20. Final output of builder&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Can you explain prototype pattern ?&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;Prototype pattern falls in the section of creational pattern. It gives us a way to create new objects from the existing instance of the object. In one sentence we clone the existing object with its data. By cloning any changes to the cloned object does not affect the original object value. If you are thinking by just setting objects we can get a clone then you have mistaken it. By setting one object to other object we set the reference of object BYREF. So changing the new object also changed the original object. To understand the BYREF fundamental more clearly consider the figure 'BYREF' below. Following is the sequence of the below code:&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ul type="disc"&gt;&lt;li class="MsoNormal" style="margin-bottom: 12pt; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;In the first      step we have created the first object i.e. obj1 from class1. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin-bottom: 12pt; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;In the second      step we have created the second object i.e. obj2 from class1. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin-bottom: 12pt; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;In the third      step we set the values of the old object i.e. obj1 to 'old value'. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin-bottom: 12pt; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;In the fourth      step we set the obj1 to obj2. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="margin-bottom: 12pt; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;In the fifth      step we change the obj2 value. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;Now we display      both the values and we have found that both the objects have the new      value.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;p class="MsoNormal" style="line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_22" spid="_x0000_i1032" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/BYREf.jpg" style="'width:459pt;height:2in;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image029.jpg" title="BYREf"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image030.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/BYREf.jpg" shapes="Picture_x0020_22" width="612" border="0" height="192" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 21. BYREf&lt;br /&gt;&lt;br /&gt;The conclusion of the above example is that objects when set to other objects are set BYREF. So changing new object values also changes the old object value.&lt;br /&gt;&lt;br /&gt;There are many instances when we want the new copy object changes should not affect the old object. The answer to this is prototype patterns.&lt;br /&gt;&lt;br /&gt;Lets look how we can achieve the same using C#. In the below figure 'Prototype in action' we have the customer class 'ClsCustomer' which needs to be cloned. This can be achieved in C# my using the 'MemberWiseClone' method. In JAVA we have the 'Clone' method to achieve the same. In the same code we have also shown the client code. We have created two objects of the customer class 'obj1' and 'obj2'. Any changes to 'obj2' will not affect 'obj1' as it's a complete cloned copy.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_23" spid="_x0000_i1031" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Prototypeinaction.jpg" style="'width:475.5pt;height:303pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image031.jpg" title="Prototypeinaction"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image031.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Prototypeinaction.jpg" shapes="Picture_x0020_23" width="634" border="0" height="404" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 22. Prototype in action&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; : You can get the above sample in the CD in 'Prototype' folder. In C# we use the 'MemberWiseClone' function while in JAVA we have the 'Clone' function to achieve the same.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;i&gt;(A) Can you explain shallow copy and deep copy in prototype patterns ?&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;There are two types of cloning for prototype patterns. One is the shallow cloning which you have just read in the first question. In shallow copy only that object is cloned, any objects containing in that object is not cloned. For instance consider the figure 'Deep cloning in action' we have a customer class and we have an address class aggregated inside the customer class. 'MemberWiseClone' will only clone the customer class 'ClsCustomer' but not the 'ClsAddress' class. So we added the 'MemberWiseClone' function in the address class also. Now when we call the 'getClone' function we call the parent cloning function and also the child cloning function, which leads to cloning of the complete object. When the parent objects are cloned with their containing objects it's called as deep cloning and when only the parent is clones its termed as shallow cloning.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_24" spid="_x0000_i1030" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Deepcloninginaction.jpg" style="'width:472.5pt;height:342pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image032.jpg" title="Deepcloninginaction"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image033.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Deepcloninginaction.jpg" shapes="Picture_x0020_24" width="630" border="0" height="456" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 23. Deep cloning in action&lt;br /&gt;&lt;b&gt;&lt;i&gt;&lt;br /&gt;(B) Can you explain singleton pattern ?&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;There are situations in a project where we want only one instance of the object to be created and shared between the clients. No client can create an instance of the object from outside. There is only one instance of the class which is shared across the clients. Below are the steps to make a singleton pattern :-&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;ol start="1" type="1"&gt;&lt;li class="MsoNormal" style="margin-bottom: 12pt; line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;Define the      constructor as private.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;li class="MsoNormal" style="line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;Define the      instances and methods as static.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;  &lt;p class="MsoNormal" style="line-height: normal;"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;Below is a code snippet of a singleton in C#. We have defined the constructor as private, defined all the instance and methods using the static keyword as shown in the below code snippet figure 'Singleton in action'. The static keyword ensures that you only one instance of the object is created and you can all the methods of the class with out creating the object. As we have made the constructor private, we need to call the class directly.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_25" spid="_x0000_i1029" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Singletoninaction.jpg" style="'width:494.25pt;height:239.25pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image034.jpg" title="Singletoninaction"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image035.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Singletoninaction.jpg" shapes="Picture_x0020_25" width="659" border="0" height="319" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 24. Singleton in action&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; : In JAVA to create singleton classes we use the STATIC keyword , so its same as in C#. You can get a sample &lt;a href="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/DP1.aspx" target="_blank"&gt;&lt;span style="color: blue;"&gt;C# code&lt;/span&gt;&lt;span style="font-size: 11pt; font-family: &amp;quot;Calibri&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: windowtext; text-decoration: none;"&gt;&lt;span style=""&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_26" spid="_x0000_i1028" type="#_x0000_t75" alt="http://images.intellitxt.com/ast/adTypes/2_bing.gif" href="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/DP1.aspx" target="&amp;quot;_blank&amp;quot;" style="'width:7.5pt;height:7.5pt;visibility:visible;" button="t"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image001.gif" title="2_bing"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;span style=""&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image001.gif" alt="http://images.intellitxt.com/ast/adTypes/2_bing.gif" shapes="Picture_x0020_26" width="10" border="0" height="10" /&gt;&lt;/span&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/a&gt; for singleton in the 'singleton' folder.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Can you explain command patterns?&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;Command pattern allows a request to exist as an object. Ok let's understand what it means. Consider the figure 'Menu and Commands' we have different actions depending on which menu is clicked. So depending on which menu is clicked we have passed a string which will have the action text in the action string. Depending on the action string we will execute the action. The bad thing about the code is it has lot of 'IF' condition which makes the coding more cryptic.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_27" spid="_x0000_i1027" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/MenuandCommands.jpg" style="'width:419.25pt;height:261.75pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image036.jpg" title="MenuandCommands"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image036.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/MenuandCommands.jpg" shapes="Picture_x0020_27" width="559" border="0" height="349" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 25. Menu and Commands&lt;br /&gt;&lt;br /&gt;Command pattern moves the above action in to objects. These objects when executed actually execute the command.&lt;br /&gt;&lt;br /&gt;As said previously every command is an object. We first prepare individual classes for every action i.e. exit, open, file and print. Al l the above actions are wrapped in to classes like Exit action is wrapped in 'clsExecuteExit' , open action is wrapped in 'clsExecuteOpen', print action is wrapped in 'clsExecutePrint' and so on. All these classes are inherited from a common interface 'IExecute'.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_28" spid="_x0000_i1026" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/ObjectsandCommand.jpg" style="'width:423.75pt;height:470.25pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image037.jpg" title="ObjectsandCommand"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image038.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/ObjectsandCommand.jpg" shapes="Picture_x0020_28" width="565" border="0" height="627" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 26. Objects and Command&lt;br /&gt;&lt;br /&gt;Using all the action classes we can now make the invoker. The main work of invoker is to map the action with the classes which have the action.&lt;br /&gt;&lt;br /&gt;So we have added all the actions in one collection i.e. the arraylist. We have exposed a method 'getCommand' which takes a string and gives back the abstract object 'IExecute'. The client code is now neat and clean. All the 'IF' conditions are now moved to the 'clsInvoker' class.&lt;br /&gt;&lt;br /&gt;&lt;span style=""&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_29" spid="_x0000_i1025" type="#_x0000_t75" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Invokerandthecleanclient.jpg" style="'width:449.25pt;height:289.5pt;visibility:visible;mso-wrap-style:square'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image039.jpg" title="Invokerandthecleanclient"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image040.jpg" alt="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Invokerandthecleanclient.jpg" shapes="Picture_x0020_29" width="599" border="0" height="386" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Figure 27. Invoker and the clean client&lt;/span&gt;&lt;span style="font-size: 12pt; font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-1307427580970488666?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/1307427580970488666/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/design-pattern.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/1307427580970488666'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/1307427580970488666'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/design-pattern.html' title='Design Pattern'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-7241043272176598532</id><published>2010-02-04T03:59:00.000-08:00</published><updated>2010-02-04T04:01:50.926-08:00</updated><title type='text'>Prototype pattern</title><content type='html'>&lt;h4&gt;&lt;span class="mw-headline" id="Prototype"&gt;Prototype&lt;/span&gt;&lt;/h4&gt; &lt;p&gt;Specify the kinds of objects to create using a prototypical instance, and create new objects by copying that prototype.&lt;/p&gt; &lt;ul&gt;&lt;li&gt;A prototype pattern is used in software development when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. This pattern is used for example when the inherent cost of creating a new object in the standard way (e.g., using the 'new' keyword) is prohibitively expensive for a given application.&lt;/li&gt;&lt;/ul&gt; &lt;ul&gt;&lt;li&gt;Implementation: Declare an abstract base class that specifies a pure virtual clone() method. Any class that needs a "polymorphic constructor" capability derives itself from the abstract base class, and implements the clone() operation.&lt;/li&gt;&lt;/ul&gt; &lt;ul&gt;&lt;li&gt;Here the client code first invokes the factory method. This factory method, depending on the parameter, finds out concrete class. On this concrete class call to the Clone() method is called and the object is returned by the factory method.&lt;/li&gt;&lt;/ul&gt; &lt;ul&gt;&lt;li&gt;This is sample code which is a sample implementation of Prototype method. We have the detailed description of all the components here. &lt;ul&gt;&lt;li&gt;"Record" class which is a pure virtual class which is having pure virtual method "Clone()".&lt;/li&gt;&lt;li&gt;"CarRecord", "BikeRecord" and "PersonRecord" as concrete implementation of "Record" class.&lt;/li&gt;&lt;li&gt;An enum RECORD_TYPE_en as one to one mapping of each concrete implementation of "Record" class.&lt;/li&gt;&lt;li&gt;"RecordFactory" class which is having Factory method "CreateRecord(...)". This method requires an enum RECORD_TYPE_en as parameter and depending on this parameter it returns the concrete implementation of "Record" class.&lt;/li&gt;&lt;/ul&gt; &lt;/li&gt;&lt;/ul&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="cpp source-cpp" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt;  &lt;span class="coMULTI"&gt;/**&lt;br /&gt;  * Implementation of Prototype Method&lt;br /&gt;  **/&lt;/span&gt;&lt;br /&gt; &lt;span class="co2"&gt;#include &lt;iostream&gt;&lt;/span&gt;&lt;br /&gt; &lt;span class="co2"&gt;#include &lt;map&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="kw2"&gt;using&lt;/span&gt; &lt;span class="kw2"&gt;namespace&lt;/span&gt; std&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="kw2"&gt;enum&lt;/span&gt; RECORD_TYPE_en&lt;br /&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;   CAR,&lt;br /&gt;   BIKE,&lt;br /&gt;   PERSON&lt;br /&gt; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="coMULTI"&gt;/**&lt;br /&gt;  * Record is the Prototype&lt;br /&gt;  */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="kw2"&gt;class&lt;/span&gt; Record&lt;br /&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span class="kw2"&gt;public&lt;/span&gt; &lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     Record&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     ~Record&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     Record&lt;span class="sy2"&gt;*&lt;/span&gt; Clone&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy1"&gt;=&lt;/span&gt;&lt;span class="nu0"&gt;0&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     &lt;span class="kw2"&gt;virtual&lt;/span&gt; &lt;span class="kw4"&gt;void&lt;/span&gt; Print&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy1"&gt;=&lt;/span&gt;&lt;span class="nu0"&gt;0&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="coMULTI"&gt;/**&lt;br /&gt;  * CarRecord is Concrete Prototype&lt;br /&gt;  */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="kw2"&gt;class&lt;/span&gt; CarRecord &lt;span class="sy4"&gt;:&lt;/span&gt; &lt;span class="kw2"&gt;public&lt;/span&gt; Record&lt;br /&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span class="kw2"&gt;private&lt;/span&gt; &lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;     string m_oStrCarName&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     u_int32_t m_ui32ID&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   &lt;span class="kw2"&gt;public&lt;/span&gt; &lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     CarRecord&lt;span class="br0"&gt;(&lt;/span&gt;string _oStrCarName,u_int32_t _ui32ID&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;       &lt;span class="sy4"&gt;:&lt;/span&gt; Record&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;, m_oStrCarName&lt;span class="br0"&gt;(&lt;/span&gt;_oStrCarName&lt;span class="br0"&gt;)&lt;/span&gt;,&lt;br /&gt;         m_ui32ID&lt;span class="br0"&gt;(&lt;/span&gt;_ui32ID&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     CarRecord&lt;span class="br0"&gt;(&lt;/span&gt;CarRecord&lt;span class="sy3"&gt;&amp;amp;&lt;/span&gt; _oCarRecord&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;       &lt;span class="sy4"&gt;:&lt;/span&gt; Record&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;       m_oStrCarName &lt;span class="sy1"&gt;=&lt;/span&gt; _oCarRecord.&lt;span class="me1"&gt;m_oStrCarName&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;       m_ui32ID &lt;span class="sy1"&gt;=&lt;/span&gt; _oCarRecord.&lt;span class="me1"&gt;m_ui32ID&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     ~CarRecord&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     Record&lt;span class="sy2"&gt;*&lt;/span&gt; Clone&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="kw3"&gt;new&lt;/span&gt; CarRecord&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="sy2"&gt;*&lt;/span&gt;&lt;span class="kw3"&gt;this&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     &lt;span class="kw4"&gt;void&lt;/span&gt; Print&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span class="kw3"&gt;cout&lt;/span&gt; &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; &lt;span class="st0"&gt;"Car Record"&lt;/span&gt; &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; endl&lt;br /&gt;         &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; &lt;span class="st0"&gt;"Name  : "&lt;/span&gt; &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; m_oStrCarName &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; endl&lt;br /&gt;         &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; &lt;span class="st0"&gt;"Number: "&lt;/span&gt; &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; m_ui32ID &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; endl &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; endl&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="coMULTI"&gt;/**&lt;br /&gt;  * BikeRecord is the Concrete Prototype&lt;br /&gt;  */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="kw2"&gt;class&lt;/span&gt; BikeRecord &lt;span class="sy4"&gt;:&lt;/span&gt; &lt;span class="kw2"&gt;public&lt;/span&gt; Record&lt;br /&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span class="kw2"&gt;private&lt;/span&gt; &lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;     string m_oStrBikeName&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     u_int32_t m_ui32ID&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   &lt;span class="kw2"&gt;public&lt;/span&gt; &lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;     BikeRecord&lt;span class="br0"&gt;(&lt;/span&gt;string _oStrBikeName,u_int32_t _ui32ID&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;       &lt;span class="sy4"&gt;:&lt;/span&gt; Record&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;, m_oStrBikeName&lt;span class="br0"&gt;(&lt;/span&gt;_oStrBikeName&lt;span class="br0"&gt;)&lt;/span&gt;,&lt;br /&gt;         m_ui32ID&lt;span class="br0"&gt;(&lt;/span&gt;_ui32ID&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     BikeRecord&lt;span class="br0"&gt;(&lt;/span&gt;BikeRecord&lt;span class="sy3"&gt;&amp;amp;&lt;/span&gt; _oBikeRecord&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;       &lt;span class="sy4"&gt;:&lt;/span&gt; Record&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;       m_oStrBikeName &lt;span class="sy1"&gt;=&lt;/span&gt; _oBikeRecord.&lt;span class="me1"&gt;m_oStrBikeName&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;       m_ui32ID &lt;span class="sy1"&gt;=&lt;/span&gt; _oBikeRecord.&lt;span class="me1"&gt;m_ui32ID&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     ~BikeRecord&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     Record&lt;span class="sy2"&gt;*&lt;/span&gt; Clone&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="kw3"&gt;new&lt;/span&gt; BikeRecord&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="sy2"&gt;*&lt;/span&gt;&lt;span class="kw3"&gt;this&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     &lt;span class="kw4"&gt;void&lt;/span&gt; Print&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span class="kw3"&gt;cout&lt;/span&gt; &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; &lt;span class="st0"&gt;"Bike Record"&lt;/span&gt; &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; endl&lt;br /&gt;         &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; &lt;span class="st0"&gt;"Name  : "&lt;/span&gt; &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; m_oStrBikeName &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; endl&lt;br /&gt;         &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; &lt;span class="st0"&gt;"Number: "&lt;/span&gt; &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; m_ui32ID &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; endl &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; endl&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="coMULTI"&gt;/**&lt;br /&gt;  * PersonRecord is the Concrete Prototype&lt;br /&gt;  */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="kw2"&gt;class&lt;/span&gt; PersonRecord &lt;span class="sy4"&gt;:&lt;/span&gt; &lt;span class="kw2"&gt;public&lt;/span&gt; Record&lt;br /&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span class="kw2"&gt;private&lt;/span&gt; &lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;     string m_oStrPersonName&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     u_int32_t m_ui32Age&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   &lt;span class="kw2"&gt;public&lt;/span&gt; &lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;     PersonRecord&lt;span class="br0"&gt;(&lt;/span&gt;string _oStrPersonName, u_int32_t _ui32Age&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;       &lt;span class="sy4"&gt;:&lt;/span&gt; Record&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;, m_oStrPersonName&lt;span class="br0"&gt;(&lt;/span&gt;_oStrPersonName&lt;span class="br0"&gt;)&lt;/span&gt;,&lt;br /&gt;         m_ui32Age&lt;span class="br0"&gt;(&lt;/span&gt;_ui32Age&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     PersonRecord&lt;span class="br0"&gt;(&lt;/span&gt;PersonRecord&lt;span class="sy3"&gt;&amp;amp;&lt;/span&gt; _oPersonRecord&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;       &lt;span class="sy4"&gt;:&lt;/span&gt; Record&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;       m_oStrPersonName &lt;span class="sy1"&gt;=&lt;/span&gt; _oPersonRecord.&lt;span class="me1"&gt;m_oStrPersonName&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;       m_ui32Age &lt;span class="sy1"&gt;=&lt;/span&gt; _oPersonRecord.&lt;span class="me1"&gt;m_ui32Age&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     ~PersonRecord&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     Record&lt;span class="sy2"&gt;*&lt;/span&gt; Clone&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="kw3"&gt;new&lt;/span&gt; PersonRecord&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="sy2"&gt;*&lt;/span&gt;&lt;span class="kw3"&gt;this&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;   &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   &lt;span class="kw4"&gt;void&lt;/span&gt; Print&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;   &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;     &lt;span class="kw3"&gt;cout&lt;/span&gt; &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; &lt;span class="st0"&gt;"Person Record"&lt;/span&gt; &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; endl&lt;br /&gt;       &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; &lt;span class="st0"&gt;"Name : "&lt;/span&gt; &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; m_oStrPersonName &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; endl&lt;br /&gt;       &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; &lt;span class="st0"&gt;"Age  : "&lt;/span&gt; &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; m_ui32Age &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; endl &lt;span class="sy1"&gt;&lt;&lt;&lt;/span&gt; endl &lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;   &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="coMULTI"&gt;/**&lt;br /&gt;  * RecordFactory is the client&lt;br /&gt;  */&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="kw2"&gt;class&lt;/span&gt; RecordFactory&lt;br /&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;   &lt;span class="kw2"&gt;private&lt;/span&gt; &lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;     map&lt;span class="sy1"&gt;&lt;&lt;/span&gt;RECORD_TYPE_en, Record&lt;span class="sy2"&gt;*&lt;/span&gt; &lt;span class="sy1"&gt;&gt;&lt;/span&gt; m_oMapRecordReference&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   &lt;span class="kw2"&gt;public&lt;/span&gt; &lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;     RecordFactory&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;       m_oMapRecordReference&lt;span class="br0"&gt;[&lt;/span&gt;CAR&lt;span class="br0"&gt;]&lt;/span&gt;  &lt;span class="sy1"&gt;=&lt;/span&gt; &lt;span class="kw3"&gt;new&lt;/span&gt; CarRecord&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;"Ferrari"&lt;/span&gt;, 5050&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;       m_oMapRecordReference&lt;span class="br0"&gt;[&lt;/span&gt;BIKE&lt;span class="br0"&gt;]&lt;/span&gt; &lt;span class="sy1"&gt;=&lt;/span&gt; &lt;span class="kw3"&gt;new&lt;/span&gt; BikeRecord&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;"Yamaha"&lt;/span&gt;, 2525&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;     m_oMapRecordReference&lt;span class="br0"&gt;[&lt;/span&gt;PERSON&lt;span class="br0"&gt;]&lt;/span&gt; &lt;span class="sy1"&gt;=&lt;/span&gt; &lt;span class="kw3"&gt;new&lt;/span&gt; PersonRecord&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;"Tom"&lt;/span&gt;, 25&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     ~RecordFactory&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span class="kw3"&gt;delete&lt;/span&gt; m_oMapRecordReference&lt;span class="br0"&gt;[&lt;/span&gt;CAR&lt;span class="br0"&gt;]&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;       &lt;span class="kw3"&gt;delete&lt;/span&gt; m_oMapRecordReference&lt;span class="br0"&gt;[&lt;/span&gt;BIKE&lt;span class="br0"&gt;]&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;       &lt;span class="kw3"&gt;delete&lt;/span&gt; m_oMapRecordReference&lt;span class="br0"&gt;[&lt;/span&gt;PERSON&lt;span class="br0"&gt;]&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;     Record&lt;span class="sy2"&gt;*&lt;/span&gt; CreateRecord&lt;span class="br0"&gt;(&lt;/span&gt;RECORD_TYPE_en enType&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;       &lt;span class="kw1"&gt;return&lt;/span&gt; m_oMapRecordReference&lt;span class="br0"&gt;[&lt;/span&gt;enType&lt;span class="br0"&gt;]&lt;/span&gt;&lt;span class="sy2"&gt;-&lt;/span&gt;&lt;span class="sy1"&gt;&gt;&lt;/span&gt;Clone&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;     &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt; &lt;span class="kw4"&gt;int&lt;/span&gt; main&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt; &lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;   RecordFactory&lt;span class="sy2"&gt;*&lt;/span&gt; poRecordFactory &lt;span class="sy1"&gt;=&lt;/span&gt; &lt;span class="kw3"&gt;new&lt;/span&gt; RecordFactory&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   Record&lt;span class="sy2"&gt;*&lt;/span&gt; poRecord&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;   poRecord &lt;span class="sy1"&gt;=&lt;/span&gt; poRecordFactory&lt;span class="sy2"&gt;-&lt;/span&gt;&lt;span class="sy1"&gt;&gt;&lt;/span&gt;CreateRecord&lt;span class="br0"&gt;(&lt;/span&gt;CAR&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;   poRecord&lt;span class="sy2"&gt;-&lt;/span&gt;&lt;span class="sy1"&gt;&gt;&lt;/span&gt;Print&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;   &lt;span class="kw3"&gt;delete&lt;/span&gt; poRecord&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   poRecord &lt;span class="sy1"&gt;=&lt;/span&gt; poRecordFactory&lt;span class="sy2"&gt;-&lt;/span&gt;&lt;span class="sy1"&gt;&gt;&lt;/span&gt;CreateRecord&lt;span class="br0"&gt;(&lt;/span&gt;BIKE&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;   poRecord&lt;span class="sy2"&gt;-&lt;/span&gt;&lt;span class="sy1"&gt;&gt;&lt;/span&gt;Print&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;   &lt;span class="kw3"&gt;delete&lt;/span&gt; poRecord&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   poRecord &lt;span class="sy1"&gt;=&lt;/span&gt; poRecordFactory&lt;span class="sy2"&gt;-&lt;/span&gt;&lt;span class="sy1"&gt;&gt;&lt;/span&gt;CreateRecord&lt;span class="br0"&gt;(&lt;/span&gt;PERSON&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;   poRecord&lt;span class="sy2"&gt;-&lt;/span&gt;&lt;span class="sy1"&gt;&gt;&lt;/span&gt;Print&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;   &lt;span class="kw3"&gt;delete&lt;/span&gt; poRecord&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;   &lt;span class="kw3"&gt;delete&lt;/span&gt; poRecordFactory&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;   &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="nu0"&gt;0&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt; &lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;p&gt;Another example:&lt;/p&gt; &lt;p&gt;To implement the pattern, declare an abstract base class that specifies a pure virtual clone() member function. Any class that needs a "polymorphic constructor" capability derives itself from the abstract base class, and implements the clone() operation.&lt;/p&gt; &lt;p&gt;The client, instead of writing code that invokes the "new" operator on a hard-wired class name, calls the clone() member function on the prototype, calls a factory member function with a parameter designating the particular concrete derived class desired, or invokes the clone() member function through some mechanism provided by another design pattern.&lt;/p&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="cpp source-cpp" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt; &lt;span class="kw2"&gt;class&lt;/span&gt; CPrototypeMonster&lt;br /&gt;&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span class="kw2"&gt;protected&lt;/span&gt;&lt;span class="sy4"&gt;:&lt;/span&gt;           &lt;br /&gt;    CString           _name&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw2"&gt;public&lt;/span&gt;&lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;    CPrototypeMonster&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    CPrototypeMonster&lt;span class="br0"&gt;(&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt; CPrototypeMonster&lt;span class="sy3"&gt;&amp;amp;&lt;/span&gt; copy &lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    ~CPrototypeMonster&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kw2"&gt;virtual&lt;/span&gt; CPrototypeMonster&lt;span class="sy2"&gt;*&lt;/span&gt;    Clone&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt;&lt;span class="sy1"&gt;=&lt;/span&gt;&lt;span class="nu0"&gt;0&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt; &lt;span class="co1"&gt;// This forces every derived class to provide an overload for this function.&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;void&lt;/span&gt;        Name&lt;span class="br0"&gt;(&lt;/span&gt; CString name &lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    CString    Name&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kw2"&gt;class&lt;/span&gt; CGreenMonster &lt;span class="sy4"&gt;:&lt;/span&gt; &lt;span class="kw2"&gt;public&lt;/span&gt; CPrototypeMonster&lt;br /&gt;&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span class="kw2"&gt;protected&lt;/span&gt;&lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;int&lt;/span&gt;         _numberOfArms&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;double&lt;/span&gt;      _slimeAvailable&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw2"&gt;public&lt;/span&gt;&lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;    CGreenMonster&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    CGreenMonster&lt;span class="br0"&gt;(&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt; CGreenMonster&lt;span class="sy3"&gt;&amp;amp;&lt;/span&gt; copy &lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    ~CGreenMonster&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kw2"&gt;virtual&lt;/span&gt; CPrototypeMonster&lt;span class="sy2"&gt;*&lt;/span&gt;    Clone&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;void&lt;/span&gt;  NumberOfArms&lt;span class="br0"&gt;(&lt;/span&gt; &lt;span class="kw4"&gt;int&lt;/span&gt; numberOfArms &lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;void&lt;/span&gt;  SlimeAvailable&lt;span class="br0"&gt;(&lt;/span&gt; &lt;span class="kw4"&gt;double&lt;/span&gt; slimeAvailable &lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;int&lt;/span&gt;         NumberOfArms&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;double&lt;/span&gt;      SlimeAvailable&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kw2"&gt;class&lt;/span&gt; CPurpleMonster &lt;span class="sy4"&gt;:&lt;/span&gt; &lt;span class="kw2"&gt;public&lt;/span&gt; CPrototypeMonster&lt;br /&gt;&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span class="kw2"&gt;protected&lt;/span&gt;&lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;int&lt;/span&gt;         _intensityOfBadBreath&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;double&lt;/span&gt;      _lengthOfWhiplikeAntenna&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw2"&gt;public&lt;/span&gt;&lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;    CPurpleMonster&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    CPurpleMonster&lt;span class="br0"&gt;(&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt; CPurpleMonster&lt;span class="sy3"&gt;&amp;amp;&lt;/span&gt; copy &lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    ~CPurpleMonster&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kw2"&gt;virtual&lt;/span&gt; CPrototypeMonster&lt;span class="sy2"&gt;*&lt;/span&gt;    Clone&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;void&lt;/span&gt;  IntensityOfBadBreath&lt;span class="br0"&gt;(&lt;/span&gt; &lt;span class="kw4"&gt;int&lt;/span&gt; intensityOfBadBreath &lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;void&lt;/span&gt;  LengthOfWhiplikeAntenna&lt;span class="br0"&gt;(&lt;/span&gt; &lt;span class="kw4"&gt;double&lt;/span&gt; lengthOfWhiplikeAntenna &lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;int&lt;/span&gt;       IntensityOfBadBreath&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;double&lt;/span&gt;    LengthOfWhiplikeAntenna&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="kw2"&gt;class&lt;/span&gt; CBellyMonster &lt;span class="sy4"&gt;:&lt;/span&gt; &lt;span class="kw2"&gt;public&lt;/span&gt; CPrototypeMonster&lt;br /&gt;&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;&lt;span class="kw2"&gt;protected&lt;/span&gt;&lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;double&lt;/span&gt;      _roomAvailableInBelly&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="kw2"&gt;public&lt;/span&gt;&lt;span class="sy4"&gt;:&lt;/span&gt;&lt;br /&gt;    CBellyMonster&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    CBellyMonster&lt;span class="br0"&gt;(&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt; CBellyMonster&lt;span class="sy3"&gt;&amp;amp;&lt;/span&gt; copy &lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    ~CBellyMonster&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kw2"&gt;virtual&lt;/span&gt; CPrototypeMonster&lt;span class="sy2"&gt;*&lt;/span&gt;    Clone&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;void&lt;/span&gt;       RoomAvailableInBelly&lt;span class="br0"&gt;(&lt;/span&gt; &lt;span class="kw4"&gt;double&lt;/span&gt; roomAvailableInBelly &lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw4"&gt;double&lt;/span&gt;     RoomAvailableInBelly&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;CPrototypeMonster&lt;span class="sy2"&gt;*&lt;/span&gt; CGreenMonster&lt;span class="sy4"&gt;::&lt;/span&gt;&lt;span class="me2"&gt;Clone&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="kw3"&gt;new&lt;/span&gt; CGreenMonster&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="sy2"&gt;*&lt;/span&gt;&lt;span class="kw3"&gt;this&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;CPrototypeMonster&lt;span class="sy2"&gt;*&lt;/span&gt; CPurpleMonster&lt;span class="sy4"&gt;::&lt;/span&gt;&lt;span class="me2"&gt;Clone&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="kw3"&gt;new&lt;/span&gt; CPurpleMonster&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="sy2"&gt;*&lt;/span&gt;&lt;span class="kw3"&gt;this&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;CPrototypeMonster&lt;span class="sy2"&gt;*&lt;/span&gt; CBellyMonster&lt;span class="sy4"&gt;::&lt;/span&gt;&lt;span class="me2"&gt;Clone&lt;/span&gt;&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw1"&gt;return&lt;/span&gt; &lt;span class="kw3"&gt;new&lt;/span&gt; CBellyMonster&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="sy2"&gt;*&lt;/span&gt;&lt;span class="kw3"&gt;this&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;p&gt;A client of one of the concrete monster classes only needs a reference (pointer) to a CPrototypeMonster class object to be able to call the ‘Clone’ function and create copies of that object. The function below demonstrates this concept:&lt;/p&gt; &lt;div dir="ltr" class="mw-geshi" style="text-align: left;"&gt; &lt;div class="cpp source-cpp" style="font-family: monospace;"&gt; &lt;pre class="de1"&gt; &lt;span class="kw4"&gt;void&lt;/span&gt; DoSomeStuffWithAMonster&lt;span class="br0"&gt;(&lt;/span&gt; &lt;span class="kw4"&gt;const&lt;/span&gt; CPrototypeMonster&lt;span class="sy2"&gt;*&lt;/span&gt; originalMonster &lt;span class="br0"&gt;)&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;{&lt;/span&gt;&lt;br /&gt;    CPrototypeMonster&lt;span class="sy2"&gt;*&lt;/span&gt; newMonster &lt;span class="sy1"&gt;=&lt;/span&gt; originalMonster&lt;span class="sy2"&gt;-&lt;/span&gt;&lt;span class="sy1"&gt;&gt;&lt;/span&gt;Clone&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    ASSERT&lt;span class="br0"&gt;(&lt;/span&gt; newMonster &lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    newMonster&lt;span class="sy2"&gt;-&lt;/span&gt;&lt;span class="sy1"&gt;&gt;&lt;/span&gt;Name&lt;span class="br0"&gt;(&lt;/span&gt;&lt;span class="st0"&gt;"MyOwnMoster"&lt;/span&gt;&lt;span class="br0"&gt;)&lt;/span&gt;&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;    &lt;span class="co1"&gt;// Add code doing all sorts of cool stuff with the monster.&lt;/span&gt;&lt;br /&gt;    &lt;span class="kw3"&gt;delete&lt;/span&gt; newMonster&lt;span class="sy4"&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span class="br0"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt; &lt;/div&gt; &lt;p&gt;Now originalMonster can be passed as a pointer to CGreenMonster, CPurpleMonster or CBellyMonster.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-7241043272176598532?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/7241043272176598532/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/prototype-pattern.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/7241043272176598532'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/7241043272176598532'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/prototype-pattern.html' title='Prototype pattern'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-1955557140093830796</id><published>2010-02-04T03:19:00.000-08:00</published><updated>2010-02-17T01:26:15.809-08:00</updated><title type='text'>Design Pattern</title><content type='html'>&lt;span style="font-size:85%;"&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  &gt;&lt;b&gt;Introduction&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;Hi friends, please do not think you get an architecture position by reading interview questions. But yes there should be some kind of reference which will help you quickly revise what are the definition. Just by reading these answers you get to a position where you are aware of the fundamentals. But if you have not really worked you will surely fail with scenario based questions. So use this as a quick revision rather than a shot cut.&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  &gt;&lt;b&gt;(B) What are design patterns ?&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;a itxtdid="17250623" target="_blank" href="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/DP1.aspx#" style="border-bottom: 1px dotted darkgreen ! important; font-weight: normal ! important; font-size: 100% ! important; text-decoration: none ! important; padding-bottom: 0px ! important; color: darkgreen ! important; background-color: transparent ! important; background-image: none; padding-top: 0pt; padding-right: 0pt; padding-left: 0pt;" classname="iAs" class="iAs"&gt;Design &lt;nobr style="font-weight: normal; font-size: 100%; color: darkgreen;" id="itxt_nobr_2_0"&gt;patterns&lt;img style="border: 0pt none ; margin: 0pt; padding: 0pt; display: inline ! important; height: 10px; width: 10px; position: relative; top: 1px; left: 1px; float: none;" name="itxt-icon-77" src="http://images.intellitxt.com/ast/adTypes/2_bing.gif" /&gt;&lt;/nobr&gt;&lt;/a&gt; are documented tried and tested solutions for recurring problems in a given context. So basically you have a problem context and the proposed solution for the same. Design patterns existed in some or other form right from the inception stage of software development. Let's say if you want to implement a sorting algorithm the first thing comes to mind is bubble sort. So the problem is sorting and solution is bubble sort. Same holds true for design patterns.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;(I) Which are the three main categories of design patterns ?&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;There are three basic classifications of patterns Creational, Structural, and Behavioral patterns.&lt;br /&gt;&lt;i&gt;&lt;br /&gt;&lt;b&gt;Creational Patterns&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Abstract Factory &lt;/i&gt;: Creates an instance of several families of classes&lt;br /&gt;&lt;i&gt;Builder&lt;/i&gt; : Separates object construction from its representation&lt;br /&gt;&lt;i&gt;Factory Method &lt;/i&gt;: Creates an instance of several derived classes&lt;br /&gt;&lt;i&gt;Prototype &lt;/i&gt;: A fully initialized instance to be copied or cloned&lt;br /&gt;&lt;i&gt;Singleton&lt;/i&gt; : A class in which only a single instance can exist&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;u&gt;Note&lt;/u&gt;&lt;/b&gt; : The best way to remember Creational pattern is by remembering ABFPS (Abraham Became First President of States).&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Structural Patterns&lt;br /&gt;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;i&gt;Adapter &lt;/i&gt;: Match interfaces of different classes .&lt;br /&gt;&lt;i&gt;Bridge &lt;/i&gt;: Separates an object's abstraction from its implementation.&lt;br /&gt;&lt;i&gt;Composite &lt;/i&gt;: A tree structure of simple and composite objects.&lt;br /&gt;&lt;i&gt;Decorator &lt;/i&gt;: Add responsibilities to objects dynamically.&lt;br /&gt;&lt;i&gt;Flyweight &lt;/i&gt;: A fine-grained instance used for efficient sharing.&lt;br /&gt;&lt;i&gt;Proxy &lt;/i&gt;: An object representing another object.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;u&gt;Note&lt;/u&gt; &lt;/b&gt;: To remember structural pattern best is (ABCDFFP)&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Behavioral Patterns&lt;br /&gt;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;i&gt;Mediator &lt;/i&gt;: Defines simplified communication between classes.&lt;br /&gt;&lt;i&gt;Memento &lt;/i&gt;: Capture and restore an object's internal state.&lt;br /&gt;&lt;i&gt;Interpreter &lt;/i&gt;: A way to include language elements in a program.&lt;br /&gt;&lt;i&gt;Iterator &lt;/i&gt;: Sequentially access the elements of a collection.&lt;br /&gt;&lt;i&gt;Chain of Resp &lt;/i&gt;: A way of passing a request between a chain of objects.&lt;br /&gt;&lt;i&gt;Command &lt;/i&gt;: Encapsulate a command request as an object.&lt;br /&gt;&lt;i&gt;State &lt;/i&gt;: Alter an object's behavior when its state changes.&lt;br /&gt;&lt;i&gt;Strategy &lt;/i&gt;: Encapsulates an algorithm inside a class.&lt;br /&gt;&lt;i&gt;Observer &lt;/i&gt;: A way of notifying change to a number of classes.&lt;br /&gt;&lt;i&gt;Template Method &lt;/i&gt;: Defer the exact steps of an algorithm to a subclass.&lt;br /&gt;&lt;i&gt;Visitor &lt;/i&gt;: Defines a new operation to a class without change.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt;: Just remember Music....... 2 MICS On TV (MMIICCSSOTV).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; : In the further section we will be covering all the above design patterns in a more detail manner.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;(A) Can you explain factory pattern ?&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;Factory pattern is one of the types of creational patterns. You can make out from the name factory itself it's meant to construct and create something. In software architecture world factory pattern is meant to centralize creation of objects. Below is a code snippet of a client which has different types of invoices. These invoices are created depending on the invoice type specified by the client. There are two issues with the code below :&lt;br /&gt;&lt;br /&gt;First we have lots of 'new' keyword scattered in the client. In other ways the client is loaded with lot of object creational activities which can make the client logic very complicated.&lt;br /&gt;&lt;br /&gt;Second issue is that the client needs to be aware of all types of invoices. So if we are adding one more invoice class type called as 'InvoiceWithFooter' we need to reference the new class in the client and recompile the client also&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  &gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/InvoiceTypes.jpg" width="386" border="0" height="159" /&gt;\&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  &gt;Figure 1. Different types of invoice&lt;br /&gt;&lt;br /&gt;Taking these issues as our base we will now look in to how factory pattern can help us solve the same. Below figure 'Factory Pattern' shows two concrete classes 'ClsInvoiceWithHeader' and 'ClsInvoiceWithOutHeader'.&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;first issue&lt;/i&gt; was that these classes are in direct contact with client which leads to lot of 'new' keyword scattered in the client code. This is removed by introducing a new class 'ClsFactoryInvoice' which does all the creation of objects.&lt;br /&gt;&lt;br /&gt;The &lt;i&gt;second issue&lt;/i&gt; was that the client code is aware of both the concrete classes i.e. 'ClsInvoiceWithHeader' and 'ClsInvoiceWithOutHeader'. This leads to recompiling of the client code when we add new invoice types. For instance if we add 'ClsInvoiceWithFooter' client code needs to be changed and recompiled accordingly. To remove this issue we have introduced a common interface 'IInvoice'. Both the concrete classes 'ClsInvoiceWithHeader' and 'ClsInvoiceWithOutHeader' inherit and implement the 'IInvoice' interface.&lt;br /&gt;&lt;br /&gt;The client references only the 'IInvoice' interface which results in zero connection between client and the concrete classes ( 'ClsInvoiceWithHeader' and 'ClsInvoiceWithOutHeader'). So now if we add new concrete invoice class we do not need to change any thing at the client side.&lt;br /&gt;&lt;br /&gt;In one line the creation of objects is taken care by 'ClsFactoryInvoice' and the client disconnection from the concrete classes is taken care by 'IInvoice' interface.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/FactoryPattern.jpg" width="690" border="0" height="374" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 2. Factory pattern&lt;br /&gt;&lt;br /&gt;Below are the code snippets of how actually factory pattern can be implemented in C#. In order to avoid recompiling the client we have introduced the invoice interface 'IInvoice'. Both the concrete classes 'ClsInvoiceWithOutHeaders' and 'ClsInvoiceWithHeader' inherit and implement the 'IInvoice' interface.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/InterfaceAndConcrete.jpg" width="612" border="0" height="418" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 3. Interface and concrete classes&lt;br /&gt;&lt;br /&gt;We have also introduced an extra class 'ClsFactoryInvoice' with a function 'getInvoice()' which will generate objects of both the invoices depending on 'intInvoiceType' value. In short we have centralized the logic of object creation in the 'ClsFactoryInvoice'. The client calls the 'getInvoice' function to generate the invoice classes. One of the most important points to be noted is that client only refers to 'IInvoice' type and the factory class 'ClsFactoryInvoice' also gives the same type of reference. This helps the client to be complete detached from the concrete classes, so now when we add new classes and invoice types we do not need to recompile the client.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/FactoryClass.jpg" width="626" border="0" height="572" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 4. Factory class which generates objects&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note : &lt;/b&gt;The above example is given in C# . Even if you are from some other technology you can still map the concept accordingly. You can get source code from the CD in 'FactoryPattern' folder.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;Can you explain abstract factory pattern ?&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Abstract factory expands on the basic factory pattern. Abstract factory helps us to unite similar factory pattern classes in to one unified interface. So basically all the common factory patterns now inherit from a common abstract factory class which unifies them in a common class. All other things related to factory pattern remain same as discussed in the previous question.&lt;br /&gt;&lt;br /&gt;A factory class helps us to centralize the creation of classes and types. Abstract factory helps us to bring uniformity between related factory patterns which leads more simplified interface for the client.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/AbstractFActory.jpg" width="404" border="0" height="156" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 5. Abstract factory unifies related factory patterns&lt;br /&gt;&lt;br /&gt;Now that we know the basic lets try to understand the details of how abstract factory patterns are actually implemented. As said previously we have the factory pattern classes (factory1 and factory2) tied up to a common abstract factory (AbstractFactory Interface) via inheritance. Factory classes stand on the top of concrete classes which are again derived from common interface. For instance in figure 'Implementation of abstract factory' both the concrete classes 'product1' and 'product2' inherits from one interface i.e. 'common'. The client who wants to use the concrete class will only interact with the abstract factory and the common interface from which the concrete classes inherit.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Implementation.jpg" width="516" border="0" height="249" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 6. Implementation of abstract factory&lt;br /&gt;&lt;br /&gt;Now let's have a look at how we can practically implement abstract factory in actual code. We have scenario where we have UI creational activities for textboxes and buttons through their own centralized factory classes 'ClsFactoryButton' and 'ClsFactoryText'. Both these classes inherit from common interface 'InterfaceRender'. Both the factories 'ClsFactoryButton' and 'ClsFactoryText' inherits from the common factory 'ClsAbstractFactory'. Figure 'Example for AbstractFactory' shows how these classes are arranged and the client code for the same. One of the important points to be noted about the client code is that it does not interact with the concrete classes. For object creation it uses the abstract factory ( ClsAbstractFactory ) and for calling the concrete class implementation it calls the methods via the interface 'InterfaceRender'. So the 'ClsAbstractFactory' class provides a common interface for both factories 'ClsFactoryButton' and 'ClsFactoryText'.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Exampleforabstract.jpg" width="702" border="0" height="535" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 7. Example for abstract factory&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt;: We have provided a code sample in C# in the 'AbstractFactory' folder. People who are from different technology can compare easily the implementation in their own language.&lt;br /&gt;&lt;br /&gt;We will just run through the sample code for abstract factory. Below code snippet 'Abstract factory and factory code snippet' shows how the factory pattern classes inherit from abstract factory.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Abstractfactoryandfactorycode.jpg" width="937" border="0" height="485" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 8. Abstract factory and factory code snippet&lt;br /&gt;&lt;br /&gt;Figure 'Common Interface for concrete classes' how the concrete classes inherits from a common interface 'InterFaceRender' which enforces the method 'render' in all the concrete classes.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Commoninterface.jpg" width="943" border="0" height="287" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 9. Common interface for concrete classes&lt;br /&gt;&lt;br /&gt;The final thing is the client code which uses the interface 'InterfaceRender' and abstract factory 'ClsAbstractFactory' to call and create the objects. One of the important points about the code is that it is completely isolated from the concrete classes. Due to this any changes in concrete classes like adding and removing concrete classes does not need client level changes.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Clientinterface.jpg" width="539" border="0" height="242" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 10. Client, interface and abstract factory&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Can you explain builder pattern?&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Builder falls under the type of creational pattern category. Builder pattern helps us to separate the construction of a complex object from its representation so that the same construction process can create different representations. Builder pattern is useful when the construction of the object is very complex. The main objective is to separate the construction of objects and their representations. If we are able to separate the construction and representation, we can then get many representations from the same construction.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Builderconcept.jpg" width="350" border="0" height="120" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 11. Builder concept&lt;br /&gt;&lt;br /&gt;To understand what we mean by construction and representation lets take the example of the below 'Tea preparation' sequence.&lt;br /&gt;&lt;br /&gt;You can see from the figure 'Tea preparation' from the same preparation steps we can get three representation of tea's (i.e. Tea with out sugar, tea with sugar / milk and tea with out milk).&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Teapreparation.jpg" width="498" border="0" height="451" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 12. Tea preparation&lt;br /&gt;&lt;br /&gt;Now let's take a real time example in software world to see how builder can separate the complex creation and its representation. Consider we have application where we need the same report to be displayed in either 'PDF' or 'EXCEL' format. Figure 'Request a report' shows the series of steps to achieve the same. Depending on report type a new report is created, report type is set, headers and footers of the report are set and finally we get the report for display.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Requestreport.jpg" width="290" border="0" height="424" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 13. Request a report&lt;br /&gt;&lt;br /&gt;Now let's take a different view of the problem as shown in figure 'Different View'. The same flow defined in 'Request a report' is now analyzed in representations and common construction. The construction process is same for both the types of reports but they result in different representations.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/DifferentView.jpg" width="463" border="0" height="374" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 14. Different View&lt;br /&gt;&lt;br /&gt;We will take the same report problem and try to solve the same using builder patterns. There are three main parts when you want to implement builder patterns.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Builder &lt;/i&gt;: Builder is responsible for defining the construction process for individual parts. Builder has those individual processes to initialize and configure the product.&lt;br /&gt;&lt;i&gt;Director &lt;/i&gt;: Director takes those individual processes from the builder and defines the sequence to build the product.&lt;br /&gt;&lt;i&gt;Product&lt;/i&gt; : Product is the final object which is produced from the builder and director coordination.&lt;br /&gt;&lt;br /&gt;First let's have a look at the builder class hierarchy. We have a abstract class called as 'ReportBuilder' from which custom builders like 'ReportPDF' builder and 'ReportEXCEL' builder will be built.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Builderclasshierarchy.jpg" width="340" border="0" height="186" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 15. Builder class hierarchy&lt;br /&gt;&lt;br /&gt;Figure 'Builder classes in actual code' shows the methods of the classes. To generate report we need to first Create a new report, set the report type (to EXCEL or PDF) , set report headers , set the report footers and finally get the report. We have defined two custom builders one for 'PDF' (ReportPDF) and other for 'EXCEL' (ReportExcel). These two custom builders define there own process according to the report type.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Builderclassesinactualcode.jpg" width="855" border="0" height="414" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 16. Builder classes in actual code&lt;br /&gt;&lt;br /&gt;Now let's understand how director will work. Class 'clsDirector' takes the builder and calls the individual method process in a sequential manner. So director is like a driver who takes all the individual processes and calls them in sequential manner to generate the final product, which is the report in this case. Figure 'Director in action' shows how the method 'MakeReport' calls the individual process to generate the report product by PDF or EXCEL.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Directorinaction.jpg" width="887" border="0" height="252" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 17. Director in action&lt;br /&gt;&lt;br /&gt;The third component in the builder is the product which is nothing but the report class in this case.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Thereportclass.jpg" width="435" border="0" height="175" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 18. The report class&lt;br /&gt;&lt;br /&gt;Now let's take a top view of the builder project. Figure 'Client,builder,director and product' shows how they work to achieve the builder pattern. Client creates the object of the director class and passes the appropriate builder to initialize the product. Depending on the builder the product is initialized/created and finally sent to the client.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Clientbuilderdirector.jpg" width="950" border="0" height="586" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 19. Client, builder, director and product&lt;br /&gt;&lt;br /&gt;The output is something like this. We can see two report types displayed with their headers according to the builder.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Finaloutputofbuilder.jpg" width="355" border="0" height="214" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 20. Final output of builder&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Can you explain prototype pattern ?&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;Prototype pattern falls in the section of creational pattern. It gives us a way to create new objects from the existing instance of the object. In one sentence we clone the existing object with its data. By cloning any changes to the cloned object does not affect the original object value. If you are thinking by just setting objects we can get a clone then you have mistaken it. By setting one object to other object we set the reference of object BYREF. So changing the new object also changed the original object. To understand the BYREF fundamental more clearly consider the figure 'BYREF' below. Following is the sequence of the below code:&lt;br /&gt;&lt;/span&gt;&lt;/span&gt; &lt;ul&gt;&lt;span style="font-size:85%;"&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  &gt;&lt;li&gt;In the first step we have created the first object i.e. obj1 from class1.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;In the second step we have created the second object i.e. obj2 from class1.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;In the third step we set the values of the old object i.e. obj1 to 'old value'.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;In the fourth step we set the obj1 to obj2.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;In the fifth step we change the obj2 value.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Now we display both the values and we have found that both the objects have the new value.&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;&lt;/ul&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  &gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/BYREf.jpg" width="789" border="0" height="192" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 21. BYREf&lt;br /&gt;&lt;br /&gt;The conclusion of the above example is that objects when set to other objects are set BYREF. So changing new object values also changes the old object value.&lt;br /&gt;&lt;br /&gt;There are many instances when we want the new copy object changes should not affect the old object. The answer to this is prototype patterns.&lt;br /&gt;&lt;br /&gt;Lets look how we can achieve the same using C#. In the below figure 'Prototype in action' we have the customer class 'ClsCustomer' which needs to be cloned. This can be achieved in C# my using the 'MemberWiseClone' method. In JAVA we have the 'Clone' method to achieve the same. In the same code we have also shown the client code. We have created two objects of the customer class 'obj1' and 'obj2'. Any changes to 'obj2' will not affect 'obj1' as it's a complete cloned copy.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Prototypeinaction.jpg" width="634" border="0" height="404" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 22. Prototype in action&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; : You can get the above sample in the CD in 'Prototype' folder. In C# we use the 'MemberWiseClone' function while in JAVA we have the 'Clone' function to achieve the same.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;(A) Can you explain shallow copy and deep copy in prototype patterns ?&lt;br /&gt;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;There are two types of cloning for prototype patterns. One is the shallow cloning which you have just read in the first question. In shallow copy only that object is cloned, any objects containing in that object is not cloned. For instance consider the figure 'Deep cloning in action' we have a customer class and we have an address class aggregated inside the customer class. 'MemberWiseClone' will only clone the customer class 'ClsCustomer' but not the 'ClsAddress' class. So we added the 'MemberWiseClone' function in the address class also. Now when we call the 'getClone' function we call the parent cloning function and also the child cloning function, which leads to cloning of the complete object. When the parent objects are cloned with their containing objects it's called as deep cloning and when only the parent is clones its termed as shallow cloning.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Deepcloninginaction.jpg" width="717" border="0" height="456" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 23. Deep cloning in action&lt;br /&gt;&lt;i&gt;&lt;b&gt;&lt;br /&gt;(B) Can you explain singleton pattern ?&lt;br /&gt;&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;There are situations in a project where we want only one instance of the object to be created and shared between the clients. No client can create an instance of the object from outside. There is only one instance of the class which is shared across the clients. Below are the steps to make a singleton pattern :-&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;ol&gt;&lt;span style="font-size:85%;"&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  &gt;&lt;li&gt;Define the constructor as private.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Define the instances and methods as static.&lt;/li&gt;&lt;/span&gt;&lt;/span&gt;&lt;/ol&gt; &lt;p&gt;&lt;span style="font-size:85%;"&gt;&lt;span style=";font-family:Verdana;font-size:85%;"  &gt;Below is a code snippet of a singleton in C#. We have defined the constructor as private, defined all the instance and methods using the static keyword as shown in the below code snippet figure 'Singleton in action'. The static keyword ensures that you only one instance of the object is created and you can all the methods of the class with out creating the object. As we have made the constructor private, we need to call the class directly.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Singletoninaction.jpg" width="961" border="0" height="319" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 24. Singleton in action&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Note&lt;/b&gt; : In JAVA to create singleton classes we use the STATIC keyword , so its same as in C#. You can get a sample &lt;a itxtdid="17250323" target="_blank" href="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/DP1.aspx#" style="border-bottom: 1px dotted darkgreen ! important; font-weight: normal ! important; font-size: 100% ! important; text-decoration: none ! important; padding-bottom: 0px ! important; color: darkgreen ! important; background-color: transparent ! important; background-image: none; padding-top: 0pt; padding-right: 0pt; padding-left: 0pt;" classname="iAs" class="iAs"&gt;C# &lt;nobr style="font-weight: normal; font-size: 100%; color: darkgreen;" id="itxt_nobr_72_0"&gt;code&lt;img style="border: 0pt none ; margin: 0pt; padding: 0pt; display: inline ! important; height: 10px; width: 10px; position: relative; top: 1px; left: 1px; float: none;" name="itxt-icon-77" src="http://images.intellitxt.com/ast/adTypes/2_bing.gif" /&gt;&lt;/nobr&gt;&lt;/a&gt; for singleton in the 'singleton' folder.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Can you explain command patterns?&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;Command pattern allows a request to exist as an object. Ok let's understand what it means. Consider the figure 'Menu and Commands' we have different actions depending on which menu is clicked. So depending on which menu is clicked we have passed a string which will have the action text in the action string. Depending on the action string we will execute the action. The bad thing about the code is it has lot of 'IF' condition which makes the coding more cryptic.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/MenuandCommands.jpg" width="559" border="0" height="349" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 25. Menu and Commands&lt;br /&gt;&lt;br /&gt;Command pattern moves the above action in to objects. These objects when executed actually execute the command.&lt;br /&gt;&lt;br /&gt;As said previously every command is an object. We first prepare individual classes for every action i.e. exit, open, file and print. Al l the above actions are wrapped in to classes like Exit action is wrapped in 'clsExecuteExit' , open action is wrapped in 'clsExecuteOpen', print action is wrapped in 'clsExecutePrint' and so on. All these classes are inherited from a common interface 'IExecute'.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/ObjectsandCommand.jpg" width="759" border="0" height="627" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 26. Objects and Command&lt;br /&gt;&lt;br /&gt;Using all the action classes we can now make the invoker. The main work of invoker is to map the action with the classes which have the action.&lt;br /&gt;&lt;br /&gt;So we have added all the actions in one collection i.e. the arraylist. We have exposed a method 'getCommand' which takes a string and gives back the abstract object 'IExecute'. The client code is now neat and clean. All the 'IF' conditions are now moved to the 'clsInvoker' class.&lt;br /&gt;&lt;br /&gt;&lt;img src="http://www.c-sharpcorner.com/UploadFile/questpond/DP109212008014904AM/Images/Invokerandthecleanclient.jpg" width="971" border="0" height="386" /&gt;&lt;br /&gt;&lt;br /&gt;Figure 27. Invoker and the clean client&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-1955557140093830796?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/1955557140093830796/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/introduction-hi-friends-please-do-not.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/1955557140093830796'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/1955557140093830796'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/introduction-hi-friends-please-do-not.html' title='Design Pattern'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-539526546915356763</id><published>2010-02-04T03:12:00.000-08:00</published><updated>2010-02-04T03:14:25.563-08:00</updated><title type='text'>composition and aggregation</title><content type='html'>&lt;meta equiv="Content-Type" content="text/html; charset=utf-8"&gt;&lt;meta name="ProgId" content="Word.Document"&gt;&lt;meta name="Generator" content="Microsoft Word 12"&gt;&lt;meta name="Originator" content="Microsoft Word 12"&gt;&lt;link rel="File-List" href="file:///C:%5CDOCUME%7E1%5Cz063380%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml"&gt;&lt;link rel="Edit-Time-Data" href="file:///C:%5CDOCUME%7E1%5Cz063380%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_editdata.mso"&gt;&lt;!--[if !mso]&gt; &lt;style&gt; v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} &lt;/style&gt; &lt;![endif]--&gt;&lt;link rel="themeData" href="file:///C:%5CDOCUME%7E1%5Cz063380%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx"&gt;&lt;link rel="colorSchemeMapping" href="file:///C:%5CDOCUME%7E1%5Cz063380%5CLOCALS%7E1%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml"&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:worddocument&gt;   &lt;w:view&gt;Normal&lt;/w:View&gt;   &lt;w:zoom&gt;0&lt;/w:Zoom&gt;   &lt;w:trackmoves/&gt;   &lt;w:trackformatting/&gt;   &lt;w:punctuationkerning/&gt;   &lt;w:validateagainstschemas/&gt;   &lt;w:saveifxmlinvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;   &lt;w:ignoremixedcontent&gt;false&lt;/w:IgnoreMixedContent&gt;   &lt;w:alwaysshowplaceholdertext&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;   &lt;w:donotpromoteqf/&gt;   &lt;w:lidthemeother&gt;EN-US&lt;/w:LidThemeOther&gt;   &lt;w:lidthemeasian&gt;X-NONE&lt;/w:LidThemeAsian&gt;   &lt;w:lidthemecomplexscript&gt;X-NONE&lt;/w:LidThemeComplexScript&gt;   &lt;w:compatibility&gt;    &lt;w:breakwrappedtables/&gt;    &lt;w:snaptogridincell/&gt;    &lt;w:wraptextwithpunct/&gt;    &lt;w:useasianbreakrules/&gt;    &lt;w:dontgrowautofit/&gt;    &lt;w:splitpgbreakandparamark/&gt;    &lt;w:dontvertaligncellwithsp/&gt;    &lt;w:dontbreakconstrainedforcedtables/&gt;    &lt;w:dontvertalignintxbx/&gt;    &lt;w:word11kerningpairs/&gt;    &lt;w:cachedcolbalance/&gt;   &lt;/w:Compatibility&gt;   &lt;w:browserlevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;   &lt;m:mathpr&gt;    &lt;m:mathfont val="Cambria Math"&gt;    &lt;m:brkbin val="before"&gt;    &lt;m:brkbinsub val="&amp;#45;-"&gt;    &lt;m:smallfrac val="off"&gt;    &lt;m:dispdef/&gt;    &lt;m:lmargin val="0"&gt;    &lt;m:rmargin val="0"&gt;    &lt;m:defjc val="centerGroup"&gt;    &lt;m:wrapindent val="1440"&gt;    &lt;m:intlim val="subSup"&gt;    &lt;m:narylim val="undOvr"&gt;   &lt;/m:mathPr&gt;&lt;/w:WordDocument&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;  &lt;w:latentstyles deflockedstate="false" defunhidewhenused="true" defsemihidden="true" defqformat="false" defpriority="99" latentstylecount="267"&gt;   &lt;w:lsdexception locked="false" priority="0" semihidden="false" unhidewhenused="false" qformat="true" name="Normal"&gt;   &lt;w:lsdexception locked="false" priority="9" semihidden="false" unhidewhenused="false" qformat="true" name="heading 1"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 2"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 3"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 4"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 5"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 6"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 7"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 8"&gt;   &lt;w:lsdexception locked="false" priority="9" qformat="true" name="heading 9"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 1"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 2"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 3"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 4"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 5"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 6"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 7"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 8"&gt;   &lt;w:lsdexception locked="false" priority="39" name="toc 9"&gt;   &lt;w:lsdexception locked="false" priority="35" qformat="true" name="caption"&gt;   &lt;w:lsdexception locked="false" priority="10" semihidden="false" unhidewhenused="false" qformat="true" name="Title"&gt;   &lt;w:lsdexception locked="false" priority="1" name="Default Paragraph Font"&gt;   &lt;w:lsdexception locked="false" priority="11" semihidden="false" unhidewhenused="false" qformat="true" name="Subtitle"&gt;   &lt;w:lsdexception locked="false" priority="22" semihidden="false" unhidewhenused="false" qformat="true" name="Strong"&gt;   &lt;w:lsdexception locked="false" priority="20" semihidden="false" unhidewhenused="false" qformat="true" name="Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="59" semihidden="false" unhidewhenused="false" name="Table Grid"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Placeholder Text"&gt;   &lt;w:lsdexception locked="false" priority="1" semihidden="false" unhidewhenused="false" qformat="true" name="No Spacing"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" unhidewhenused="false" name="Revision"&gt;   &lt;w:lsdexception locked="false" priority="34" semihidden="false" unhidewhenused="false" qformat="true" name="List Paragraph"&gt;   &lt;w:lsdexception locked="false" priority="29" semihidden="false" unhidewhenused="false" qformat="true" name="Quote"&gt;   &lt;w:lsdexception locked="false" priority="30" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Quote"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 1"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 2"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 3"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 4"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 5"&gt;   &lt;w:lsdexception locked="false" priority="60" semihidden="false" unhidewhenused="false" name="Light Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="61" semihidden="false" unhidewhenused="false" name="Light List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="62" semihidden="false" unhidewhenused="false" name="Light Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="63" semihidden="false" unhidewhenused="false" name="Medium Shading 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="64" semihidden="false" unhidewhenused="false" name="Medium Shading 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="65" semihidden="false" unhidewhenused="false" name="Medium List 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="66" semihidden="false" unhidewhenused="false" name="Medium List 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="67" semihidden="false" unhidewhenused="false" name="Medium Grid 1 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="68" semihidden="false" unhidewhenused="false" name="Medium Grid 2 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="69" semihidden="false" unhidewhenused="false" name="Medium Grid 3 Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="70" semihidden="false" unhidewhenused="false" name="Dark List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="71" semihidden="false" unhidewhenused="false" name="Colorful Shading Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="72" semihidden="false" unhidewhenused="false" name="Colorful List Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="73" semihidden="false" unhidewhenused="false" name="Colorful Grid Accent 6"&gt;   &lt;w:lsdexception locked="false" priority="19" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="21" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Emphasis"&gt;   &lt;w:lsdexception locked="false" priority="31" semihidden="false" unhidewhenused="false" qformat="true" name="Subtle Reference"&gt;   &lt;w:lsdexception locked="false" priority="32" semihidden="false" unhidewhenused="false" qformat="true" name="Intense Reference"&gt;   &lt;w:lsdexception locked="false" priority="33" semihidden="false" unhidewhenused="false" qformat="true" name="Book Title"&gt;   &lt;w:lsdexception locked="false" priority="37" name="Bibliography"&gt;   &lt;w:lsdexception locked="false" priority="39" qformat="true" name="TOC Heading"&gt;  &lt;/w:LatentStyles&gt; &lt;/xml&gt;&lt;![endif]--&gt;&lt;style&gt; &lt;!--  /* Font Definitions */  @font-face 	{font-family:"Cambria Math"; 	panose-1:2 4 5 3 5 4 6 3 2 4; 	mso-font-alt:"Calisto MT"; 	mso-font-charset:0; 	mso-generic-font-family:roman; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1107304683 0 0 159 0;} @font-face 	{font-family:Calibri; 	panose-1:2 15 5 2 2 2 4 3 2 4; 	mso-font-alt:"Times New Roman"; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face 	{font-family:Verdana; 	panose-1:2 11 6 4 3 5 4 4 2 4; 	mso-font-charset:0; 	mso-generic-font-family:swiss; 	mso-font-pitch:variable; 	mso-font-signature:536871559 0 0 0 415 0;}  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal 	{mso-style-unhide:no; 	mso-style-qformat:yes; 	mso-style-parent:""; 	margin:0in; 	margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-bidi-font-family:"Times New Roman";} a:link, span.MsoHyperlink 	{mso-style-noshow:yes; 	mso-style-priority:99; 	color:blue; 	text-decoration:underline; 	text-underline:single;} a:visited, span.MsoHyperlinkFollowed 	{mso-style-noshow:yes; 	mso-style-priority:99; 	color:purple; 	mso-themecolor:followedhyperlink; 	text-decoration:underline; 	text-underline:single;} p 	{mso-style-noshow:yes; 	mso-style-priority:99; 	mso-margin-top-alt:auto; 	margin-right:0in; 	mso-margin-bottom-alt:auto; 	margin-left:0in; 	mso-pagination:widow-orphan; 	font-size:12.0pt; 	font-family:"Times New Roman","serif"; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin;} .MsoChpDefault 	{mso-style-type:export-only; 	mso-default-props:yes; 	font-size:10.0pt; 	mso-ansi-font-size:10.0pt; 	mso-bidi-font-size:10.0pt;} @page Section1 	{size:8.5in 11.0in; 	margin:1.0in 1.0in 1.0in 1.0in; 	mso-header-margin:.5in; 	mso-footer-margin:.5in; 	mso-paper-source:0;} div.Section1 	{page:Section1;} --&gt; &lt;/style&gt;&lt;!--[if gte mso 10]&gt; &lt;style&gt;  /* Style Definitions */  table.MsoNormalTable 	{mso-style-name:"Table Normal"; 	mso-tstyle-rowband-size:0; 	mso-tstyle-colband-size:0; 	mso-style-noshow:yes; 	mso-style-priority:99; 	mso-style-qformat:yes; 	mso-style-parent:""; 	mso-padding-alt:0in 5.4pt 0in 5.4pt; 	mso-para-margin:0in; 	mso-para-margin-bottom:.0001pt; 	mso-pagination:widow-orphan; 	font-size:11.0pt; 	font-family:"Calibri","sans-serif"; 	mso-ascii-font-family:Calibri; 	mso-ascii-theme-font:minor-latin; 	mso-fareast-font-family:Calibri; 	mso-fareast-theme-font:minor-latin; 	mso-hansi-font-family:Calibri; 	mso-hansi-theme-font:minor-latin; 	mso-bidi-font-family:"Times New Roman"; 	mso-bidi-theme-font:minor-bidi;} &lt;/style&gt; &lt;![endif]--&gt;  &lt;p&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;Introduction:&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;Apart from programming, a lot of my spare time sat at the computer is spent reading group, &lt;a href="http://www.c-sharpcorner.com/UploadFile/pcurnow/compagg07272007062838AM/compagg.aspx" target="_blank"&gt;blog&lt;/a&gt; postings, etc from other developers. One particular posting that caught my eye recently provoked a lot of response and mixed answers to a question posed by a poster. This question was, 'What is the difference between composition and aggregation and how would I express it in my programs'?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;Reading the responses to the post, I had a mixed reaction, many of the responses reflected my understanding of the difference, others turned my understanding right around and explained composition as my understanding of aggregation.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;This short article will put forward my understanding of composition and aggregation and how I would express it in &lt;a href="http://www.c-sharpcorner.com/UploadFile/pcurnow/compagg07272007062838AM/compagg.aspx" target="_blank"&gt;C# code&lt;span style="text-decoration: none;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shapetype id="_x0000_t75" coordsize="21600,21600" spt="75" preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"&gt;  &lt;v:stroke joinstyle="miter"&gt;  &lt;v:formulas&gt;   &lt;v:f eqn="if lineDrawn pixelLineWidth 0"&gt;   &lt;v:f eqn="sum @0 1 0"&gt;   &lt;v:f eqn="sum 0 0 @1"&gt;   &lt;v:f eqn="prod @2 1 2"&gt;   &lt;v:f eqn="prod @3 21600 pixelWidth"&gt;   &lt;v:f eqn="prod @3 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @0 0 1"&gt;   &lt;v:f eqn="prod @6 1 2"&gt;   &lt;v:f eqn="prod @7 21600 pixelWidth"&gt;   &lt;v:f eqn="sum @8 21600 0"&gt;   &lt;v:f eqn="prod @7 21600 pixelHeight"&gt;   &lt;v:f eqn="sum @10 21600 0"&gt;  &lt;/v:formulas&gt;  &lt;v:path extrusionok="f" gradientshapeok="t" connecttype="rect"&gt;  &lt;o:lock ext="edit" aspectratio="t"&gt; &lt;/v:shapetype&gt;&lt;v:shape id="Picture_x0020_1" spid="_x0000_i1025" type="#_x0000_t75" alt="http://images.intellitxt.com/ast/adTypes/2_bing.gif" style="'width:7.5pt;"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image001.gif" href="cid:image001.gif@01CAA5B7.290B6010"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image001.gif" alt="http://images.intellitxt.com/ast/adTypes/2_bing.gif" shapes="Picture_x0020_1" width="10" border="0" height="10" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;/a&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;Composition:&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;As we know, inheritance gives us an 'is-a' relationship. To make the understanding of composition easier, we can say that composition gives us a 'part-of' relationship. Composition is shown on a UML diagram as a filled diamond (see Figure 1).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="text-align: center;" align="center"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_2" spid="_x0000_i1026" type="#_x0000_t75" alt="Figure 1 - Composition" style="'width:198pt;height:63pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image002.png" href="cid:image002.png@01CAA5B7.290B6010"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image003.gif" alt="Figure 1 - Composition" shapes="Picture_x0020_2" width="264" border="0" height="84" /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;If we were going to model a car, it would make sense to say that an engine is part-of a car. Within composition, the lifetime of the part (Engine) is managed by the whole (Car), in other words, when Car is destroyed, Engine is destroyed along with it. So how do we express this in &lt;a href="http://www.c-sharpcorner.com/UploadFile/pcurnow/compagg07272007062838AM/compagg.aspx" target="_blank"&gt;C#&lt;/a&gt;? &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;public class&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: teal;"&gt;Engine&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;{&lt;br /&gt; . . .&lt;br /&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;public&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;class&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: teal;"&gt;Car&lt;/span&gt;&lt;span style="font-size: 12pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;{&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;    Engine e = &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;new&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt; Engine();&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;    .......&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;As you can see in the example code above, Car manages the lifetime of Engine. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;Aggregation:&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;If inheritance gives us 'is-a' and composition gives us 'part-of', we could argue that aggregation gives us a 'has-a' relationship. Within aggregation, the lifetime of the part is not managed by the whole. To make this clearer, we need an example. For the past 12+ months I have been involved with the implementation of a &lt;a href="http://www.c-sharpcorner.com/UploadFile/pcurnow/compagg07272007062838AM/compagg.aspx" target="_blank"&gt;CRM&lt;span style="text-decoration: none;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_3" spid="_x0000_i1027" type="#_x0000_t75" alt="http://images.intellitxt.com/ast/adTypes/2_bing.gif" style="'width:7.5pt;height:7.5pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image001.gif" href="cid:image001.gif@01CAA5B7.290B6010"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image001.gif" alt="http://images.intellitxt.com/ast/adTypes/2_bing.gif" shapes="Picture_x0020_3" width="10" border="0" height="10" /&gt;&lt;!--[endif]--&gt;&lt;/span&gt;&lt;/a&gt; system, so I am going to use part of this as an example. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;The CRM system has a &lt;a href="http://www.c-sharpcorner.com/UploadFile/pcurnow/compagg07272007062838AM/compagg.aspx" target="_blank"&gt;database&lt;/a&gt; of customers and a separate database that holds all addresses within a geographic area. Aggregation would make sense in this situation, as a Customer 'has-a' Address. It wouldn't make sense to say that an Address is 'part-of' the Customer, because it isn't. Consider it this way, if the customer ceases to exist, does the address? I would argue that it does not cease to exist. Aggregation is shown on a UML diagram as an unfilled diamond (see Figure 2). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="text-align: center;" align="center"&gt;&lt;span style="font-size: 10pt;"&gt;&lt;!--[if gte vml 1]&gt;&lt;v:shape id="Picture_x0020_4" spid="_x0000_i1028" type="#_x0000_t75" alt="Figure 2 - Aggregation" style="'width:198pt;height:63pt'"&gt;  &lt;v:imagedata src="file:///C:\DOCUME~1\z063380\LOCALS~1\Temp\msohtmlclip1\01\clip_image004.png" href="cid:image003.png@01CAA5B7.290B6010"&gt; &lt;/v:shape&gt;&lt;![endif]--&gt;&lt;!--[if !vml]--&gt;&lt;img src="file:///C:/DOCUME%7E1/z063380/LOCALS%7E1/Temp/msohtmlclip1/01/clip_image005.gif" alt="Figure 2 - Aggregation" shapes="Picture_x0020_4" width="264" border="0" height="84" /&gt;&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;So how do we express the concept of aggregation in C#? Well, it's a little different to composition. Consider the following code:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;public class&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: teal;"&gt;Address&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;{&lt;br /&gt; . . .&lt;br /&gt;}&lt;/span&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;public&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;class&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt; &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: teal;"&gt;Person&lt;/span&gt;&lt;span style="font-size: 12pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;{&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;     &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;private&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt; Address address;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;     &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;public&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt; Person(Address address)&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;     {&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;         &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: blue;"&gt;this&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;.address = address;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;     }&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;     . . .&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;; color: black;"&gt;}&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;Person would then be used as follows:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;Address address = &lt;span style="color: blue;"&gt;new&lt;/span&gt; Address();&lt;br /&gt;Person person = &lt;span style="color: blue;"&gt;new&lt;/span&gt; Person(address);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;or&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;Person person = &lt;span style="color: blue;"&gt;new&lt;/span&gt; Person( &lt;span style="color: blue;"&gt;new&lt;/span&gt; Address() );&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;As you can see, Person does not manage the lifetime of Address. If Person is destroyed, the Address still exists. This scenario does map quite nicely to the real world.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: &amp;quot;Verdana&amp;quot;,&amp;quot;sans-serif&amp;quot;;"&gt;Conclusion:&lt;/span&gt;&lt;/strong&gt;&lt;span style="font-size: 10pt;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&lt;span style="font-size: 10pt;"&gt;As I said at the beginning of the article, this is my take on composition and aggregation. Making the decision on whether to use composition or aggregation should not be a tricky. When object modelling, it should be a matter of saying is this 'part-of' or does it 'have-a'?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-539526546915356763?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/539526546915356763/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/02/composition-and-aggregation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/539526546915356763'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/539526546915356763'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/02/composition-and-aggregation.html' title='composition and aggregation'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-4640054772432705089</id><published>2010-01-20T12:09:00.000-08:00</published><updated>2010-01-20T12:10:10.958-08:00</updated><title type='text'>Visual Studio 2005 Installation Problems</title><content type='html'>&lt;h4 class="beTitle" id="subjcns!3BC0BA53FCAF028C!597"&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;&lt;span style="color:#ff0000;"&gt;The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2908&lt;/span&gt;&lt;/span&gt;&lt;/h4&gt;&lt;div&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;OK, I just ended up having to burn one of my MSDN incidents :( because I could not get Visual Studio 2005 to install correctly, so I figured I'd blog the solution so someone else could benefit from it.&lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt; &lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;strong&gt;&lt;u&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;The Error&lt;/span&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt; &lt;div&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;The error message I got simply said that Document Explorer 2005 failed to install.  Tracing the event log I got the following:&lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt; &lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;&lt;span style="color:#ff0000;"&gt;Product: Microsoft Document Explorer 2005 -- The installer has encountered an unexpected error installing this package. This may indicate a problem with this package. The error code is 2908. The arguments are: {FAA7C2AC-4205-4228-BEB6-6E647CCA9FD2}, ,&lt;/span&gt; &lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt; &lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;"&gt;followed by:&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;color:#ff0000;"&gt;Product: Microsoft Document Explorer 2005 -- Error 1935.An error occurred during the installation of assembly 'Microsoft.MSXML,Version="8.0.0.0",PublicKeyToken="b03f5f7f11d50a3a",Culture="neutral",FileVersion="8.0.50727.42",ProcessorArchitecture="MSIL"'. Please refer to Help and Support for more information. HRESULT: 0x80131700. assembly interface: , function: CreateAssemblyNameObject, component: {B1BE189C-054D-4195-9C26-49D28C20DE94}&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt; &lt;/span&gt;&lt;/div&gt; &lt;div&gt;&lt;strong&gt;&lt;u&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;The Solution&lt;/span&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/div&gt; &lt;div&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;The problem was solved by following these steps:&lt;/span&gt;&lt;/div&gt; &lt;ol&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Uninstall .NET 2.0.&lt;/span&gt;&lt;/li&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Click "Start".  The Windows Start Menu pops up.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Click "Control Panel".  The Control Panel windows opens.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Double Click "Add/Remove Programs".  The Add/Remove Programs window opens and after some period of scanning for applications, presents you with a list of installed applications.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Select the ".NET Framework 2.0" application and select to remove it.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Delete temp files.&lt;/span&gt;&lt;/li&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Click "Start".  The Windows Start Menu pops up.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Click "Run".  The Run command window opens.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Enter "%temp%" and click OK.  This will open your Temp folder.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Press Ctrl+A.  This will select all the files in the folder.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Press Shift+Del to delete all files listed that are not locked.  The delete process may abort on error several times stating that a particular file could not be deleted.  Simply unselect that given file by holding down the Ctrl key and clicking the file and continue the deletion.  In my case there were 2 files that could not be deleted in the end.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Add registry key.&lt;/span&gt;&lt;/li&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Click "Start".  The Windows Start Menu pops up.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Click "Run".  The Run command window opens.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Enter "regedit" and click OK.  This will open RegEdit.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Navigate down to HKLM\Software\Policies\Microsoft\Windows\Installer.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Right click in the right hand pane.  A popup menu with one option, "New" appears.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Click "New".  A new popup menu with several options appears.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Click "String Value".&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Change the "New Value #1" text to "Logging".&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Double click the "Logging" entry.  The value edit window opens.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Change the value of the key to "VoiceWarmup" &amp;amp; click OK.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Close RegEdit.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Install the .NET Framework 2.0.&lt;/span&gt;&lt;/li&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Open Windows Explorer.&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Navigate to "D:\wcu\dotNetFramework".&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Double click "dotnetfx.exe" to install the framework.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Install the Microsoft Document Explorer 2005.&lt;/span&gt;&lt;/li&gt;&lt;ol&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;In Windows Explorer, navigate to "D:\wcu\DExplore".&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Double click "DExplore.exe" to install the Document Explorer.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;li&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;Install Visual Studio 2005 as per normal from here.&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;&lt;span style="font-family:Verdana, Geneva, Arial, Sans-serif;font-size:85%;"&gt;That worked for me... hopefully, it will work for you too! :)&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-4640054772432705089?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/4640054772432705089/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/01/visual-studio-2005-installation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/4640054772432705089'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/4640054772432705089'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/01/visual-studio-2005-installation.html' title='Visual Studio 2005 Installation Problems'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-1053849207392390617</id><published>2010-01-05T02:03:00.000-08:00</published><updated>2010-01-05T02:05:33.200-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Fruit juice'/><title type='text'>Fruit juices - adding colour and health to your life</title><content type='html'>Fruit juices - adding colour and health to your life&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Easy to prepare, a good friend of your taste buds, a hit all through the year and good for your health – that’s a glass of fresh juice, which can also add glow and energy to your life. Fresh juice is healthy and we all know that drinking the real thing is better than the sugary alternatives that are packed months before they reach the consumers. Fresh juices benefit us in the following ways:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  * They provide minerals, vitamins, essential fatty acids, carbohydrates and proteins&lt;br /&gt;  * Help improve energy levels&lt;br /&gt;  * Good for the skin&lt;br /&gt;  * Strengthen the immune system&lt;br /&gt;  * Make the bones stronger&lt;br /&gt;&lt;br /&gt;Despite all the benefits that fruit juices offer, there are certain things we need to know about fresh juice.&lt;br /&gt;&lt;br /&gt;Is it OK to drink as much juice as we want daily?&lt;br /&gt;&lt;br /&gt;No, water should be the main source of liquid and it is always better to have fruits in their natural form rather than as juice. Why? Because we all add sugar and salt to the fruit juice we make at home. This increases the amount of sugar in our diet and thus, the calorie load. But we don’t really perceive drinks to be food. Eating a whole pomegranate or having three or four oranges in a row is a cumbersome job. But we would gallop a big glass of juice in a few seconds and even forget to count them as calories. So, if you take two servings of fruit in a juice, ideally you should forego your evening snacks.&lt;br /&gt;&lt;br /&gt;Should we drink juice daily?&lt;br /&gt;&lt;br /&gt;Drinking juice is an easy way to have two fruit servings per day that is good for the daily quota of vitamins. But, keep a check on the sugar added to the juice. It’s best to have fresh juice without any sugar or salt. Though such juice might taste a bit bland and sometimes sour as in the case of orange juice, you would gradually develop a taste for them. The best choice for a daily habit of juice is carrot, apple and ginger, made with only one piece of fruit. Carrots are sweet but lower in calories and have about half the carbohydrates of fruits. Celery is also a nice low-calorie filler. Have a look at the amount of carbohydrates different fruits have.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  * Orange –16 g&lt;br /&gt;  * Grapes – 28 g&lt;br /&gt;  * Pomegranates – 26 g&lt;br /&gt;  * Pineapple – 19 g&lt;br /&gt;  * Apple – 21 g&lt;br /&gt;&lt;br /&gt;How to use the juicer?&lt;br /&gt;&lt;br /&gt;Now the next thing is how to use the juicer at home to get the best juice. The foremost thing is to get a good quality juicer, preferably ISI marked. If you want the fibre benefits, then put all the vegetables and fruits into a blender and don’t use a juice extractor. While ordering fresh juice from outside, be sure about the hygiene and ensure that they are using a blender, not an extractor. Extractors make a smooth drink but they remove the all-important fibre from the juice.&lt;br /&gt;&lt;br /&gt;Are juices good for children?&lt;br /&gt;&lt;br /&gt;Replacing water with juice for children can cause diarrhoea. Having juice everyday can help to develop lifetime sweet tendencies in children. So, juices should be an occasional drink for children. Eating fruit in its natural form and relying on water, as the source of liquid, are better alternatives. Nevertheless, fruit juice is better than having aerated drinks.&lt;br /&gt;&lt;br /&gt;Tips on getting best out of your juices&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  * Always wash fruit and vegetables – even organic produce could carry bacteria.&lt;br /&gt;  * Include the stems and leaves of vegetables because they have a high vitamin and mineral content.&lt;br /&gt;  * Drink a juice within half an hour of preparing it, or it can get oxidised by exposure to air and develop a sour taste.&lt;br /&gt;  * If you must prepare juice early, keep it refrigerated with a tight lid. Or freeze in daily-serving-size containers immediately and drink it straight after thawing.&lt;br /&gt;  * Include the white inner skin of citrus fruits, as it is full of beneficial bioflavonoids.&lt;br /&gt;  * Add lemon juice to preserve the natural colour and reduce the oxidation of essential nutrients.&lt;br /&gt;  * If you want to lose weight, then drink vegetable juices, as they contain fewer calories than fruit juice.&lt;br /&gt;  * If you have a sensitive stomach or irritable bowel syndrome (IBS), ensure that you dilute juices with water (three parts of juice with one part of water).&lt;br /&gt;&lt;br /&gt;Easy to make juice-based drinks&lt;br /&gt;&lt;br /&gt;Watermelon drink&lt;br /&gt;&lt;br /&gt;Ingredients - 3 cups watermelon (washed and cut into small pieces), sugar (as per taste), 3 tablespoon skimmed milk, ice cubes.&lt;br /&gt;&lt;br /&gt;Method - Blend the ingredients in a blender and refrigerate. Pour the prepared drink into serving glass, add ice cubes and serve.&lt;br /&gt;&lt;br /&gt;Nutritive value of the watermelon juice - Apart from providing energy, watermelon protects against age-related symptoms of vision loss, fights heart disease, reduces cancer risk and is loaded with anti-oxidants. So, a glass of watermelon drink everyday not only quenches your thirst but also offers a range of health benefits.&lt;br /&gt;&lt;br /&gt;Carrot, celery and cabbage juice&lt;br /&gt;&lt;br /&gt;Ingredients - 2 cucumbers, stalks of celery, a piece of ginger, a handful of parsley, piece of apple or citrus fruit.&lt;br /&gt;&lt;br /&gt;Method - Wash all vegetables and juice them together. Serve it fresh.&lt;br /&gt;&lt;br /&gt;A glass of fruit or vegetable juice takes very little digestion. It goes right into your body and is a very yummy way of getting instant energy. Fruit juices can energise your life.&lt;br /&gt;( Wednesday , 16 September 2009)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/7988202699791029454-1053849207392390617?l=javediitr.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://javediitr.blogspot.com/feeds/1053849207392390617/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://javediitr.blogspot.com/2010/01/fruit-juices-adding-colour-and-health.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/1053849207392390617'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7988202699791029454/posts/default/1053849207392390617'/><link rel='alternate' type='text/html' href='http://javediitr.blogspot.com/2010/01/fruit-juices-adding-colour-and-health.html' title='Fruit juices - adding colour and health to your life'/><author><name>jamalume</name><uri>http://www.blogger.com/profile/08384461943675450633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7988202699791029454.post-4741309974902060807</id><published>2009-12-17T11:36:00.000-08:00</published><updated>2009-12-17T11:44:11.765-08:00</updated><title type='text'>Migraine Headache</title><content type='html'>&lt;h2&gt;&lt;br /&gt;&lt;/h2&gt;&lt;!-- Start Top Of Page Chunk--&gt;    &lt;div&gt;     &lt;div style="float: left; width: 20px; margin-right: 9px; display: block; margin-top: 4px;"&gt;       &lt;a onclick="wmdTrack('slideprmo-arttop');WindowOpenMenu('http://www.medicinenet.com/script/main/art.asp?articlekey=100390',1000,1000);" href="http://www.medicinenet.com/migraine_headache/article.htm#"&gt;         &lt;img src="http://images.medicinenet.com/images/slideshow/icon_slideshow.gif" alt="Pictures of Headache &amp;amp; Migraine Triggers" align="left" border="0" height="20" width="20" /&gt;       &lt;/a&gt;&lt;/div&gt;     &lt;div style="float: left; text-align: left; display: block; max-width: 320px; padding-top: 5px;"&gt;       &lt;a onclick="wmdTrack('slideprmo-arttop');WindowOpenMenu('http://www.medicinenet.com/script/main/art.asp?articlekey=100390',1000,1000);" href="http://www.medicinenet.com/migraine_headache/article.htm#"&gt;Headache &amp;amp; Migraine Triggers Slideshow&lt;/a&gt;&lt;/div&gt;     &lt;div style="float: left; width: 46px; margin-left: 9px; display: block;"&gt;       &lt;a onclick="wmdTrack('slideprmo-arttop');WindowOpenMenu('http://www.medicinenet.com/script/main/art.asp?articlekey=100390',1000,1000);" href="http://www.medicinenet.com/migraine_headache/article.htm#"&gt;         &lt;img src="http://images.medicinenet.com/images/slideshow/tn-headache-triggers-slideshow.gif" alt="View Headache &amp;amp; Migraine Triggers Slideshow" border="0" height="35" width="46" /&gt;       &lt;/a&gt;&lt;/div&gt;        &lt;/div&gt;  &lt;!-- End Top Of Page Chunk--&gt; Medical Author: &lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=3915"&gt;Dennis Lee, MD&lt;/a&gt;&lt;br /&gt;Medical Editors: &lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=12190"&gt;Harley I. Kornblum, MD, PhD&lt;/a&gt;,   &lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=6930"&gt;Jay W. Marks, MD&lt;/a&gt; &lt;ul&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;page=1#tocb"&gt;What is a migraine headache?&lt;/a&gt;   &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;page=2#tocc"&gt;What are the symptoms of migraine headaches?&lt;/a&gt;   &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;page=3#tocd"&gt;How is a migraine headache diagnosed?&lt;/a&gt;   &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;page=3#toce"&gt;How are migraine headaches treated?&lt;/a&gt;     &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;page=4#toch"&gt;What is the treatment for moderate to severe migraine  headaches?&lt;/a&gt;     &lt;/li&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;page=5#tocm"&gt;What other medications are used for treating migraine  headaches?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;page=5#tocn"&gt;How are migraine headaches prevented?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;page=5#toco"&gt;What are migraine triggers?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;page=6#tocp"&gt;What should migraine sufferers do?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;page=6#tocq"&gt;What are prophylactic medications for migraine headaches?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;page=7#toct"&gt;What is the proper way to use preventive medications?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;page=7#migraine"&gt;What is the treatment for menstrual migraine?&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;page=8#tocu"&gt;Conclusions&lt;/a&gt;&lt;/li&gt;&lt;!-- Start TOC Chunk--&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/migraine_headache/article.htm#" onclick="wmdTrack('slideprmo-arttoc'); WindowOpenMenu('http://www.medicinenet.com/script/main/art.asp?articlekey=100390',1000,1000);"&gt;Headache &amp;amp; Migraine Triggers - Slideshow     &lt;img src="http://images.medicinenet.com/images/slideshow/icon_slideshow.gif" alt="View Headache &amp;amp; Migraine Triggers Slideshow" align="absmiddle" border="0" height="20" width="20" /&gt;&lt;/a&gt;&lt;/li&gt;&lt;!-- End TOC Chunk--&gt;&lt;li&gt;&lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=417&amp;amp;questionid=75"&gt;&lt;b&gt;Patient Discussions:&lt;/b&gt; Migraine Headache - Effective Treatments&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt; &lt;!-- Start Generic Article in Article --&gt; &lt;div id="genericAIAblue"&gt;  &lt;div id="genericAIATop"&gt;&lt;h2&gt;Migraine Pain:&lt;br /&gt;What to Do About It&lt;/h2&gt;         &lt;/div&gt;         &lt;div id="genericAIAContent"&gt;&lt;h3&gt;How Not to Suffer from Migraine Pain&lt;/h3&gt;  &lt;ul&gt;&lt;li&gt;Go to sleep and waking up at the same time each day.&lt;/li&gt;&lt;li&gt;Exercise regularly (daily if possible). Make a commitment to exercise even when traveling or during busy periods at work. Exercise can improve the quality of sleep and reduce the frequency and severity of migraine headaches. Build up your exercise level gradually. Over-exertion, especially for someone who is out of shape, can lead to migraine headaches.&lt;/li&gt;&lt;li&gt;Do not skip meals, and avoiding prolonged fasting.&lt;/li&gt;&lt;li&gt;Limit stress through regular exercise and relaxation techniques.&lt;/li&gt;&lt;li&gt;Limit caffeine consumption to less than two caffeine-containing beverages a day.&lt;/li&gt;&lt;li&gt;Avoid bright or flashing lights and wearing sunglasses if sunlight is a trigger.&lt;/li&gt;&lt;li&gt;Identify and avoid foods that trigger headaches by keeping a headache and food diary. Review the diary with your doctor. It is impractical to adopt a diet that avoids all known migraine triggers, however, it is reasonable to avoid foods that consistently trigger migraine headaches.&lt;/li&gt;&lt;/ul&gt;                         &lt;/div&gt;                  &lt;/div&gt; &lt;!-- End Generic Article in Article --&gt; &lt;p&gt;&lt;b&gt;&lt;a name="tocb"&gt;What is a migraine headache?&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;A migraine headache is a form of  vascular headache. Migraine headache is caused by a combination of  vasodilatation (enlargement of blood vessels) and the release of chemicals from  nerve fibers that coil around the blood vessels. During a migraine attack, the  temporal artery enlarges. (The temporal artery is an artery that lies on the outside of the skull just under the skin of the temple.) Enlargement of the temporal artery stretches the nerves that coil around the artery and causes the nerves to release chemicals. The chemicals cause inflammation, pain, and further enlargement of the artery. The increasing enlargement of the artery magnifies the pain.&lt;/p&gt; &lt;p&gt;Migraine attacks commonly activate the sympathetic nervous system in the  body. The sympathetic nervous system is often thought of as the part of the  nervous system that controls primitive responses to &lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=488"&gt;stress&lt;/a&gt; and pain, the so-called  "fight or flight" response. The increased sympathetic nervous activity in the  intestine causes nausea, vomiting, and &lt;a href="http://www.medicinenet.com/script/main/art.asp?articlekey=1900"&gt;diarrhea&lt;/a&gt;. Sympathetic activity  also delays emptying of the stomach into the small intestine and thereby  prevents oral medications from entering the intestine and being absorbed. The  impaired absorption of oral medications is a common reason for the  ineffectiveness of medications taken to treat migraine headaches. The increased  sympathetic activity also decreases the circulation of blood, and this leads to  pallor of the skin as well as cold hands and feet. The increased sympathetic  activity also contributes to the sensitivity to light and sound sensitivity as  well as blurred vision.&lt;/p&gt; &lt;p&gt;                        Migraine  afflicts 28 million Americans, with females suffering more  frequently (17%) than males (6%). Missed work and lost productivity from migraine  create a significant public burden. Nevertheless, migraine still remains largely  undertreated and underdiagnosed. Less than half the sufferers are diagnosed by  their doctors.&lt;/p&gt;&lt;p&gt;&lt;b&gt;&lt;a name="tocc"&gt;What are the symptoms of migraine headaches?&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Migraine is a chronic condition  of recurrent attacks. Most (but not all) migraine
