tag:blogger.com,1999:blog-58340099210816053912024-03-07T22:45:48.446-08:00Life Runs On CodeMD. Munirul Hoquehttp://www.blogger.com/profile/05115460930842148547noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-5834009921081605391.post-86015055137135399442011-02-14T03:45:00.000-08:002011-02-14T03:45:05.127-08:00Add Columns with Default value in a Table in SQL SERVER 2008<div dir="ltr" style="text-align: left;" trbidi="on">We Have atable named "User_General_Info" . Then If we need to Add a column to the table with a default date(e,g, System Date) then we can write in this way....<br />
<br />
<span style="color: blue;">ALTER TABLE [User_General_Info]</span><br />
<span style="color: blue;"></span><br />
<span style="color: blue;"><br />
</span><br />
<span style="color: blue;">ADD Reg_Date datetime</span><br />
<span style="color: blue;"><br />
</span><br />
<span style="color: blue;">CONSTRAINT DF_User_General_Info_Reg_Date DEFAULT (getdate()) NOT NULL</span></div>MD. Munirul Hoquehttp://www.blogger.com/profile/05115460930842148547noreply@blogger.com0tag:blogger.com,1999:blog-5834009921081605391.post-4729050474571293842010-05-22T21:57:00.000-07:002010-05-22T21:59:51.580-07:00Understanding Static Methods and Data<meta content="text/html; charset=utf-8" http-equiv="Content-Type"></meta><meta content="Word.Document" name="ProgId"></meta><meta content="Microsoft Word 12" name="Generator"></meta><meta content="Microsoft Word 12" name="Originator"></meta><link href="file:///C:%5CUsers%5CZaman%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml" rel="File-List"></link><link href="file:///C:%5CUsers%5CZaman%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx" rel="themeData"></link><link href="file:///C:%5CUsers%5CZaman%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml" rel="colorSchemeMapping"></link> <m:smallfrac m:val="off"> <m:dispdef> <m:lmargin m:val="0"> <m:rmargin m:val="0"> <m:defjc m:val="centerGroup"> <m:wrapindent m:val="1440"> <m:intlim m:val="subSup"> <m:narylim m:val="undOvr"> </m:narylim></m:intlim> </m:wrapindent><style>
<!--
/* 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 415 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:-520092929 1073786111 9 0 415 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:-1593833729 1073750107 16 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-fareast-font-family:"Times New Roman";
mso-bidi-font-family:"Times New Roman";}
.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;
mso-ascii-font-family:Calibri;
mso-hansi-font-family:Calibri;}
@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:281616981;
mso-list-type:hybrid;
mso-list-template-ids:-1265990914 67698701 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Wingdings;}
@list l1
{mso-list-id:919870612;
mso-list-type:hybrid;
mso-list-template-ids:908117872 67698699 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l1:level1
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Wingdings;}
@list l2
{mso-list-id:1214081082;
mso-list-type:hybrid;
mso-list-template-ids:-1581581746 67698701 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l2:level1
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Wingdings;}
ol
{margin-bottom:0in;}
ul
{margin-bottom:0in;}
-->
</style> </m:defjc></m:rmargin></m:lmargin></m:dispdef></m:smallfrac><br />
<div class="MsoNormal"><b><span style="color: #e36c0a; font-family: "Verdana","sans-serif"; font-size: 12pt; line-height: 115%;">Understanding Static Methods and Data<o:p></o:p></span></b></div><div class="MsoNormal"><b><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">Static</span></b><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;"> keyword is widely used to <b><i>share the same field or method</i></b> among all the objects of the class. The actual goal of the static keyword is to share a single data over all the objects.<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">There are three types of sharing using the <b>static</b> keyword. They are –<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><span style="font-family: Wingdings; font-size: 10pt; line-height: 115%;">Ø<span style="font: 7pt "Times New Roman";"> </span></span><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">Static Method<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><span style="font-family: Wingdings; font-size: 10pt; line-height: 115%;">Ø<span style="font: 7pt "Times New Roman";"> </span></span><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">Static Field<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in; text-indent: -0.25in;"><span style="font-family: Wingdings; font-size: 10pt; line-height: 115%;">Ø<span style="font: 7pt "Times New Roman";"> </span></span><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">Static Class<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">Now I am going to give a short brief on these three types-<o:p></o:p></span></div><div class="MsoNormal"><b><span style="color: #31849b; font-family: "Verdana","sans-serif";">Static Method<o:p></o:p></span></b></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">A <b>Static Method</b> can be accessed from outside the class without creating any object of this class. This <b>Static Method</b> can be accessed by directly by the name of the static method followed by the . (dot operator) and the class name.</span><b><span style="color: #31849b; font-family: "Verdana","sans-serif";"><o:p></o:p></span></b></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">For example, we can consider the <b>Sqrt </b>method of the <b>Math</b> class. This is how the <b>Sqrt </b>method of the real <b>Math</b> class is defined :<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">class Math<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">{<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">……….<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">public static double Sqrt (double d)<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 1in;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">{<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 1.5in;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">………………………<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 1in;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">} <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">}<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">From the previous example you can notify that the <b>Sqrt</b> method is declared as static so that it can be accessed by using the class name directly,no object of the Math class is required to access the static method.<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">So, here I will like to some general properties of a <b>Static Method</b> :<o:p></o:p></span></div><ul><li><span style="font-family: Wingdings; font-size: 10pt; line-height: 115%;"><span style="font: 7pt "Times New Roman";"> </span></span><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">It can access only the static fields of the class.<o:p></o:p></span></li>
<li><span style="font-family: Wingdings; font-size: 10pt; line-height: 115%;"><span style="font: 7pt "Times New Roman";"> </span></span><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">It can directly invoke the methods that are defined as static. <o:p></o:p></span></li>
</ul><div class="MsoNormal"><b><span style="color: #31849b; font-family: "Verdana","sans-serif";">Static Fields<o:p></o:p></span></b></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">A static field is shared among all the objects of the of the class. So if an object change this the value then all the object of this class will get the changed value.<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">Look at the example below – <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">class</span><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Point<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> Point()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.x = -1;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.y = -1;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.WriteLine(<span style="color: maroon;">"Deafult Constructor Called"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> objectCount++;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> Point(<span style="color: blue;">int</span> x, <span style="color: blue;">int</span> y)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.x = x;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.y = y;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.WriteLine(<span style="color: maroon;">"x = {0} , y = {1}"</span>, x, y);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> objectCount++;<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt; line-height: 115%;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in; text-indent: 0.5in;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">private</span><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">int</span> x, y;<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt; line-height: 115%;"> <span style="color: blue;">public static</span> <span style="color: blue;">int</span> objectCount = 0;<o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt; line-height: 115%;"> }<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">Now if we create three objects for this class – <o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in;"><span style="color: teal; font-family: "Courier New"; font-size: 10pt; line-height: 115%;">Point</span><span style="font-family: "Courier New"; font-size: 10pt; line-height: 115%;"> origin1 = <span style="color: blue;">new</span> <span style="color: teal;">Point</span>(); <span style="color: #76923c;">// objectCount = 1</span><span style="color: #c2d69b;"><o:p></o:p></span></span></div><div class="MsoNormal" style="margin-left: 0.5in;"><span style="color: teal; font-family: "Courier New"; font-size: 10pt; line-height: 115%;">Point</span><span style="font-family: "Courier New"; font-size: 10pt; line-height: 115%;"> origin2 = <span style="color: blue;">new</span> <span style="color: teal;">Point</span>(); <span style="color: #76923c;">// objectCount = 2</span><o:p></o:p></span></div><div class="MsoNormal" style="margin-left: 0.5in;"><span style="color: teal; font-family: "Courier New"; font-size: 10pt; line-height: 115%;">Point</span><span style="font-family: "Courier New"; font-size: 10pt; line-height: 115%;"> origin3 = <span style="color: blue;">new</span> <span style="color: teal;">Point</span>(); <span style="color: #76923c;">// objectCount = 3<o:p></o:p></span></span></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">Here these three objects share the same field so evry time the <b>static</b> field </span><b><span style="font-family: "Courier New"; font-size: 10pt; line-height: 115%;">objectCount </span></b><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">is incremented.<o:p></o:p></span></div><div class="MsoNormal"><b><span style="color: #31849b; font-family: "Verdana","sans-serif";">Static Class<o:p></o:p></span></b></div><div class="MsoNormal"><span style="color: black; font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">A static class is used to hold all the utility methods and fields. A static Class has some properties –<o:p></o:p></span></div><ul><li><span style="color: black; font-family: Wingdings; font-size: 10pt; line-height: 115%;"><span style="font: 7pt "Times New Roman";"> </span></span><span style="color: black; font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">All the methods and fields inside the class must be declared as static.<o:p></o:p></span></li>
<li><span style="color: black; font-family: Wingdings; font-size: 10pt; line-height: 115%;"><span style="font: 7pt "Times New Roman";"> </span></span><span style="color: black; font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">A static class cannot contain any instance method or data.<o:p></o:p></span></li>
<li><span style="color: black; font-family: Wingdings; font-size: 10pt; line-height: 115%;"><span style="font: 7pt "Times New Roman";"> </span></span><span style="color: black; font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">No object can be created (even using the “new” keyword) of this class.<o:p></o:p></span></li>
<li><span style="color: black; font-family: Wingdings; font-size: 10pt; line-height: 115%;"><span style="font: 7pt "Times New Roman";"> </span></span><span style="color: black; font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">It can has a default constructor and it is also static.<o:p></o:p></span></li>
</ul><div class="MsoNormal"><b><span style="color: #5f497a; font-family: "Verdana","sans-serif";">Example<o:p></o:p></span></b></div><div class="MsoNormal"><span style="color: black; font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">Let us consider an example – <o:p></o:p></span></div><div class="MsoNormal"><b><u><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">Point.cs<o:p></o:p></span></u></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">using</span><span style="font-family: "Courier New"; font-size: 10pt;"> System;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">using</span><span style="font-family: "Courier New"; font-size: 10pt;"> System.Collections.Generic;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">using</span><span style="font-family: "Courier New"; font-size: 10pt;"> System.Text;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">namespace</span><span style="font-family: "Courier New"; font-size: 10pt;"> ConAppCH7CCons<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">class</span> <span style="color: teal;">Point<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> Point()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.x = -1;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.y = -1;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.WriteLine(<span style="color: maroon;">"Deafult Constructor Called"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> objectCount++;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> Point(<span style="color: blue;">int</span> x, <span style="color: blue;">int</span> y)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.x = x;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.y = y;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.WriteLine(<span style="color: maroon;">"x = {0} , y = {1}"</span>, x, y);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> objectCount++;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> <span style="color: blue;">double</span> DistanceTo(<span style="color: teal;">Point</span> other)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">int</span> xDiff = <span style="color: blue;">this</span>.x - other.x;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">int</span> yDiff = <span style="color: blue;">this</span>.y - other.y;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span> <span style="color: teal;">Math</span>.Sqrt((xDiff * xDiff) + (yDiff * yDiff));<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">int</span> FnObjectCount()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span> objectCount;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">private</span> <span style="color: blue;">int</span> x, y;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: blue;">int</span> objectCount = 0;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><b><u><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">ConstructorExample.cs<o:p></o:p></span></u></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">using</span><span style="font-family: "Courier New"; font-size: 10pt;"> System;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">using</span><span style="font-family: "Courier New"; font-size: 10pt;"> System.Collections.Generic;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">using</span><span style="font-family: "Courier New"; font-size: 10pt;"> System.Text;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">namespace</span><span style="font-family: "Courier New"; font-size: 10pt;"> ConAppCH7CCons<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">class</span> <span style="color: teal;">ConstructorExample<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Point</span> origin = <span style="color: blue;">new</span> <span style="color: teal;">Point</span>();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Point</span> bottomRight = <span style="color: blue;">new</span> <span style="color: teal;">Point</span>(1024, 1280);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">double</span> distance = origin.DistanceTo(bottomRight);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.WriteLine(<span style="color: maroon;">"distance = {0}"</span>,distance);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.WriteLine(<span style="color: maroon;">"No of Objects {0}"</span>, <span style="color: teal;">Point</span>.FnObjectCount());<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.ReadLine();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoNormal"><br />
</div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">In this example the </span><span style="font-family: "Courier New"; font-size: 10pt; line-height: 115%;">FnObjectCount()</span><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">method is called directly with the class name, no object is reqired here.<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">If you want to access the static method with an object like – <o:p></o:p></span></div><div class="MsoNormal" style="text-indent: 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt; line-height: 115%;">bottomRight.FnObjectCount()// do not write this<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">then the compiler will report an error.<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">Now, give a deeper look into the </span><span style="font-family: "Courier New"; font-size: 10pt; line-height: 115%;">FnObjectCount() </span><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">static mehod – <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">int</span> FnObjectCount()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span> objectCount;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt; line-height: 115%;">As it is a static method, so it can hold only static field or ststic mehod.<o:p></o:p></span></div>MD. Munirul Hoquehttp://www.blogger.com/profile/05115460930842148547noreply@blogger.com0tag:blogger.com,1999:blog-5834009921081605391.post-23999571954577388482010-05-19T21:56:00.000-07:002010-05-19T21:56:45.441-07:00Constructor in C# (For the Beginners)<meta content="text/html; charset=utf-8" http-equiv="Content-Type"></meta><meta content="Word.Document" name="ProgId"></meta><meta content="Microsoft Word 12" name="Generator"></meta><meta content="Microsoft Word 12" name="Originator"></meta><link href="file:///C:%5CUsers%5CZaman%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_filelist.xml" rel="File-List"></link><link href="file:///C:%5CUsers%5CZaman%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_themedata.thmx" rel="themeData"></link><link href="file:///C:%5CUsers%5CZaman%5CAppData%5CLocal%5CTemp%5Cmsohtmlclip1%5C01%5Cclip_colorschememapping.xml" rel="colorSchemeMapping"></link> <m:smallfrac m:val="off"> <m:dispdef> <m:lmargin m:val="0"> <m:rmargin m:val="0"> <m:defjc m:val="centerGroup"> <m:wrapindent m:val="1440"> <m:intlim m:val="subSup"> <m:narylim m:val="undOvr"> </m:narylim></m:intlim> </m:wrapindent><style>
<!--
/* 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 415 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:-520092929 1073786111 9 0 415 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:-1593833729 1073750107 16 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-fareast-font-family:Calibri;
mso-bidi-font-family:Arial;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
mso-style-unhide:no;
mso-style-qformat:yes;
margin-top:0in;
margin-right:0in;
margin-bottom:10.0pt;
margin-left:.5in;
mso-add-space:auto;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-font-family:Calibri;
mso-bidi-font-family:Arial;}
p.MsoListParagraphCxSpFirst, li.MsoListParagraphCxSpFirst, div.MsoListParagraphCxSpFirst
{mso-style-priority:34;
mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-type:export-only;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
mso-add-space:auto;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-font-family:Calibri;
mso-bidi-font-family:Arial;}
p.MsoListParagraphCxSpMiddle, li.MsoListParagraphCxSpMiddle, div.MsoListParagraphCxSpMiddle
{mso-style-priority:34;
mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-type:export-only;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
mso-add-space:auto;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-font-family:Calibri;
mso-bidi-font-family:Arial;}
p.MsoListParagraphCxSpLast, li.MsoListParagraphCxSpLast, div.MsoListParagraphCxSpLast
{mso-style-priority:34;
mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-type:export-only;
margin-top:0in;
margin-right:0in;
margin-bottom:10.0pt;
margin-left:.5in;
mso-add-space:auto;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-font-family:Calibri;
mso-bidi-font-family:Arial;}
.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;
mso-ascii-font-family:Calibri;
mso-fareast-font-family:Calibri;
mso-hansi-font-family:Calibri;
mso-bidi-font-family:Arial;}
@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:2076930030;
mso-list-type:hybrid;
mso-list-template-ids:-1708469724 67698699 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
{mso-level-number-format:bullet;
mso-level-text:;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Wingdings;}
ol
{margin-bottom:0in;}
ul
{margin-bottom:0in;}
-->
</style> </m:defjc></m:rmargin></m:lmargin></m:dispdef></m:smallfrac><br />
<div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><b><span style="font-family: "Verdana","sans-serif"; font-size: 12pt;">Constructor<o:p></o:p></span></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">Constructor is a simple method inside a class. Except it has some exceptions:<o:p></o:p></span></div><div class="MsoListParagraphCxSpFirst" style="line-height: normal; margin-bottom: 0.0001pt; text-indent: -0.25in;"><span style="font-family: Wingdings; font-size: 10pt;">Ø<span style="font: 7pt "Times New Roman";"> </span></span><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">Constructor has the same name as the class.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-indent: -0.25in;"><span style="font-family: Wingdings; font-size: 10pt;">Ø<span style="font: 7pt "Times New Roman";"> </span></span><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">Constructor does not return value even void.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-indent: -0.25in;"><span style="font-family: Wingdings; font-size: 10pt;">Ø<span style="font: 7pt "Times New Roman";"> </span></span><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">Constructor can be built with parameter or without parameter.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin-bottom: 0.0001pt; text-indent: -0.25in;"><span style="font-family: Wingdings; font-size: 10pt;">Ø<span style="font: 7pt "Times New Roman";"> </span></span><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">Every class has a default constructor Even if did not create it. If the developer does not create a constructor then the .NET compiler create a default constructor, this deafault constructor actually does nothing. <o:p></o:p></span></div><div class="MsoListParagraphCxSpLast" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">You can easily create a default constructor by creating a method like this :<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">class</span><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Point<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> Point()<o:p></o:p></span></div><div class="MsoListParagraph" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;"> </span><span style="color: blue;">this</span>.x = -1;<o:p></o:p></span></div><div class="MsoListParagraphCxSpFirst" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.y = -1;<span style="color: green;"><o:p></o:p></span></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;"> </span><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">private</span> <span style="color: blue;">int</span> x, y; <o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">Have a look on the example, there are two private variable x and y. So when an instance of the class point will be created the constructor will be fired and the variable x and y will get their value as -1 , -1 accordingly.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><br />
</div><div class="MsoListParagraphCxSpLast" style="line-height: normal; margin: 0in 0in 0.0001pt;"><b><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">[</span></b><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;"> Here one thing is noticable, why I have used “this” keyword? I have told earlier that a constructor may be paremeterized or non-parameterized . if it is parameterized and I write it as<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;"> </span><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">class</span><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Point<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> Point(int x , int y)// do not write as this<o:p></o:p></span></div><div class="MsoListParagraph" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: green;"> </span>x = x;//what is the parameter and what is the feild<o:p></o:p></span></div><div class="MsoListParagraphCxSpFirst" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> y = y;// what is the parameter and what is the feild<span style="color: green;"><o:p></o:p></span></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="color: green; font-family: "Courier New"; font-size: 10pt;"> </span><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">private</span> <span style="color: blue;">int</span> x, y; <o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">Though the program will run but it is little ambiguous which one the parameter andwhich one is the field. <o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">The “this” keyword indicates that – “this is a field”<b>]<o:p></o:p></b></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><br />
</div><div class="MsoListParagraphCxSpLast" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">Now you can initialize your object by the constructor Point(). Like this way – <o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">namespace</span><span style="font-family: "Courier New"; font-size: 10pt;"> ConAppCH7CCons<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">class</span> <span style="color: teal;">ConstructorExample<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoListParagraph" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Point</span> origin = <span style="color: blue;">new</span> <span style="color: teal;">Point</span>();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.ReadLine();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoListParagraphCxSpFirst" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">So, when the “origin” object is created it it is initialized with the value <o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="color: #17365d; font-family: "Verdana","sans-serif"; font-size: 10pt;">x=-1<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="color: #17365d; font-family: "Verdana","sans-serif"; font-size: 10pt;">y=-1<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><b><span style="font-family: "Verdana","sans-serif";">Overriding a Constructor<o:p></o:p></span></b></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">Overriding is a feture of OOP and an example of Polymorphism. Constructor overloading is very simple as method overloading. You can have different version of constructors and they can vary by the number of parameter and type of parameter.<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">From the preeciding example , let uss, you do not want to initialize your x and y value with different values and in the mean time you want to keep an option that the user can run the program without any value. In this situation you can code like this :<o:p></o:p></span></div><div class="MsoListParagraphCxSpLast" style="line-height: normal; margin: 0in 0in 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">namespace</span><span style="font-family: "Courier New"; font-size: 10pt;"> ConAppCH7CCons<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">class</span> <span style="color: teal;">Point<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> Point()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.x = -1;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.y = -1;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.WriteLine(<span style="color: maroon;">"Deafult Constructor Called"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> Point(<span style="color: blue;">int</span> x, <span style="color: blue;">int</span> y)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.x = x;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.y = y;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.WriteLine(<span style="color: maroon;">"x = {0} , y = {1}"</span>, x, y);<o:p></o:p></span></div><div class="MsoListParagraph" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;"> private</span><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">int</span> x, y;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0.0001pt 0.5in;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoListParagraphCxSpFirst" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">Now you have two different versions of constructor. You can create objects like bellow :<o:p></o:p></span></div><div class="MsoListParagraphCxSpLast" style="line-height: normal; margin: 0in 0in 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">namespace</span><span style="font-family: "Courier New"; font-size: 10pt;"> ConAppCH7CCons<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">class</span> <span style="color: teal;">ConstructorExample<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Point</span> origin = <span style="color: blue;">new</span> <span style="color: teal;">Point</span>();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Point</span> bottomRight = <span style="color: blue;">new</span> <span style="color: teal;">Point</span>(1024, 1280);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.ReadLine();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoListParagraphCxSpFirst" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">So when when the object “origin” is initiated then <o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="color: #17365d; font-family: "Verdana","sans-serif"; font-size: 10pt;">x=-1<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="color: #17365d; font-family: "Verdana","sans-serif"; font-size: 10pt;">y=-1<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">and when the object “bottomRight” is initiated then <o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="color: #17365d; font-family: "Verdana","sans-serif"; font-size: 10pt;">x=1024<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="color: #17365d; font-family: "Verdana","sans-serif"; font-size: 10pt;">y=1280<o:p></o:p></span></div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><br />
</div><div class="MsoListParagraphCxSpMiddle" style="line-height: normal; margin: 0in 0in 0.0001pt;"><b><span style="font-family: "Verdana","sans-serif";">Example<o:p></o:p></span></b></div><div class="MsoListParagraphCxSpLast" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">Here I will show an example related on constructor. This example is for calculate the distance between two given points-<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><b><u><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">Point.cs<span style="color: blue;"><o:p></o:p></span></span></u></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">using</span><span style="font-family: "Courier New"; font-size: 10pt;"> System;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">using</span><span style="font-family: "Courier New"; font-size: 10pt;"> System.Collections.Generic;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">using</span><span style="font-family: "Courier New"; font-size: 10pt;"> System.Text;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">namespace</span><span style="font-family: "Courier New"; font-size: 10pt;"> ConAppCH7CCons<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">class</span> <span style="color: teal;">Point<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> Point()<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.x = -1;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.y = -1;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.WriteLine(<span style="color: maroon;">"Deafult Constructor Called"</span>);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> Point(<span style="color: blue;">int</span> x, <span style="color: blue;">int</span> y)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.x = x;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">this</span>.y = y;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.WriteLine(<span style="color: maroon;">"x = {0} , y = {1}"</span>, x, y);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">public</span> <span style="color: blue;">double</span> DistanceTo(<span style="color: teal;">Point</span> other)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">int</span> xDiff = <span style="color: blue;">this</span>.x - other.x;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">int</span> yDiff = <span style="color: blue;">this</span>.y - other.y;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">return</span> <span style="color: teal;">Math</span>.Sqrt((xDiff * xDiff) + (yDiff * yDiff));<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">private</span> <span style="color: blue;">int</span> x, y;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">}<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><b><u><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;">ConstructorExample.cs<o:p></o:p></span></u></b></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">using</span><span style="font-family: "Courier New"; font-size: 10pt;"> System;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">using</span><span style="font-family: "Courier New"; font-size: 10pt;"> System.Collections.Generic;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">using</span><span style="font-family: "Courier New"; font-size: 10pt;"> System.Text;<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><br />
</div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="color: blue; font-family: "Courier New"; font-size: 10pt;">namespace</span><span style="font-family: "Courier New"; font-size: 10pt;"> ConAppCH7CCons<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">{<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">class</span> <span style="color: teal;">ConstructorExample<o:p></o:p></span></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[] args)<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> {<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Point</span> origin = <span style="color: blue;">new</span> <span style="color: teal;">Point</span>();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Point</span> bottomRight = <span style="color: blue;">new</span> <span style="color: teal;">Point</span>(1024, 1280);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: blue;">double</span> distance = origin.DistanceTo(bottomRight);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.WriteLine(<span style="color: maroon;">"distance = {0}"</span>,distance);<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> <span style="color: teal;">Console</span>.ReadLine();<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoNormal" style="line-height: normal; margin-bottom: 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;"> }<o:p></o:p></span></div><div class="MsoListParagraph" style="line-height: normal; margin: 0in 0in 0.0001pt;"><span style="font-family: "Courier New"; font-size: 10pt;">}</span><span style="font-family: "Verdana","sans-serif"; font-size: 10pt;"><o:p></o:p></span></div>MD. Munirul Hoquehttp://www.blogger.com/profile/05115460930842148547noreply@blogger.com0