<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Don-Jai : โดนใจ &#187; ซีชาร์ป</title>
	<atom:link href="http://don-jai.com/content/%e0%b8%8b%e0%b8%b5%e0%b8%8a%e0%b8%b2%e0%b8%a3%e0%b9%8c%e0%b8%9b/feed/" rel="self" type="application/rss+xml" />
	<link>http://don-jai.com</link>
	<description>โดนใจ.คอม : บล็อคของ nongoffna เพื่อบันทึกเรื่องราวโดนใจ ในเรื่องโดนๆ</description>
	<lastBuildDate>Fri, 03 Sep 2010 13:26:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>[C#]Unit 4 String</title>
		<link>http://don-jai.com/cunit-4-string/</link>
		<comments>http://don-jai.com/cunit-4-string/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 02:45:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[ซีชาร์ป]]></category>
		<category><![CDATA[พื้นฐาน]]></category>
		<category><![CDATA[สตริง]]></category>
		<category><![CDATA[เขียนโปรแกรม]]></category>

		<guid isPermaLink="false">http://don-jai.com/?p=125</guid>
		<description><![CDATA[Unit 4 String
String &#62;&#62; เป็นสายของอักขระ หรือเป็นการนำเอา character หลายตัวมาต่อกันในลักษณะของอาร์เรย์ โดยมี Method ...]]></description>
			<content:encoded><![CDATA[<p>Unit 4 String</p>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />String &gt;&gt; เป็นสายของอักขระ หรือเป็นการนำเอา character หลายตัวมาต่อกันในลักษณะของอาร์เรย์ โดยมี Method ที่ำสำคัญ <a id="top" name="top"></a></p>
<p>String Method <a href="http://msdn.microsoft.com/en-us/library/system.string_methods(VS.80).aspx">more</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td align="center" valign="top"><a href="#Length">Length</a></td>
<td align="center" valign="top"><a href="#Compare">Compare</a></td>
<td align="center" valign="top"><a href="#Concat">Concat</a></td>
<td align="center" valign="top">
<ul> <a href="#Copy">Copy</a></ul>
</td>
</tr>
<tr>
<td align="center" valign="top"><a href="#CopyTo">CopyTo</a></td>
<td align="center" valign="top">
<ul> <a href="#Equals">Equals</a></ul>
</td>
<td align="center" valign="top"><a href="#IndexOf">IndexOf</a></td>
<td align="center" valign="top">
<ul> <a href="#Insert">Insert</a></ul>
</td>
</tr>
<tr>
<td align="center" valign="top">
<ul> <a href="#Remove">Remove</a></ul>
</td>
<td align="center" valign="top"><a href="#Replace">Replace</a></td>
<td align="center" valign="top">
<ul> <a href="#Split">Split </a></ul>
</td>
<td align="center" valign="top"><a href="#Substring">Substring</a></td>
</tr>
<tr>
<td align="center" valign="top">
<ul> <a href="#ToLower">ToLower </a></ul>
</td>
<td align="center" valign="top"><a href="#ToString">ToString</a></td>
<td align="center" valign="top"><a href="#ToUpper">ToUpper</a></td>
<td align="center" valign="top">
<ul> <a href="#TrimEnd">TrimEnd</a></ul>
</td>
</tr>
</tbody>
</table>
<ul>
<li>Length<a id="Length" name="Length"></a> &gt;&gt; เป็นการหาความยาวของสตริงที่กำหนด <a href="http://msdn.microsoft.com/en-us/library/system.string.length(VS.80).aspx " target="_blank">more</a> <a href="#top">top</a><br />
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">// Sample for  String.Length</p>
<p>using System;</p>
<p>class Sample</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>string  str = &#8220;abcdefg&#8221;;</p>
<p>Console.WriteLine(&#8220;1) The length of &#8216;{0}&#8217; is {1}&#8221;, str,  str.Length);</p>
<p>Console.WriteLine(&#8220;2) The length of &#8216;{0}&#8217; is {1}&#8221;, &#8220;xyz&#8221;, &#8220;xyz&#8221;.Length);</p>
<p>}</p>
<p>}</p>
<p>/*This example  produces the following results:</p>
<p>1) The length of  &#8216;abcdefg&#8217; is 7</p>
<p>2) The length of  &#8216;xyz&#8217; is 3</p>
<p>*/</td>
</tr>
</tbody>
</table>
</li>
<li>Compare<a id="Compare" name="Compare"></a> &gt;&gt; ใช้ในการเปรียบเทียบสตริง 2 ตัว โดยหากตัวแรกยาวกว่าตัวที่สองจะคืนค่า 1 หากสั้นกว่าจะคื่นค่า -1 แต่ถ้าหากเท่ากันจะคืนค่า 0 <a href="http://msdn.microsoft.com/en-us/library/system.string.compare(VS.80).aspx" target="_blank">more</a> <a href="#top">top</a><br />
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>class Program</p>
<p>{</p>
<p>static void Main(string[] args)</p>
<p>{</p>
<p>string  str1 = &#8220;1&#8243;;</p>
<p>string  str2 = &#8220;12&#8243;;</p>
<p>string  str3 = &#8220;123&#8243;;</p>
<p>int  i = String.Compare(str1,str1);</p>
<p>int  j = String.Compare(str1, str3);</p>
<p>int  k = String.Compare(str3, str2);</p>
<p>Console.WriteLine(&#8220;{0}&#8221;,i); //  str1 = str1 so result = 0</p>
<p>Console.WriteLine(&#8220;{0}&#8221;, j); //  str1 &lt; str3 so result = -1</p>
<p>Console.WriteLine(&#8220;{0}&#8221;, k); //  str3 &gt; str2 so result = 1</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>Concat<a id="Concat" name="Concat"></a> &gt;&gt; เป็นการนำสตริงมาต่อกัน <a href="http://msdn.microsoft.com/en-us/library/system.string.concat(VS.80).aspx" target="_blank">more</a> <a href="#top">top</a><br />
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>class ConcatTest</p>
<p>{</p>
<p>static void Main(string[]  args)</p>
<p>{</p>
<p>string  str1 = &#8220;Hello&#8221;;</p>
<p>string  str2 = &#8220;World&#8221;;</p>
<p>string  str3 = String.Concat(str1,str2);</p>
<p>Console.WriteLine(str3);</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</p>
<p>// Result is HelloWorld</td>
</tr>
</tbody>
</table>
</li>
<li>Copy<a id="Copy" name="Copy"></a> &gt;&gt; เป็นการคัดลอกสตริง <a href="http://msdn.microsoft.com/en-us/library/system.string.copy(VS.80).aspx" target="_blank">more</a> <a href="#top">top</a><br />
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">// Sample for  String.Copy()</p>
<p>using System;</p>
<p>class Sample</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>string  str1 = &#8220;abc&#8221;;</p>
<p>string  str2 = &#8220;xyz&#8221;;</p>
<p>str2 = String.Copy(str1);</p>
<p>Console.WriteLine(&#8220;str1 = &#8216;{0}&#8217;&#8221;, str1);</p>
<p>Console.WriteLine(&#8220;str2 = &#8216;{0}&#8217;&#8221;, str2);</p>
<p>}</p>
<p>}</p>
<p>/*This example  produces the following results:</p>
<p>str1 = &#8216;abc&#8217;</p>
<p>str2 = &#8216;abc&#8217;*/</td>
</tr>
</tbody>
</table>
</li>
<li>CopyTo<a id="CopyTo" name="CopyTo"></a> &gt;&gt; เป็นการคัดลอกอักขระตามจำนวน และตำแหน่งเริ่มต้นที่ระบุ ไปเก็บไว้ในรูปแบบของอาร์เรย์ <a href="http://msdn.microsoft.com/en-us/library/system.string.copyto(VS.80).aspx" target="_blank">more</a><br />
<a href="#top">top</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>public class CopyToTest</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>// Embed an  array of characters in a string</p>
<p>string  strSource = &#8220;changed&#8221;;</p>
<p>char[]  destination = { &#8216;T&#8217;, &#8216;h&#8217;, &#8216;e&#8217;, &#8216; &#8216;, &#8216;i&#8217;, &#8216;n&#8217;, &#8216;i&#8217;, &#8216;t&#8217;, &#8216;i&#8217;, &#8216;a&#8217;, &#8216;l&#8217;, &#8216; &#8216;,</p>
<p>&#8216;a&#8217;, &#8216;r&#8217;,  &#8216;r&#8217;, &#8216;a&#8217;,  &#8216;y&#8217; };</p>
<p>// Print the  char array</p>
<p>Console.WriteLine(destination);</p>
<p>// Embed the  source string in the destination string</p>
<p>strSource.CopyTo(0, destination, 4,  strSource.Length);</p>
<p>// Print the  resulting array</p>
<p>Console.WriteLine(destination);</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>Equals<a id="Equals" name="Equals"></a> &gt;&gt; เปรียบเทียบว่าสตริง 2 ตัวเหมือนกันหรือไม่ หากเหมือนจะคืนค่า true <a href="http://msdn.microsoft.com/en-us/library/system.string.equals(VS.80).aspx" target="_blank">more</a><br />
<a href="#top">top</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>using System.Text;</p>
<p>class Sample</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>string  str1 = &#8220;aaa&#8221;;</p>
<p>string  str2 = &#8220;bbb&#8221;;</p>
<p>string  str3 = &#8220;bbb&#8221;;</p>
<p>bool x  = String.Equals(str1,str2);</p>
<p>bool y  = String.Equals(str2, str3);</p>
<p>Console.WriteLine(x);  // str1 is not equal str2,so result is Fault</p>
<p>Console.WriteLine(y);  // str2 is   equal str3,so result is True</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>IndexOf <a id="IndexOf" name="IndexOf"></a>&gt;&gt; เป็นการตรวจสอบตำแหน่งของอักขระในสตริงที่กำหนด หากมีสตริงซ้ำกันหลายตัวจะพิจารณาตัวแรกที่เจอ โดยตำแหน่งเริ่มต้นลำดับเป็น 0 <a href="http://msdn.microsoft.com/en-us/library/system.string.indexof(VS.80).aspx" target="_blank">more</a><br />
<a href="#top">top</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>public class IndexOfTest</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>string  str1 = &#8220;Today is Monday&#8221;;</p>
<p>int i =  str1.IndexOf(&#8220;is&#8221;);</p>
<p>Console.WriteLine(i);// result is 6</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>Insert<a id="Insert" name="Insert"></a> &gt;&gt; เป็นการแทรกสตริงเข้าไปในตำแหน่งที่กำหนด <a href="http://msdn.microsoft.com/en-us/library/system.string.insert(VS.80).aspx" target="_blank">more</a><br />
<a href="#top">top</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>public class InsertTest</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>string  str1 = &#8220;Today is Monday&#8221;;</p>
<p>str1 = str1.Insert(9,&#8221;not &#8220;);</p>
<p>Console.WriteLine(str1);</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>Remove<a id="Remove" name="Remove"></a> &gt;&gt;เป็นการลบสตริงจากตำแหน่งและจำนวนที่กำหนด <a href="http://msdn.microsoft.com/en-us/library/system.string.remove(VS.80).aspx" target="_blank">more</a><br />
<a href="#top">top</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>public class RemoveTest</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>string  str1 = &#8220;Today is not Monday&#8221;;</p>
<p>string  str2 = str1.Remove(9,3);</p>
<p>Console.WriteLine(str2);  //Result : Today is Monday</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>Replace<a id="Replace" name="Replace"></a>&gt;&gt; เป็นการแทนที่สตริงเดิมด้วยสตริงใหม่ <a href="http://msdn.microsoft.com/en-us/library/system.string.replace(VS.80).aspx" target="_blank">more</a><br />
<a href="#top">top</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>class stringReplace1</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>String  str = &#8220;1 2 3 4 5 6 7 8 9&#8243;;</p>
<p>Console.WriteLine(&#8220;Original string: \&#8221;{0}\&#8221;",  str);</p>
<p>Console.WriteLine(&#8220;CSV string:       \&#8221;{0}\&#8221;", str.Replace(&#8216; &#8216;,  &#8216;,&#8217;));</p>
<p>}</p>
<p>}</p>
<p>// This example  produces the following output:</p>
<p>// Original  string: &#8220;1 2 3 4 5 6 7 8 9&#8243;</p>
<p>// CSV  string:      &#8220;1,2,3,4,5,6,7,8,9&#8243;</td>
</tr>
</tbody>
</table>
</li>
<li>Split <a id="Split" name="Split"></a>&gt;&gt; เป็นการคัดแยกสตริงด้วย character ที่กำหนด ผลลัพธ์ที่ได้เก็บไว้ในอาร์เรย์สตริง <a href="http://msdn.microsoft.com/en-us/library/system.string.split(VS.80).aspx" target="_blank">more</a><br />
<a href="#top">top</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>public class SplitTest</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>string  words = &#8220;this is a list of words, with: a bit  of punctuation.&#8221;;</p>
<p>string[]  split = words.Split(new Char[] { &#8216; &#8216;, &#8216;,&#8217;, &#8216;.&#8217;, &#8216;:&#8217; });</p>
<p>foreach  (string s in  split)</p>
<p>{</p>
<p>if  (s.Trim() != &#8220;&#8221;)</p>
<p>Console.WriteLine(s);</p>
<p>}</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>Substring<a id="Substring" name="Substring"></a> &gt;&gt; เป็นการหาสตริงย่อยภายในสตริงที่กำหนด <a href="http://msdn.microsoft.com/en-us/library/system.string.substring(VS.80).aspx" target="_blank">more</a><br />
<a href="#top">top</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>public class SubStringTest</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>string  str1 = &#8220;Microsoft Visual C# &#8220;;</p>
<p>string  str2 = str1.Substring(0,9);</p>
<p>Console.WriteLine(str2);  //Result : Microsoft</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>ToLower<a id="ToLower" name="ToLower"></a> &gt;&gt; แปลงสตริงทั้งหมดเป็นตัวพิมพ์เล็ก <a href="http://msdn.microsoft.com/en-us/library/system.string.tolower(VS.80).aspx" target="_blank">more</a><br />
<a href="#top">top</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>public class ToLowerTest</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>string  str1 = &#8220;FRIENDS FOREVER&#8221;;</p>
<p>str1 = str1.ToLower();</p>
<p>Console.WriteLine(str1);  //Result : friends forever</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>ToString<a id="ToString" name="ToString"></a> &gt;&gt; แปลงค่าที่กำหนดให้เป็นสตริง <a href="http://msdn.microsoft.com/en-us/library/system.string.tostring(VS.80).aspx" target="_blank">more</a><br />
<a href="#top">top</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>class stringToString</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>String  str1 = &#8220;123&#8243;;</p>
<p>String  str2 = &#8220;abc&#8221;;</p>
<p>Console.WriteLine(&#8220;Original str1: {0}&#8221;, str1);</p>
<p>Console.WriteLine(&#8220;Original str2: {0}&#8221;, str2);</p>
<p>Console.WriteLine(&#8220;str1 same as str2?: {0}&#8221;, Object.ReferenceEquals(str1, str2));</p>
<p>str2 = str1.ToString();</p>
<p>Console.WriteLine();</p>
<p>Console.WriteLine(&#8220;New str2:{0}&#8221;, str2);</p>
<p>Console.WriteLine(&#8220;str1 same as str2?: {0}&#8221;, Object.ReferenceEquals(str1, str2));</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</p>
<p>/*This code  produces the following output:</p>
<p>Original str1:  123</p>
<p>Original str2:  abc</p>
<p>str1 same as  str2?: False</p>
<p>New str2:123</p>
<p>str1 same as str2?: True*/</td>
</tr>
</tbody>
</table>
</li>
<li>ToUpper<a id="ToUpper" name="ToUpper"></a> &gt;&gt; แปลงสตริงทั้งหมดเป็นตัวพิมพ์ใหญ่ <a href="http://msdn.microsoft.com/en-us/library/system.string.toupper(VS.80).aspx" target="_blank">more</a><br />
<a href="#top">top</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>public class ToUpperTest</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>string  str1 = &#8221; friends forever&#8221;;</p>
<p>str1 = str1.ToLower();</p>
<p>Console.WriteLine(str1);  //Result : FRIENDS FOREVER</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>TrimEnd<a id="TrimEnd" name="TrimEnd"></a> &gt;&gt; ตัดช่องว่างที่อยู่ท้ายสตริงนั้นออก <a href="http://msdn.microsoft.com/en-us/library/system.string.trimend(VS.80).aspx" target="_blank">more</a><br />
<a href="#top">top</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">using System;</p>
<p>public class TrimTest</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>string  str1 = &#8220;FRIENDS FOREVER &#8220;;</p>
<p>str1 = str1.TrimEnd();</p>
<p>Console.WriteLine(str1);  //Result : FRIENDS FOREVER</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
</ul>
<img src="http://don-jai.com/?ak_action=api_record_view&id=125&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://don-jai.com/cunit-4-string/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>[C#]Unit 3 Array</title>
		<link>http://don-jai.com/cunit-3-array/</link>
		<comments>http://don-jai.com/cunit-3-array/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 02:44:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ซีชาร์ป]]></category>
		<category><![CDATA[พื้นฐาน]]></category>
		<category><![CDATA[อาร์เรย์]]></category>
		<category><![CDATA[เขียนโปรแกรม]]></category>

		<guid isPermaLink="false">http://don-jai.com/?p=124</guid>
		<description><![CDATA[Unit 3 Array
Array

รูปแบบในการสร้างอาร์เรย์ &#62;&#62; มีดังนี้




รูปแบบของคำสั่ง


ตัวอย่าง



DataType [] ArrayName = new DataType[Dimention];
int[] ...]]></description>
			<content:encoded><![CDATA[<p>Unit 3 Array</p>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />Array</p>
<ul>
<li>รูปแบบในการสร้างอาร์เรย์ &gt;&gt; มีดังนี้<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="352" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="282" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td>DataType [] ArrayName = new DataType[Dimention];</td>
<td align="left" valign="top">int[] MyArray = new int[10];</td>
</tr>
</tbody>
</table>
<p>Dimention : มิติของอาร์เรย์ หรือจำนวนสมาชิก โดยที่สมาชิกตัวแรกจะมีลำดับเป็น 0 เสมอ</li>
<li>การกำหนดค่าให้อาร์เรย์ &gt;&gt; มี 2 วิธี1. กำหนดโดยการแจกแจงสมาชิกแต่ละตัว เช่น<br />
<table border="1" width="650">
<tbody>
<tr>
<td>MyArray[0] = 0;</p>
<p>MyArray[1] = 10;</p>
<p>MyArray[2] = 20;</p>
<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..</td>
</tr>
</tbody>
</table>
<p>2. กำหนดในลักษณะของเซต</p>
<table border="1" width="650">
<tbody>
<tr>
<td width="392" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="242" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td>DataType [] ArrayName = {element 1,element 2,&#8230;.element n}</td>
<td align="left" valign="top">int[] Arr = {100,200,300};</td>
</tr>
</tbody>
</table>
</li>
<li>การใช้ข้อมูลในอาร์เรย์<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="317" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="317" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td>foreach (dataType variable in ArrayName){</p>
<p>statement;</p>
<p>}</td>
<td align="left" valign="top">foreach(int i in MyArray){</p>
<p>Console.WriteLine(i);</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>การเรียงลำดับข้อมูลในอาร์เรย์<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="392" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="242" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td>Array.Sort(ArrayName,Startndex,Length);</td>
<td align="left" valign="top">Array.Sort(MyArr,3,5);</td>
</tr>
</tbody>
</table>
<p>StartIndex : ลำดับเริ่มต้นในการเรียงลำดับ หากไม่ระบุหมายถึงเรียงทุกตัว</p>
<p>Length : จำนวนสมาชิกที่ต้องการเรียงลำดับนับจาก<br />
StartIndex</p>
<p>NOTE : ถ้าเป็นตัวเลขจะเรียงจากน้อยไปมาก แตุ่้ถ้าเป็นตัวอักษรจะเรียงจาก A-Z</li>
<li>การเรียงลำดับแบบย้อนกลับ<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="392" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="242" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td>Array.Reverse(ArrayName,Startndex,Length);</td>
<td align="left" valign="top">Array.Reverse(MyArr,3,5);</td>
</tr>
</tbody>
</table>
</li>
<li>การคัดลอกอาร์เรย์<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="392" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="242" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td>Array.Copy(SourceArray,SourceIndex,DesArray,DesIndex,Length);</td>
<td align="left" valign="top">Array.Copy(Arr1,5,Arr2,0,5);</td>
</tr>
</tbody>
</table>
<p>SourceArray : อารเรยที่ี่เราต้องการคัดลอกข้อมูล</p>
<p>SourceIndex : ตำแหน่งที่จะเริ่มทำการคัดลอกข้อมูล</p>
<p>DesArray : อาร์เรย์ที่เราต้องการนำข้อมูลใส่ลงไป</p>
<p>DesIndex : ตำแหน่งเริ่มแรกที่เราต้องการใส่ข้อมูลลงไป</p>
<p>Length : ความยาว หรือจำนวนสมาชิกที่ต้องการก๊อปปี้ไป</li>
<li>การลบค่าของอาร์เรย์<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="316" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="318" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td>Array.Clear(ArrayName,Startndex,Length);</td>
<td align="left" valign="top">Array.Clear(MyArr,3,5);</td>
</tr>
</tbody>
</table>
</li>
<li>การตรวจสอบลำดับในอาร์เรย์<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="319" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="315" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td>Array.IndexOf(ArrayName,Value);</td>
<td align="left" valign="top">Array.IndexOf(MyArr,&#8221;ddd&#8221;);</td>
</tr>
</tbody>
</table>
<p>Value : สมาชิกที่ต้องการทราบอันดับ</li>
<li>การหาความยาว<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="314" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="320" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">ชื่อของอาร์เรย์.Length</td>
<td align="left" valign="top">int[] intArr = {1,2,3,4,5};</p>
<p>int len = intArr.Length; //len = 5</td>
</tr>
</tbody>
</table>
</li>
<li>การหาขอบเขตของอาร์เรย์1.ขอบเขตบน หรือสมาชิกตัวแรก (Upper Bound)<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="314" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="320" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">ชื่อของอาร์เรย์.GetUpperBound(Dimension)</td>
<td align="left" valign="top">int[] intArr = {1,2,3,4,5};</p>
<p>int upper = intArr.GetUpperBound(0); // upper= 4</td>
</tr>
</tbody>
</table>
<p>2. ขอบเขตล่าง หรือสมาชิกตัวสุดท้าย (Lower Bound)</p>
<table border="1" width="650">
<tbody>
<tr>
<td width="314" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="320" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">ชื่อของอาร์เรย์.GetLowerBound(Dimension)</td>
<td align="left" valign="top">int[] intArr = {1,2,3,4,5};</p>
<p>int lower = intArr.GetLowerBound(0); // lower = 0</td>
</tr>
</tbody>
</table>
</li>
<li>อาร์เรย์หลายมิติ &gt;&gt; อาร์เรย์ที่สมาชิกแต่ละตัวเก็บข้อมูลมากกว่า 1 ค่า ส่วนใหญ่จะใช้ไม่เกิน 2 มิติ<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="407" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="227" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td>DataType [,] ArrayName = new DataType[UpperB,LowerB];</td>
<td align="left" valign="top">int[] MyArray = new int[5,2];</td>
</tr>
</tbody>
</table>
</li>
<li>การกำหนดข้อมูลให้กับอาร์เรย์หลายมิติ1. กำหนดโดยการแจกแจงสมาชิกแต่ละตัว เช่น<br />
<table border="1" width="650">
<tbody>
<tr>
<td height="79">MyArr[0,0] = 0;</p>
<p>MyArr[0,1] = 1;</p>
<p>MyArr[1,0] = 2;</p>
<p>MyArr[1,1] = 3;</td>
</tr>
</tbody>
</table>
<p>2. กำหนดในลักษณะของเซต</p>
<table border="1" width="650">
<tbody>
<tr>
<td>int[,] MyArr ={{1,2} , {3,4} ,{5,6}};</p>
<p>string[,] animal = {{&#8220;ant,bird&#8221;},{&#8220;cat,dog&#8221;}};</td>
</tr>
</tbody>
</table>
</li>
</ul>
<img src="http://don-jai.com/?ak_action=api_record_view&id=124&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://don-jai.com/cunit-3-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[C#]Unit 2 การกำหนดเงื่อนไข</title>
		<link>http://don-jai.com/cunit-2-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%81%e0%b8%b3%e0%b8%ab%e0%b8%99%e0%b8%94%e0%b9%80%e0%b8%87%e0%b8%b7%e0%b9%88%e0%b8%ad%e0%b8%99%e0%b9%84%e0%b8%82/</link>
		<comments>http://don-jai.com/cunit-2-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%81%e0%b8%b3%e0%b8%ab%e0%b8%99%e0%b8%94%e0%b9%80%e0%b8%87%e0%b8%b7%e0%b9%88%e0%b8%ad%e0%b8%99%e0%b9%84%e0%b8%82/#comments</comments>
		<pubDate>Mon, 23 Jun 2008 02:43:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[condition]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[การกำหนดเงื่อนไข]]></category>
		<category><![CDATA[ซีชาร์ป]]></category>
		<category><![CDATA[พื้นฐาน]]></category>
		<category><![CDATA[เขียนโปรแกรม]]></category>

		<guid isPermaLink="false">http://don-jai.com/?p=123</guid>
		<description><![CDATA[Unit 2 : การกำหนดเงื่อนไข
รูปแบบของการกำหนดเงื่อนไข

Selection Statement เป็นการเลือกทำเมื่อตรงกับเงื่อนไขที่ต้องการ
Iteration Statement  เป็นการวนรอบเพื่อตามคำสั่งเดียวกันซ้ำๆ ภายใต้เงื่อนไขที่กำหนด
Jump ...]]></description>
			<content:encoded><![CDATA[<p>Unit 2 : การกำหนดเงื่อนไข</p>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />รูปแบบของการกำหนดเงื่อนไข</p>
<ul>
<li>Selection Statement เป็นการเลือกทำเมื่อตรงกับเงื่อนไขที่ต้องการ</li>
<li>Iteration Statement  เป็นการวนรอบเพื่อตามคำสั่งเดียวกันซ้ำๆ ภายใต้เงื่อนไขที่กำหนด</li>
<li>Jump Statement เป็นการกระโดดไปยังส่วนอื่นของโปรแกรม  เมื่อโปรแกรมประมวลผลมาถึงตำแหน่งนั้นๆ</li>
</ul>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />Selection Statement</p>
<ul>
<li>If &gt;&gt; เป็นการเปรียบเทียบเงื่อนไขว่าตรงตามที่เรากำหนดหรือไม่ หากตรงก็จะทำตามคำสั่งที่กำหนด แต่หากไม่ตรงก็จะข้ามคำสั่งส่วนนั้นไป<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="316" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="318" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">if( condition){</p>
<p>statement;</p>
<p>}</td>
<td align="left" valign="top">if(x==y){</p>
<p>Console.Write(&#8220;x equals y&#8221;);</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>If…else &gt;&gt; เป็นการกำหนดทางเลือกอื่นๆในการทำงานนอกเหนือจากที่กำหนดใน if โดยที่หากเงื่อนไขไม่ตรงกับที่ระบุไว้ใน if โปรแกรมจะทำตามคำสั่งที่ระบุในส่วนของ else<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="316" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="318" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td width="318" align="left" valign="top">if( condition){</p>
<p>statement; // do if condition match</p>
<p>}</p>
<p>else{</p>
<p>statement; // do other things</p>
<p>}</td>
<td width="316" align="left" valign="top">if(x&gt;y){</p>
<p>z = x &#8211; y;</p>
<p>}</p>
<p>else{</p>
<p>z = y &#8211; x;</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>else if &gt;&gt; ใช้ในกรณีที่เงื่อนไขที่เราต้องการตรวจสอบมีหลายเงื่อนไข<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="316" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="318" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td width="315" align="left" valign="top">if( condition){</p>
<p>statement;</p>
<p>}</p>
<p>else if( condition){</p>
<p>statement;</p>
<p>}</p>
<p>else{</p>
<p>statement;</p>
<p>}</td>
<td width="319" align="left" valign="top">if( score &gt;= 90){</p>
<p>grade = &#8220;A&#8221; ;</p>
<p>}</p>
<p>else if( score &gt;= 80){</p>
<p>grade = &#8220;B&#8221; ;</p>
<p>}</p>
<p>else{</p>
<p>grade = &#8220;D&#8221;;</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>Nest if &gt;&gt; ใช้เมื่อต้องการตรวจสอบเงื่อนไขหลายๆเงื่อนไขร่วมกัน<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="316" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="318" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td width="316" height="41" align="left" valign="top">if(condition){</p>
<p>if(condition){</p>
<p>if(condition){</p>
<p>statement;</p>
<p>}</p>
<p>else{</p>
<p>statement;</p>
<p>}</p>
<p>}</p>
<p>}</td>
<td width="318" align="left" valign="top">if(x&gt;5){</p>
<p>if(y&gt;30){</p>
<p>if(x != y){</p>
<p>x += y ;</p>
<p>}</p>
<p>else{</p>
<p>x -= y;</p>
<p>}</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>switch…case &gt;&gt; ใช้ในกรณีที่เราีมีหลายเงื่อนไขที่ต้องตรวจสอบ วิธีนี้จะสะดวกกว่าการใช้ else if หลายๆรอบ<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="316" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="318" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td width="317" height="48" align="left" valign="top">switch(expression){</p>
<p>case value 1: statement 1;</p>
<p>break;</p>
<p>case value 2: statement 2;</p>
<p>break;</p>
<p>case value 3: statement 3;</p>
<p>break;</p>
<p>case value n: statement n;</p>
<p>break;</p>
<p>default : statement; // ใช้ในกรณีที่ไม่เข้ากับเงื่อนไขใดเลย</p>
<p>}</td>
<td width="317" align="left" valign="top">d = int.Parse(Console.ReadLine());</p>
<p>switch(d){</p>
<p>case value 1: myday = &#8220;Sunday&#8221;;</p>
<p>break;</p>
<p>case value 2: myday = &#8220;Monday&#8221;;</p>
<p>break;</p>
<p>case value 3: myday = &#8220;Tueday&#8221;;</p>
<p>break;</p>
<p>case value 4: myday = &#8220;Wednesday&#8221;;</p>
<p>break;</p>
<p>default : myday = &#8220;Unknown&#8221;;</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
</ul>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />Iteration Statement</p>
<ul>
<li>for &gt;&gt; เป็นการทำงานซ้ำตามจำนวนครั้งที่กำหนด โดยเริ่มจากค่าแรกไปจนถึงค่าสุดท้าย<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="316" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="318" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td width="444" align="left" valign="top">for(counter = first value; counter condition; adjust counter value){</p>
<p>statement;</p>
<p>}</td>
<td width="190" align="left" valign="top">for(int i=1;i&lt;=10;i++){</p>
<p>sum +=i;</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>Nest for…loop &gt;&gt; เป็นการวบลูปซ้อนกัน เมื่อมีหลายเงื่อนไข<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="316" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="318" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td width="318" align="left" valign="top">for(){</p>
<p>for(){</p>
<p>for(){</p>
<p>statement;</p>
<p>}</p>
<p>}</p>
<p>}</td>
<td width="316" align="left" valign="top">for(i=0;i&lt;5;i++){</p>
<p>for(j=0;j&gt;9;j++){</p>
<p>for(k=0;k&gt;=17;k++){</p>
<p>sum += i+j+k;</p>
<p>}</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>foreach…in &gt;&gt;ใช้ในกรณีที่ตัวแปรตัวนั้นเก็บข้อมูลหลายค่าเอาไว้ เช่น Array<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="316" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="318" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td width="369" align="left" valign="top">foreach( ชนิดข้อมูล ตัวแปร in ตัวแปรที่เก็บข้อมูล){</p>
<p>statement;</p>
<p>}</td>
<td width="265" align="left" valign="top">foreach(string s in args){</p>
<p>Console.WriteLine(s);</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>while &gt;&gt; ใช้เมื่อทราบเงื่อนไขบางอย่าง แต่ไม่ทราบค่าเริ่มต้นและค่าสุดท้ายของลูป<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="316" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="318" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">while(condition){</p>
<p>statement;</p>
<p>}</td>
<td align="left" valign="top">while(x&lt;100){</p>
<p>x += 1 ;</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>do…while…&gt;&gt; เป็นการตรวจสอบเงื่อนไขคล้าย while แต่do..while จะตรวจสอบเงื่อนไขที่ท้ายลูป<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="316" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="318" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">do{</p>
<p>statement;</p>
<p>}while(condition);</td>
<td align="left" valign="top">do{</p>
<p>sum +=1</p>
<p>}while(sum&lt;10);</td>
</tr>
</tbody>
</table>
</li>
</ul>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />Jump Statement</p>
<ul>
<li>break &gt;&gt; เป็นการสั่งให้ออกจากลูปโดยการหยุดการตรวจสอบเงื่อนไขถัดไป</li>
<li>continue &gt;&gt; เป็นการสั่งให้วนลูปถัดไปโดยไม่ทำคำสั่งที่เหลือในลูปนั้น</li>
</ul>
<img src="http://don-jai.com/?ak_action=api_record_view&id=123&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://don-jai.com/cunit-2-%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b8%81%e0%b8%b3%e0%b8%ab%e0%b8%99%e0%b8%94%e0%b9%80%e0%b8%87%e0%b8%b7%e0%b9%88%e0%b8%ad%e0%b8%99%e0%b9%84%e0%b8%82/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[C#]Unit 1 พื้นฐาน C# ตอน 3</title>
		<link>http://don-jai.com/unit-1-%e0%b8%9e%e0%b8%b7%e0%b9%89%e0%b8%99%e0%b8%90%e0%b8%b2%e0%b8%99-c-%e0%b8%95%e0%b8%ad%e0%b8%99-3/</link>
		<comments>http://don-jai.com/unit-1-%e0%b8%9e%e0%b8%b7%e0%b9%89%e0%b8%99%e0%b8%90%e0%b8%b2%e0%b8%99-c-%e0%b8%95%e0%b8%ad%e0%b8%99-3/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 02:39:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[การพัฒนาโปรแกรมบน Visual C# .NET]]></category>
		<category><![CDATA[ซีชาร์ป]]></category>
		<category><![CDATA[พื้นฐาน]]></category>
		<category><![CDATA[เขียนโปรแกรม]]></category>

		<guid isPermaLink="false">http://don-jai.com/?p=135</guid>
		<description><![CDATA[Unit 1 : พื้นฐาน C# ตอน 3
การพัฒนาโปรแกรมบน Visual C# .NET

พื้นฐานทั่วไปVisual ...]]></description>
			<content:encoded><![CDATA[<p>Unit 1 : พื้นฐาน C# ตอน 3</p>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />การพัฒนาโปรแกรมบน Visual C# .NET</p>
<ul>
<li>พื้นฐานทั่วไปVisual C# .NET เป็นเครื่องมือในการพัฒนาโปรแกรมด้วย C# ซึ่งเป็นหนึ่งในชุด Visual Studio .NET ของ Microsoft มีทั้งการเขียนแบบ Visual และแบบ Console Application ซึ่งจริงๆแล้วสำหรับมือใหม่อาจจะเริ่มต้นด้วย Sharpdev ก็ได้</li>
<li>Download Programโหลดได้ฟรีจากเว็บไมโครซอฟท์ แต่มันอืดเลยเอามา Mirror ให้ละกัน<a href="ftp://ftp.cpsk.info/mirror/VS2008ExpressENUX1397868.iso" target="_blank">ftp://ftp.cpsk.info/mirror/VS2008ExpressENUX1397868.iso</a>เป็น UDF ISO จะไรท์ลงแผ่น, Extract แล้วลง, หรือจะ ImageDrive ยังไงก็ได้ ลองดูตามสบาย<br />
โดยรวมๆ มันก็เหมือนกับ VS2005EE แหละ แต่โดยรวมแล้ว UI จะลื่นไหลกว่า และ Support .NET Framework ถึง 3.5</p>
<p>สำหรับ .NET Framework รุ่นต่างๆ โหลดได้ข้างล่างนี่ (เครื่องทั่วไปจะมีถึง 2.0 แล้ว โหลดแค่ 3.0, 3.5 ก็พอ)</p>
<ul>
<li><strong> .NET Framework 1.0</strong> <a href="ftp://ftp.cpsk.info/mirror/dotnetfx10.exe" target="_blank">ftp://ftp.cpsk.info/mirror/dotnetfx10.exe</a></li>
<li><strong> .NET Framework 1.1</strong> <a href="ftp://ftp.cpsk.info/mirror/dotnetfx11.exe" target="_blank">ftp://ftp.cpsk.info/mirror/dotnetfx11.exe</a></li>
<li><strong>.NET Framework 2.0</strong> <a href="ftp://ftp.cpsk.info/mirror/dotnetfx20.exe" target="_blank">ftp://ftp.cpsk.info/mirror/dotnetfx20.exe</a></li>
<li><strong> .NET Framework 3.0</strong> <a href="ftp://ftp.cpsk.info/mirror/dotnetfx30.exe" target="_blank">ftp://ftp.cpsk.info/mirror/dotnetfx30.exe</a></li>
<li><strong> .NET Framework 3.5</strong> <a href="ftp://ftp.cpsk.info/mirror/dotnetfx35.exe" target="_blank">ftp://ftp.cpsk.info/mirror/dotnetfx35.exe</a></li>
</ul>
</li>
<li>เริ่มต้น1.เปิดโปรแกรม2.เลือก File &gt;&gt;New Project &gt;&gt; เลือก Console Application
<p>3. ช่อง Name ใส่ชื่อของproject</p>
<p>4. ช่อง Location ใส ่Directory ที่จะใช้เก็บ Project</p>
<p>5. ช่อง Solutionให้เลือกวิธีการเก็บ Project โดยปกติก็ไม่ต้องเลือก<br />
แต่ถ้าต้องการนำ Project เพิ่มเข้าไปใน Project อื่นก็เลือกเป็น Add to Solution</p>
<p>6. จะอธิบายส่วนที่สำคัญก่อน โดยสามารถลบส่วนอื่นทิ้งไปก่อนได้เลย</p>
<p>using System &gt;&gt;  เป็นการประกาศใช้องค์ประกอบพื้นฐานของระบบในการทำงานทั่วๆไป</p>
<p>class &gt;&gt; เป็นส่วนที่เราเอาไว้เก็บรายละเอียดทั้งหมด</p>
<p>static void Main(string[] args){&#8230;} &gt;&gt; เป็นMethod หลักของ class</li>
<li>Console.Write/WriteLine<br />
เป็นคำสั่งสำหรับเขียนข้อความลงบน Console Window เำพื่อแสดงผลลัพธ์ในแบบ Text<br />
1. Console.Write(ข้อความ) &gt;&gt; เป็นการเขียนข้อความลงไปแล้วเคอร์เซอร์จะไปหยุดรออยู่ที่ท้ายข้อความนั้น เช่น</p>
<table border="1" width="650">
<tbody>
<tr>
<td>Console.Write(&#8220;Hello&#8221;);</td>
</tr>
</tbody>
</table>
<p>2.    Console.WriteLine(ข้อความ) &gt;&gt; เป็นการเขียนข้อความลงไปแล้วเคอร์เซอร์จะไปหยุดรออยู่บรรทัดถัดไป เช่น</p>
<table border="1" width="650">
<tbody>
<tr>
<td>Console.WriteLine(&#8220;Hello World &#8220;);</td>
</tr>
</tbody>
</table>
</li>
<li>Console.Read/ReadLine<br />
ใช้ในการอ่านข้อมูลที่ผู้ใช้ใส่เข้าไปจากคีย์บอร์ด ณ จดที่รอรับคำสั่ง</p>
<p>1. Console.Read() &gt;&gt; เป็นการอ่านค่าอักขระในตำแหน่งถัดไป ในรูปแบบของ integer(int)</p>
<p>2. Console.ReadLine() &gt;&gt; อ่านข้อมูลอยู่ที่บรรทัดถัดไปในรูปแบบของ string &lt;นิยมใช้มากกว่า&gt;เช่น</p>
<table border="1" width="650">
<tbody>
<tr>
<td>string name = Console.ReadLine();</td>
</tr>
</tbody>
</table>
</li>
<li>การรันโปรแกรม มี 2 วิธี1.กด F5 บนคีย์บอร์ด2.เลือกปุ่มสามเหลี่ยมสีเขียวที่ Toolbar
<p>Tip : ถ้าหากรันโปรแกรมแล้วดูไม่ทันให้ใส่ Console.Read(); ต่อ</li>
<li>การรับข้อมูลที่เป็นตัวเลขการรับข้อมูลผ่านเมธอด ReadLine จะเป็นการรับข้อมูลมาในรูปแบบของ string ดังนั้นถ้าเราต้องการแปลงจาก string ให้เป็นตัวเลขให้ทำดังนี้1.ชนิดข้อมูล.Parse(string);<br />
<table border="1" width="650">
<tbody>
<tr>
<td>string str = Console.ReadLine();</p>
<p>int x = int.Parse(str) ;</p>
<p>double s = double.Parse(str);</td>
</tr>
</tbody>
</table>
<p>2.<br />
Convert.Toxxx(string); // เมื่อ xxx คือชนิดข้อมูลที่ต้องการ</p>
<table border="1" width="650">
<tbody>
<tr>
<td>string str = Console.ReadLine();</p>
<p>single s = Convert.ToSingle(str);</td>
</tr>
</tbody>
</table>
</li>
<li>การแทรกข้อมูลลงในสตริงการแทรกข้อมูลหรือการนำเอาข้อมูลมาแสดงรวมกัน เช่น<br />
<table border="1" width="650">
<tbody>
<tr>
<td>string name = &#8220;Nicole&#8221;;</p>
<p>int age = 33;</td>
</tr>
</tbody>
</table>
<p>ถ้าต้องการว่า Her name is Nicole and her age is 33 years old สามารถทำได้ 2 วิธี</p>
<table border="1" width="650">
<tbody>
<tr>
<td>Console.Write(&#8220;Her name is&#8221;+ name +&#8221;and her age is&#8221; + age +&#8221;years old &#8220;);</td>
</tr>
</tbody>
</table>
<table border="1" width="650">
<tbody>
<tr>
<td>Console.Write(&#8220;Her name is {0} and her age is {1} years old &#8220;,name,age);</td>
</tr>
</tbody>
</table>
</li>
<li>อักขระพิเศษเป็นอักขระที่นำมาใช้ในการควบคุมการแสดงในแต่ละบรรทัด1. \n  &gt;&gt;ใช้ในการสั่งให้ขึ้นบรรทัดใหม่
<p>2. \t  &gt;&gt;ใช้เมื่อต้องการให้เว้นระยะไปเท่ากับ 1 แท๊บ</p>
<p>3. \r &gt;&gt; Carriage Return สิ้นสุดบรรทัด</li>
<li>การปรับแต่ง Source Code Editorเลือก Tool&gt;&gt;Options&#8230; &gt;&gt; Environment &gt;&gt; Fonts and Colors</li>
<li>การบันทึก มี 2 วิธี1.เลือก File &gt;&gt; Save All2.กด Ctrl+Shift+s บนคีย์บอร์ด</li>
<li>การเปิด Project เดิม มี 2 วิธี1. เลือก File &gt;&gt; Open Project แล้วเลือกไฟล์ที่มีชื่อเดียวกับProject2. กด Ctrl+Shift+o บนคีย์บอร์ด แล้วเลือกไฟล์ที่มีชื่อเดียวกับProject</li>
</ul>
<img src="http://don-jai.com/?ak_action=api_record_view&id=135&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://don-jai.com/unit-1-%e0%b8%9e%e0%b8%b7%e0%b9%89%e0%b8%99%e0%b8%90%e0%b8%b2%e0%b8%99-c-%e0%b8%95%e0%b8%ad%e0%b8%99-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[C#]Unit 1 พื้นฐาน C# ตอน2</title>
		<link>http://don-jai.com/cunit-1-%e0%b8%9e%e0%b8%b7%e0%b9%89%e0%b8%99%e0%b8%90%e0%b8%b2%e0%b8%99-c-%e0%b8%95%e0%b8%ad%e0%b8%992/</link>
		<comments>http://don-jai.com/cunit-1-%e0%b8%9e%e0%b8%b7%e0%b9%89%e0%b8%99%e0%b8%90%e0%b8%b2%e0%b8%99-c-%e0%b8%95%e0%b8%ad%e0%b8%992/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 02:32:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Opeator]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Type Conversion]]></category>
		<category><![CDATA[การกำหนดตัวแปรและข้อมูล]]></category>
		<category><![CDATA[การแปลงชนิดของข้อมูล]]></category>
		<category><![CDATA[ซีชาร์ป]]></category>
		<category><![CDATA[พื้นฐาน]]></category>
		<category><![CDATA[เขียนโปรแกรม]]></category>

		<guid isPermaLink="false">http://don-jai.com/?p=134</guid>
		<description><![CDATA[Unit 1 : พื้นฐาน C# ตอน 2
การกำหนดตัวแปรและข้อมูล

ตัวแปร(Variable) &#62;&#62; เป็นสัญลักษณ์ที่เรานำมาใช้แทนข้อมูลต่าง โดยมีหลักการตั้งชื่อตัวแปรดังนี้1. ...]]></description>
			<content:encoded><![CDATA[<p>Unit 1 : พื้นฐาน C# ตอน 2</p>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />การกำหนดตัวแปรและข้อมูล</p>
<ul>
<li>ตัวแปร(Variable) &gt;&gt; เป็นสัญลักษณ์ที่เรานำมาใช้แทนข้อมูลต่าง โดยมีหลักการตั้งชื่อตัวแปรดังนี้1. ต้องขึ้นต้นด้วยตัวอักษรเท่านั้น ห้ามใช้ตัวเลข หรืออักขระเป็นตัวเริ่มต้น2. Case Sensitive ตัวเล็ก ตัวใหญ่ เป็นตัวพิมพ์คนละตัว3.ส่วนใหญ่เรามักจะใช้ตัวพิมพ์เล็กทั้งหมด</li>
<li>ชนิดของข้อมูล</li>
<li>การประกาศใช้ตัวแปร &gt;&gt; แบ่งเป็น 2 วิธีดังนี้1. ชนิดของข้อมูล ชื่อตัวแปร;<br />
<table border="1" width="650">
<tbody>
<tr>
<td>int i;</td>
</tr>
</tbody>
</table>
<p>2. ชนิดของข้อมูล ชื่อตัวแปร = ค่าเริ่มต้นของตัวแปร;</p>
<table border="1" width="650">
<tbody>
<tr>
<td>double d = 10.99;</td>
</tr>
</tbody>
</table>
</li>
<li>ค่าคงที่(Constant) &gt;&gt; เป็นตัวแปรที่เรากำหนดค่าตายตัวไม่สามารถเปลี่ยนแปลงค่าได้ วิธีใช้ก็ให้ใส่ const หน้าการประกาศตัวแปร<br />
<table border="1" width="650">
<tbody>
<tr>
<td>const int x = 1;</td>
</tr>
</tbody>
</table>
</li>
</ul>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />็Operators</p>
<ul>
<li>Operators พื้นฐาน &gt;&gt; ใช้ในการคำนวณทางคณิตศาสตร์ ซึ่งประกอบด้วย<br />
<table border="1" width="400">
<tbody>
<tr>
<td width="144" align="center" valign="top">Operator</td>
<td width="340" align="left" valign="top">ใช้สำหรับ</td>
</tr>
<tr>
<td align="center" valign="top">+</td>
<td align="left" valign="top">บวก</td>
</tr>
<tr>
<td align="center" valign="top">-</td>
<td align="left" valign="top">ลบ</td>
</tr>
<tr>
<td align="center" valign="top">*</td>
<td align="left" valign="top">คูณ</td>
</tr>
<tr>
<td align="center" valign="top">/</td>
<td align="left" valign="top">หาร</td>
</tr>
<tr>
<td align="center" valign="top">%</td>
<td align="left" valign="top">หารแบบเอาเฉพาะเศษ</td>
</tr>
</tbody>
</table>
</li>
<li>Shortcut Operator &gt;&gt; เป็นเครื่องหมายในการเปลี่ยนแปลงค่าของข้อมูลโดยวิธีลัด<br />
<table border="1" width="500">
<tbody>
<tr>
<td align="center" valign="top">รูปแบบ</td>
<td align="center" valign="top">ตัวอย่างการกำหนด</td>
<td align="center" valign="top">เทียบเท่ากับ</td>
</tr>
<tr>
<td align="center" valign="top">+ =</td>
<td align="center" valign="top">x + = 8</td>
<td align="center" valign="top">x = x + 8</td>
</tr>
<tr>
<td align="center" valign="top">- =</td>
<td align="center" valign="top">x &#8211; = 8</td>
<td align="center" valign="top">x = x &#8211; 8</td>
</tr>
<tr>
<td align="center" valign="top">* =</td>
<td align="center" valign="top">x * = 8</td>
<td align="center" valign="top">x = x * 8</td>
</tr>
<tr>
<td align="center" valign="top">/ =</td>
<td align="center" valign="top">x / = 8</td>
<td align="center" valign="top">x = x / 8</td>
</tr>
<tr>
<td align="center" valign="top">% =</td>
<td align="center" valign="top">x % = 8</td>
<td align="center" valign="top">x = x % 8</td>
</tr>
</tbody>
</table>
</li>
<li>Increment , Decrement OperatorIncrement (++) เป็นการเพิ่มค่าตัวแปรที่ระบุไปอีก 1 เช่น x = 10; x++; //x =11Decrement (&#8211;) เป็นการลดค่าตัวแปรที่ระบุออกไปอีก 1 เช่น x = 10 ;x&#8211;; //x=9</li>
<li>Comparison  Operator &gt;&gt; เป็นเครื่องหมายในการเปรียบเทียบระหว่าง 2 นิพจน์<br />
<table border="1" width="500">
<tbody>
<tr>
<td align="center" valign="top">เครื่องหมาย</td>
<td align="center" valign="top">ความหมาย</td>
</tr>
<tr>
<td align="center" valign="top">&lt;</td>
<td align="left" valign="top">น้อยกว่า</td>
</tr>
<tr>
<td align="center" valign="top">&lt;=</td>
<td align="left" valign="top">น้อยกว่า หรือ เท่ากับ</td>
</tr>
<tr>
<td align="center" valign="top">&gt;</td>
<td align="left" valign="top">มากกว่า</td>
</tr>
<tr>
<td align="center" valign="top">&gt;=</td>
<td align="left" valign="top">มากกว่า หรือ เท่ากับ</td>
</tr>
<tr>
<td align="center" valign="top">==</td>
<td align="left" valign="top">เท่ากับ</td>
</tr>
<tr>
<td align="center" valign="top">!=</td>
<td align="left" valign="top">ไม่เท่ากับ</td>
</tr>
</tbody>
</table>
</li>
<li>Boolean Operator &gt;&gt; เครื่องหมายสำหรับการเปรียบเทียบทางตรรกะ<br />
<table border="1" width="500">
<tbody>
<tr>
<td width="215" align="center" valign="top">เครื่องหมาย</td>
<td width="269" align="center" valign="top">ชื่อ</td>
</tr>
<tr>
<td align="center" valign="top">!</td>
<td align="center" valign="top">not</td>
</tr>
<tr>
<td align="center" valign="top">&amp;&amp;</td>
<td align="center" valign="top">and</td>
</tr>
<tr>
<td align="center" valign="top">||</td>
<td align="center" valign="top">or</td>
</tr>
<tr>
<td align="center" valign="top">^</td>
<td align="center" valign="top">exclusive or</td>
</tr>
</tbody>
</table>
</li>
<li>ลำดับความสำคัญของ Opeator<br />
<table border="1" width="500">
<tbody>
<tr>
<td width="151" align="center" valign="top">ลำดับ</td>
<td width="333" align="center" valign="top">Operator</td>
</tr>
<tr>
<td align="center" valign="top">1</td>
<td align="left" valign="top">( )</td>
</tr>
<tr>
<td align="center" valign="top">2</td>
<td align="left" valign="top">++,&#8211;, !, Cast</td>
</tr>
<tr>
<td align="center" valign="top">3</td>
<td align="left" valign="top">* , / ,%</td>
</tr>
<tr>
<td align="center" valign="top">4</td>
<td align="left" valign="top">+ , -</td>
</tr>
<tr>
<td align="center" valign="top">5</td>
<td align="left" valign="top">&lt; , &lt;= , &gt; , &gt;=</td>
</tr>
<tr>
<td align="center" valign="top">6</td>
<td align="left" valign="top">== ,!=</td>
</tr>
<tr>
<td align="center" valign="top">7</td>
<td align="left" valign="top">&amp;&amp;</td>
</tr>
<tr>
<td align="center" valign="top">8</td>
<td align="left" valign="top">||</td>
</tr>
<tr>
<td align="center" valign="top">9</td>
<td align="left" valign="top">?:</td>
</tr>
<tr>
<td align="center" valign="top">10</td>
<td align="left" valign="top">= , += , -= , *= , /= , %=</td>
</tr>
</tbody>
</table>
</li>
</ul>
<p>Type Conversion &gt;&gt; เป็นการแปลงชนิดของข้อมูล</p>
<ul>
<li> Implicit &gt;&gt; การแปลงข้อมูลที่เกิดขึ้นอัตโนมัติ คือแปลงจากขนาดเล็กไปขนาดใหญ่<br />
<table border="1" width="650">
<tbody>
<tr>
<td>int a =123;</p>
<p>long b = a;</td>
</tr>
</tbody>
</table>
</li>
<li>Explicit &gt;&gt; การแปลงแบบ Cast คือแปลงจากขนาดใหญกว่า่ไปขนาดเล็กกว่า ทำโดยนำ้ชนิดของข้อมูลที่ต้องการ Cast ไปวางไว้หน้าข้อมูลนั้น แต่ต้องระวังการสูญหายของข้อมูลด้วย<br />
<table border="1" width="650">
<tbody>
<tr>
<td>long b = 34L;</p>
<p>int c = (int) b;</p>
<p>double y = 99.99;</p>
<p>int x = (int) y;</td>
</tr>
</tbody>
</table>
</li>
</ul>
<img src="http://don-jai.com/?ak_action=api_record_view&id=134&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://don-jai.com/cunit-1-%e0%b8%9e%e0%b8%b7%e0%b9%89%e0%b8%99%e0%b8%90%e0%b8%b2%e0%b8%99-c-%e0%b8%95%e0%b8%ad%e0%b8%992/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[C#]Unit 6 OOP</title>
		<link>http://don-jai.com/cunit-6-oop/</link>
		<comments>http://don-jai.com/cunit-6-oop/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 08:09:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ซีชาร์ป]]></category>
		<category><![CDATA[พื้นฐาน]]></category>
		<category><![CDATA[เขียนโปรแกรม]]></category>

		<guid isPermaLink="false">http://don-jai.com/?p=127</guid>
		<description><![CDATA[Unit 6 OOP
 Intro
Object Oriented Programming เป็นการเขียนโปรแกรมเชิงวัตถุ โดย ออบเจ็กต์นี้จะประกอบด้วยคุณสมบัติประจำตัวของออบเจ็กต์ที่เรียกว่า &#8221; ...]]></description>
			<content:encoded><![CDATA[<p>Unit 6 OOP</p>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" /> Intro</p>
<p>Object Oriented Programming เป็นการเขียนโปรแกรมเชิงวัตถุ โดย ออบเจ็กต์นี้จะประกอบด้วยคุณสมบัติประจำตัวของออบเจ็กต์ที่เรียกว่า &#8221; Property&#8221; และพฤติกรรมหรือที่เรียกว่า &#8220;Method&#8221; ซึ่งองค์ประกอบเหล่านี้เราจะกำหนดผ่าน Class นั่นเอง ดังนั้นการสร้างออบเจ็กต์จึงต้องเริ่มที่การสร้าง Class ก่อน เพื่อกำหนดโครงสร้างต่างๆ ของออบเจ็กต์นั้น</p>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" /> การสร้าง Object จาก Class</p>
<p>ในการสร้างออบเจ๊กต์จากคลาสนั้นเราเริ่มด้วยการสร้างตัวอ้างอิงของคลาสที่เรียกว่า &#8220;Instance&#8221; ก่อน โดย อินสแตนซ์นี้จะเป็นชื่อที่เราต้องการกำหนดให้กับออบเจ็กต์นั่นเอง ขั้นตอนการสร้่างอินสแตนซ์นี้เราเรียกว่า &#8220;Instantiation&#8221; วิธีการทำมีดังนี้</p>
<p>1. กำหนด InstanceName</p>
<table border="1" width="650">
<tbody>
<tr>
<td width="317" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="317" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">className InstanceName</td>
<td align="left" valign="top">circle myCircle;</td>
</tr>
</tbody>
</table>
<p>2.นำอินสแตนซ์ที่ได้มาสร้างเป็นออบเจ็กต์ด้วยรูปแบบดังนี้</p>
<table border="1" width="650">
<tbody>
<tr>
<td width="317" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="317" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">InstanceName = new className(argument);</td>
<td align="left" valign="top">myCircle = new circle();</td>
</tr>
</tbody>
</table>
<p>หรือสามารถรวบเหลือขั้นตอนเดียวเลยก็ได้</p>
<table border="1" width="650">
<tbody>
<tr>
<td width="368" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="266" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">className InstanceName  = new className(argument);</td>
<td align="left" valign="top">circle myCircle = new circle();</td>
</tr>
</tbody>
</table>
<p>3. ตอนนี้เราได้ออบเจ๊กต์ myCircle ซึ่งมีองค์ประกอบต่างๆ ตามที่ระบุไว้ในคลาส circle ทุกประการ หากเราต้องการเรียกใช้องค์ประกอบใดของคลาส ให้ทำดังนี้</p>
<table border="1" width="650">
<tbody>
<tr>
<td width="368" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="266" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">InstanceName.xxx // xxx = method,property,data</td>
<td align="left" valign="top">myCircle.Radius;</td>
</tr>
</tbody>
</table>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />Constructor</p>
<p>ในการสร้างออบเจ็กต์จากคลาส ในบางกรณีเราจำเป็นต้องกำหนดค่าบางอย่างที่จำเป็นในการเรียกใช้งานเบื้องต้น เราสามารถกำหนดค่าเหล่านี้ไส้ในเมธอดพิเศษที่เรียกว่า &#8220;Constructor&#8221; โดยมีข้อกำหนดดังนี้<br />
- ชื่อของ Constructor ต้องเป็นชื่อเดียวกับคลาส<br />
- เราสามารถกำหนดให้มี constructor ชื่อเดียวกันไ้ด้หลายตัวในคลาสเดียวกัน สำหรับการรับค่าอาร์กิวเมนต์ที่ต่างกัน ซึ่งก็คือการทำ Overloading นั่นเอง<br />
- สามารถกำหนด modifier ให้กับเมธอดได้เพียงระดับ public หรือไม่กำหนดอะไรเลย<br />
- constructor ไม่มีการส่งค่ากลับ แต่ ไม่ต้องระบุ void นำหน้า constructor นั้นเหมือนเมธอดทั่วไป<br />
- constructor ไม่สามารถเรียกใช้งานได้เหมือนเมธอดอื่นๆ ทำได้เพียงการผ่านค่าให้มันในขั้นตอนการสร้างออบเจ็กต์เท่านั้น</p>
<p>ตัวอย่างการสร้าง constructor ให้กับคลาส circle</p>
<table border="1" width="650">
<tbody>
<tr>
<td>class circle</p>
<p>{</p>
<p>double  radius;</p>
<p>public  circle(double r) //  constructor สำหรับรับค่าที่เป็น double กรณีผู้ใช้กำหนดค่าเริ่มต้นให้กับออบเจ็กต์</p>
<p>{</p>
<p>radius = r;</p>
<p>}</p>
<p>public  circle()</p>
<p>{</p>
<p>radius = 1;</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
<p>ในการผ่านค่าอาร์กิวเมนต์ เข้ามาให้ constructor ในขั้นตอนการสร้างออบเจ็กต์ เราสามารถทำได้ดังนี้</p>
<table border="1" width="650">
<tbody>
<tr>
<td>circle myCircle = new circle(10.0);</td>
</tr>
</tbody>
</table>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" /> Class Variable และ Instance Variable</p>
<p>โดยทั่วไปตัวแปรที่เรากำหนดในคลาสใดๆ เมื่อเรานำคลาสนั้นไปสร้างเป็นออบเจ็กต์ หากเราเปลี่ยนแปลงค่าของตัวแปรที่ออบเจ็กต์ใด จะไม่ส่งผลถึงค่าตัวแปรตัวนั้นที่ออบเจ็กต์อื่น (ที่สร้างมาจากคลาสเดียวกัน) เราเรียกตัวแปรแบบนี้ว่า instance variable</p>
<p>แต่หากเราต้องการให้ทุกออบเจ็กต์ที่สร้างมาจากคลาสเดียวกันนี้อ้างอิงข้อมูลบางอย่างเหมือนกัน หรือ อ้างอิงข้อมูลค่าเดียวกัน เมื่อเราทำการเปลี่ยนค่าของข้อมูลตัวนั้นที่ออบเจ็กต์ใด จะส่งผลให้ค่าของข้อมูลนั้นที่ออบเจ็กต์ตัวอื่นเปลี่ยนตามไปด้วย เราต้องกำหนดให้ modifier ของตัวแปรนั้นเป็นแบบ static ซึ่งเราเรียกตัวแปรแบบนี้ว่า class variable</p>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />Instance Method และ Class Method</p>
<p>Instance Method คือเมธอดทั่วๆไป ที่เราต้องเรียใช้งานผ่านอินสแตนซ์เท่านั้น</p>
<p>Class Method นั้นหมายถึงคลาสที่เีราสามารถเรียกใช้งานผ่านคลาสนั้นได้โดยตรงเลย โดยไม่ต้องสร้างอินสแตนซ์ของคลาสนั้นก่อนด้วยการกำหนด modifier ของเมธอดนั้นเป็นแบบ static เท่านั้นเอง</p>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />การผ่านค่าในรูปแบบของ Object</p>
<p>รูปแบบการผ่านค่าในรูปแบบของออบเจ็กต์ นั้นคล้ายกับการผ่านค่าของตัวแปรทั่วไป แต่มีรายละเอียดบางอย่างที่แตกต่างกันออกไป เช่น ต้องการผ่าน object myCircle ไปยังเมธอด circlrInfo โดยสมมุติว่า Circle คือคลาสที่เราได้สร้างเอาไว้แล้ว</p>
<table border="1" width="650">
<tbody>
<tr>
<td>class TestPassObject</p>
<p>{</p>
<p>public static void Main()</p>
<p>{</p>
<p>Circle myCircle = new Ccircle(10.0); //สร้างออบเจ็กต์ MyCircle รัศมี 10</p>
<p>circleInfo(myCircle); // ผ่านออบเจ็กต์ myCircle ไปยังเมธอด CircleInfo</p>
<p>}</p>
<p>public static void  circleInfo(Circle c)</p>
<p>{</p>
<p>Console.WriteLine(&#8220;Radius of circle is {0},Area is {1}&#8221;,c.Radius,c.Area);</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
<p>NOTE : ในการผ่านค่าออบเจ็กต์เป็นการผ่านแบบ Reference หากเรา้ต้องการให้เกิดการเปลี่ยนแปลงเฉพาะในส่วนนั้น โดยไม่มีผลต่อส่วนอื่่นๆ สามารถกำหนด Modifier แบบ private ให้กับข้อมูล</p>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />การใช้ is และ as</p>
<ul>
<li>is &gt;&gt; ใช้ในการตรวจสอบว่าออบเจ็กต์ที่ระบุเป็นคลาสชนิดนั้น หรือไม่ โดยค่าที่ได้กลับมาจะเป็น true หรือ false<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="317" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="317" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">object is Class</td>
<td align="left" valign="top">MyCircle is circle</td>
</tr>
</tbody>
</table>
</li>
<li>as &gt;&gt; ใช้ในการเปลี่ยนออบเจ็กต์ชนิดหนึ่งไปเป็นอีกชนิดหนึ่ง หากเปลี่ยนไม่ได้ค่าที่ได้จะเป็น null แทนที่จะเกิดข้อผิดพลาด<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="317" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="317" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">object1 as object2</td>
<td align="left" valign="top">myObject1 as myObject2</td>
</tr>
</tbody>
</table>
</li>
</ul>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />Inheritance</p>
<p>คุณสมบัติที่สำคัญของการเขียนโปรแกรมแบบ OOP ก็คือ สามารถสืบทอดจากคลาสหนึ่งไปสู่อีกคลา่สหนึ่งได้ นอกจากจะสืบทอดไปแล้ว เรายังสามารถเพิ่มเติมหรือปรับปรุงเปลี่ยนแปลงเมธอดต่างๆ ที่อยู่ในคลาสเดิมให้เป็นแบบตามที่เราต้องการได้</p>
<p>- คลาสต้นแบบที่เราจะทำการสืบทอดไปสู่คลาสอื่นเราเรียกว่า &#8220;base class&#8221;<br />
- คลาสที่ใหม่ที่ได้จากการสืบทอดไป เราเรียกว่า &#8220;derived class&#8221; ซึ่งโดยทั่วไปแล้ว derived class มักจะมีรายละเีอียดหรือความสามารถมากกว่า base class เพราะการเพิ่มเติมความสามารถใหม่นอกเหนือจากที่มีแล้วใน base class นั่นเอง<br />
-การกำหนดให้มีการสืบทอดเราจะใช้สัญลักษณ์ : เป็นตัวบอกว่าคลาสนี้สืบทอดมาจากคลาสไหน เช่น</p>
<table border="1" width="650">
<tbody>
<tr>
<td>class B:A;</p>
<p>class A</p>
<p>{</p>
<p>&#8230;.</p>
<p>}</p>
<p>class B:A</p>
<p>{</p>
<p>&#8230;.</p>
<p>}</td>
</tr>
</tbody>
</table>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" /> การใช้คีย์เวิร์ด this และ base</p>
<p>this &gt;&gt; ใช้ในการอ้างถึงคลาสปัจจุบันที่เรากำลังใช้งานอยู่ เช่น กรณีที่ต้องการเรียก constructor ของคลาสสามารถทำได้ดังนี้</p>
<table border="1" width="650">
<tbody>
<tr>
<td>public class Figure</p>
<p>{</p>
<p>private double weight, volume;</p>
<p>public  Figure()</p>
<p>{</p>
<p>this.volume  = 1.0;</p>
<p>this.weight  = 1.0;</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
<p>ในกรณีที่มีการสืบทอดระหว่างคลาส หากคลาสที่สืบทอด(Derived class) ต้องการอ้างถึง Base Class ต้องใช้คำว่า base แทน เช่น</p>
<table border="1" width="650">
<tbody>
<tr>
<td>class A</p>
<p>{</p>
<p>&#8230;.</p>
<p>public int x;</p>
<p>&#8230;.</p>
<p>}</p>
<p>class B:A</p>
<p>{</p>
<p>&#8230;.</p>
<p>base.x =10;</p>
<p>&#8230;.</p>
<p>}</td>
</tr>
</tbody>
</table>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" /> Private and Protected</p>
<ul>
<li>private &gt;&gt; เป็น modifier ใช้ในกรณีที่เราไม่ต้องการให้คลาสอื่นๆ สามารถมองเห็นหรือใช้งานองค์ประกอบนั้นๆ ของคลาสได้แม้ว่าจะสืบทอดกันมาก็ตาม</li>
<li>protected &gt;&gt; ใช้ในกรณีที่เราต้องการจะปกป้องข้อมูลต่างๆ ภายในคลาสไม่ให้สามารถเรียกใช้งานจากคลาสอื่นได้ ยกเว้นภายในคลาสของเราเอง และคลาสที่สืบทอดไปจากคลาสนี้เท่านั้น เป็นการป้องกันสมาชิกภายในคลาสไม่ให้คลาสอื่นๆ ที่ไม่อยู่ในลำดับชั้นการสืบทอดเดียวกันเข้ามาในข้อมูล</li>
</ul>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />Nested Class</p>
<table border="1" width="650">
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
<p>เราเรียกคลาส B ว่า nested class เนื่องจากถูกวางไว้ใน container class A ในการอ้างอิง nested class เราต้องระบุทั้ง container class และ nested class คล้ายๆกับเป็นเมธอดย่อยๆหนึ่ง เช่น หากเราต้องการสร้าง instance ของ nested class &#8220;N&#8221; ซึ่งอยู่ใน container &#8220;C&#8221; เราต้องระบุดังนี้</p>
<table border="1" width="650">
<tbody>
<tr>
<td>C.N n = new C.N();</td>
</tr>
</tbody>
</table>
<p>เราสามารถใช้ nested class นี้เป็นทางผ่านในการเข้าถึง member ที่กำหนด modifier แบบ private และ protected</p>
<img src="http://don-jai.com/?ak_action=api_record_view&id=127&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://don-jai.com/cunit-6-oop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[C#]Unit5  Class</title>
		<link>http://don-jai.com/cunit5-class/</link>
		<comments>http://don-jai.com/cunit5-class/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 08:08:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[Enum]]></category>
		<category><![CDATA[Method]]></category>
		<category><![CDATA[Modifier]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[คลาส]]></category>
		<category><![CDATA[ซีชาร์ป]]></category>
		<category><![CDATA[พื้นฐาน]]></category>
		<category><![CDATA[เขียนโปรแกรม]]></category>

		<guid isPermaLink="false">http://don-jai.com/?p=126</guid>
		<description><![CDATA[Unit5  Class
 Intro
การเขียนโปรแกรมแบบ OOP หรือ Object Oriented Pogramming นั้น ...]]></description>
			<content:encoded><![CDATA[<p>Unit5  Class</p>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" /> Intro</p>
<p>การเขียนโปรแกรมแบบ OOP หรือ Object Oriented Pogramming นั้น เราจะทำทุกอย่างออกมาในรูปแบบของ Class เพื่อการทำงานบางอย่าง แต่ก่อนที่เราจะมารู้จักกับลักษณะเชิงลึกของคลาส เราต้องมารู้จักสิ่งที่สำคัญยิ่งของคลาสก่อน นั่นคือ Method นั่นเอง</p>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />Method</p>
<ul>
<li>Method : เป็นองค์ประกอบอย่างหนึ่งของคลาสสำหรับกำหนดรูปแบบ วิธีการกระืืำทำ อย่างใดอย่างหนึ่ง</li>
<li>การสร้าง Methodจากลักษณะของคลาสที่ผ่านมาจะมีเมธอดเีดียวที่เรียกว่า Main() ในลักษณะดังนี้<br />
<table border="1" width="650">
<tbody>
<tr>
<td>class Classname</p>
<p>{</p>
<p>static void Main()</p>
<p>{</p>
<p>&#8230;</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
<p>แต่โดยทั่วไปแล้ว คลาสมักจะประกอบด้วยเมธอดมากกว่า 1 เมธอด สำหรับการกระทำเฉพาะอย่าง</p>
<table border="1" width="650">
<tbody>
<tr>
<td>class Classname</p>
<p>{</p>
<p>static void Main()</p>
<p>{</p>
<p>&#8230;</p>
<p>}</p>
<p>static  returnValueType MethodName (parameter)</p>
<p>{</p>
<p>&#8230;</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>returnValueType &gt;&gt; ใช้ในกรณีที่เมธอดนั้นจำเป็นต้องส่งผลลัพธ์ที่ประมวลผลภายในเมธอดนั้นกลับไปยังส่วนที่เรียกใช้งาน เราจำเป็นต้องระบุชนิดของข้อมูล เช่น int, double, string, &#8230; ที่จะส่งกลับไว้หน้าชื่อเมธอดนั้น แต่ถ้าไม่ต้องการส่งค่าให้ใส่ void<br />
<table border="1" width="650">
<tbody>
<tr>
<td>static double Cal(int r){</p>
<p>&#8230;</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>การส่งผลลัพธ์ด้วย return<br />
<table border="1" width="650">
<tbody>
<tr>
<td>static double Cal(int r){</p>
<p>double area = 3.14*r*r ;</p>
<p>return area;</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>การรับข้อมูลผ่าน Parameter &gt;&gt; ในเมธอดจะต้องมีส่วนของพารามิเตอร์ในการรับข้อมูลเข้ามา เช่น  Cal(int r) จะมี r เป็นพารามิเตอร์ชนิด Interger โดยพารามิเตอร์จะีมีกี่ตัวก็ได้ หรือไม่มีเลยก็ได้ขึ้นอยู่กับว่าจำเป็นต้องใช้อะไรบ้าง</li>
<li>การเรียกใช้ Method1. การเรียกใช้ void method หรือ เมธอดที่ไม่คืนค่า เช่น<br />
<table border="1" width="650">
<tbody>
<tr>
<td height="25">string msg = &#8220;Hello World&#8221;;</p>
<p>Say(msg); // เป็นการเรียกใช้เมธอด Say พร้อมส่งพารามิเตอร์ไปให้</td>
</tr>
</tbody>
</table>
<p>2. การเรียกใช้เมธอดที่ต้องส่งผลลัพธฺ์กลับมา เราจำเป็นต้องมีตัวแปรในการรรับค่าผลลัพธ์นั้นด้วย และ ชนิดของข้อมูลต้องเป็นชนิดเดียวกันกับที่ระบุเอาไว้ในเมธอด เช่น</p>
<table border="1" width="650">
<tbody>
<tr>
<td>double myArea = Cal(10); // เป็นการเรียกเมธอด Cal โดยการส่งค่า r = 10</td>
</tr>
</tbody>
</table>
</li>
<li>Method Parameter1. Value Parameter &gt;&gt; เป็นการส่งเฉพาะค่าของข้อมูล หากมีการเปลี่ยนแปลงค่าของพารามิเตอร์ที่เราส่งไปนั้นภายในเมธอด จะไม่มีผลต่อค่าที่ส่วนอื่นเปลี่ยนแปลงไปด้วย<br />
<table border="1" width="650">
<tbody>
<tr>
<td>using System;</p>
<p>class ValueParam</p>
<p>{</p>
<p>static void Main()</p>
<p>{</p>
<p>int a  =1;</p>
<p>Console.WriteLine(&#8220;Value before pass = {0}&#8221;,a);</p>
<p>F(a); // ส่งค่า a ไปให้ method F( )</p>
<p>Console.WriteLine(&#8220;Value after exit Method = {0}&#8221;,a);</p>
<p>Console.Read();</p>
<p>}</p>
<p>static void F (int p)</p>
<p>{</p>
<p>p++;</p>
<p>Console.WriteLine(&#8220;Value changed in method = {0}&#8221;, p);</p>
<p>}</p>
<p>}</p>
<p>/*Result is</p>
<p>Value before pass = 1</p>
<p>Value changed in method = 2</p>
<p>Value after exit Method =1</p>
<p>*/</td>
</tr>
</tbody>
</table>
<p>2. Reference Parameter &gt;&gt; การส่งพารามิเตอร์แบบนี้หากมีการเปลี่ยนแปลงค่าของพารามิเตอร์ที่เราส่งไปนั้น จะทำให้ส่วนอื่นเปลี่ยนแปลงไปด้วย วิธีการส่งทำได้โดยระบุคำว่า ref นำหน้าพารามิเตอร์ที่ส่งไป <a href="http://msdn.microsoft.com/en-us/library/14akc2c7(VS.80).aspx" target="_blank">more</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td>using System;</p>
<p>class RefParam</p>
<p>{</p>
<p>static void Main()</p>
<p>{</p>
<p>int x = 66;</p>
<p>int y =  99;</p>
<p>Console.WriteLine(&#8220;before swap : x={0},y={1}&#8221;,x,y);</p>
<p>swap(ref  x, ref y);</p>
<p>Console.WriteLine(&#8220;after swap : x={0},y={1}&#8221;, x, y);</p>
<p>Console.Read();</p>
<p>}</p>
<p>static void swap(ref int a, ref int b)</p>
<p>{</p>
<p>int t =  a;</p>
<p>a = b;</p>
<p>b = t;</p>
<p>}</p>
<p>}</p>
<p>/* Result is</p>
<p>before swap : x=66,y= 99</p>
<p>after swap : x=99,y=66*/</td>
</tr>
</tbody>
</table>
<p>3. Output Parameter &gt;&gt; คล้ายกับแบบ Referenceแต่แบบนี้เราใช้พารามิเตอร์ในการรับข้อมูลที่ส่งกลับมายังส่ี่วนที่เรียกใช้เมธอดนั้น โดยการระบุคำว่า out นำหน้าพารามิเตอร์นั้น <a href="http://msdn.microsoft.com/en-us/library/t3c3bfhx(VS.80).aspx" target="_blank">more</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td>using System;</p>
<p>class OutReturnExample</p>
<p>{</p>
<p>static void Method(out int i, out string s1, out string s2)</p>
<p>{</p>
<p>i = 44;</p>
<p>s1 = &#8220;I&#8217;ve  been returned&#8221;;</p>
<p>s2 = null;</p>
<p>}</p>
<p>static void Main()</p>
<p>{</p>
<p>int  value;</p>
<p>string  str1, str2;</p>
<p>Method(out  value, out str1, out  str2);</p>
<p>Console.WriteLine(&#8220;value ={0},str1 = {1},str2 = {2}&#8221;,value,str1,str2);</p>
<p>Console.Read();</p>
<p>// value is  now 44</p>
<p>// str1 is  now &#8220;I&#8217;ve been returned&#8221;</p>
<p>// str2 is  (still) null;</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
<p>4. Parameter Array &gt;&gt; เป็นการส่งผ่านข้อมูลไว้ในรูปแบบของอาร์เรย์ ด้วยการระบุคำว่า params ตามด้วยข้อมูลชนิดอาร์เรย์ ข้อมูลที่ส่งไปอาจอยู่ในรูปของอาร์เรย์หรือไม่ก็ได้  <a href="http://msdn.microsoft.com/en-us/library/w5zay9db(VS.80).aspx" target="_blank">more</a></p>
<table border="1" width="650">
<tbody>
<tr>
<td>using System;</p>
<p>public class MyClass</p>
<p>{</p>
<p>public static void  UseParams(params int[]  list)</p>
<p>{</p>
<p>for (int i = 0; i &lt; list.Length; i++)</p>
<p>{</p>
<p>Console.WriteLine(list[i]);</p>
<p>}</p>
<p>Console.WriteLine();</p>
<p>}</p>
<p>static void Main()</p>
<p>{</p>
<p>UseParams(1, 2, 3);</p>
<p>// An array  of objects can also be passed, as long as</p>
<p>// the array  type matches the method being called.</p>
<p>int[]  myarray = new int[3]  { 10, 11, 12 };</p>
<p>UseParams(myarray);</p>
<p>Console.Read();</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
</ul>
<ul>
<li>Recursion Method &gt;&gt; เป็นเมธอดที่มีการเรียกใช้ตัวมันเอง เพื่อทำงานบางอย่างที่ซ้ำๆกัน เหมือนกับการวบลูปไปเรื่อยๆ จนกว่าจะถึงค่าสุดท้าย</li>
<li>การเรียกใช้ Method ใน class  อื่น &gt;&gt; ระวังเรื่องสิทธิ์ในการเข้าใช้งานด้วย<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="352" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="282" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">ClassName.MethodName(parameter);</td>
<td align="left" valign="top">MyFirstClass.Cal(100);</td>
</tr>
</tbody>
</table>
</li>
<li>Overloading Method &gt;&gt; หมายถึงการตั้งชื่อเมธอดเหมือนกัน แต่การรับพารามิเตอร์และวิธีประมวลผลอาจจะต่างกัน ทั้งนี้เพื่อให้การใช้งานเมธอดนั้นมีความยืดหยุ่นมากขึ้น เช่น<br />
<table border="1" width="650">
<tbody>
<tr>
<td height="23">void F( );</p>
<p>void F(int x);</p>
<p>void F(ref int x);</td>
</tr>
</tbody>
</table>
</li>
<li>Signature &gt;&gt; หมายถึง รูปแบบในการรับพารามิเตอร์ของเมธอดนั้นสามารถกำหนดรูปแบบการประมวลผลได้หลากหลาย จากตัวอย่างของ Overloading Method ทำให้เราได้ Signature ของแต่ละ เมธอดดังนี้<br />
<table border="1" width="650">
<tbody>
<tr>
<td height="23">F( );</p>
<p>F(int );</p>
<p>F(ref int );</td>
</tr>
</tbody>
</table>
</li>
</ul>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />Modifier</p>
<ul>
<li>Modifier เป็นระดับการควบคุมการเข้าใช้งาน Class Method Property หรือตัวแปรต่างๆ1.Class Modifier<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="88">
<p align="center">Modifier</p>
</td>
<td width="546">
<p align="center">คำอธิบาย</p>
</td>
</tr>
<tr>
<td align="left" valign="top">public</td>
<td align="left" valign="top">ไม่จำกัดสิทธิ์ใดๆ ในการเข้าใช้งาน</td>
</tr>
<tr>
<td align="left" valign="top">private</td>
<td align="left" valign="top">สามารถเรียกใช้งานได้เฉพาะในคลาสเดียวกันเท่านั้น ไม่สามารถเรียกใช้งาน จากภายนอกคลาสได้</td>
</tr>
</tbody>
</table>
<p>2.Method Modifier</p>
<table border="1" width="650">
<tbody>
<tr>
<td width="88">
<p align="center">Modifier</p>
</td>
<td width="546">
<p align="center">คำอธิบาย</p>
</td>
</tr>
<tr>
<td align="left" valign="top">public</td>
<td align="left" valign="top">เป็นการอนุญาตให้สามารถเรียกใช้เมธอดจากที่ใดก็ได้โดยไม่จำกัดสิทธิ์การเข้าใช้งาน</td>
</tr>
<tr>
<td align="left" valign="top">private</td>
<td align="left" valign="top">อนุญาตให้เรียกใช้ได้เฉพาะภายในคลาสเดียวกันเท่านั้น</td>
</tr>
<tr>
<td align="left" valign="top">static</td>
<td align="left" valign="top">เมธอดนี้จะถูกโหลดขึ้นมาพร้อมคลาส และใช้งานได้ทันที เมธอดที่เป็นแบบสแตติกจะเรียกใช้ได้เฉพาะเมธอดที่เป็นสแตติกด้วยกันเองเท่านั้น</td>
</tr>
</tbody>
</table>
<p>3.Variable Modifier</p>
<table border="1" width="650">
<tbody>
<tr>
<td width="85">
<p align="center">Modifier</p>
</td>
<td width="549">
<p align="center">คำอธิบาย</p>
</td>
</tr>
<tr>
<td align="left" valign="top">public</td>
<td align="left" valign="top">ไม่จำกัดสิทธิ์ใดๆ ในการเข้าใช้งาน</td>
</tr>
<tr>
<td align="left" valign="top">private</td>
<td align="left" valign="top">เรียกประมวลผลได้เฉพาะภายในคลาสนี้เท่านั้น</td>
</tr>
<tr>
<td align="left" valign="top">static</td>
<td align="left" valign="top">ใช้สำหรับกำหนด ตัวแปรของคลาส ซึ่งเป็นตัวแปรที่เก็บข้อมูลบางอย่างที่คลาสนี้จำเป็นต้องใช้</td>
</tr>
</tbody>
</table>
</li>
</ul>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />Enum</p>
<ul>
<li>Enum (Enumeration) &gt;&gt; หมายถึงเซตของข้อมูลชุดหนึ่งที่มีจำนวนสมาชิกที่กำหนดไว้แน่นอนและทราบค่าทุกตัว ซึ่งมักจะเป็นข้อมูลที่มีลักษณะคงที่<br />
<table border="1" width="650">
<tbody>
<tr>
<td width="316" align="left" valign="top">
<p align="center">รูปแบบของคำสั่ง</p>
</td>
<td width="318" align="left" valign="top">
<p align="center">ตัวอย่าง</p>
</td>
</tr>
<tr>
<td align="left" valign="top">enum NameEnum{</p>
<p>สมาชิก1,</p>
<p>สมาชิก2,</p>
<p>สมาชิก3,</p>
<p>สมาชิก4,</p>
<p>&#8230;&#8230;&#8230;..</p>
<p>สมาชิก n</p>
<p>}</td>
<td align="left" valign="top">enum DayOfWeek{</p>
<p>Sunday,</p>
<p>Monday,</p>
<p>Tuesday,</p>
<p>Wednesday,</p>
<p>Thursday,</p>
<p>Friday</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
</ul>
<p>Property</p>
<ul>
<li>Property &gt;&gt; หมายถึงคุณลักษณะของคลาส หรือ object</li>
<li>การกำหนด Property<br />
<table border="1" width="650">
<tbody>
<tr>
<td>using System;</p>
<p>class ClassName</p>
<p>{</p>
<p>private ฟิลด์ที่จะเก็บข้อมูล</p>
<p>public ชนิดของข้อมูล ชื่อ-Property</p>
<p>{</p>
<p>get{</p>
<p>&#8230;&#8230;&#8230;</p>
<p>}</p>
<p>set{</p>
<p>&#8230;&#8230;&#8230;</p>
<p>}</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>get &gt;&gt; get accessor เป็นส่วนที่ใช้ในการอ่านข้อมูลที่เก็บอยู่ในฟิลด์ แล้วส่งไปให้ส่วนที่อ่านค่าproperty นั้น</li>
<li>set &gt;&gt; set accessor  เป็นส่วนที่ใช้ในการบันทึกหรือเขียนข้อมูลลงในตัวแปรฟิลด์ เมื่อมีการกำหนดค่าให้กับ property นั้น</li>
<li>NOTE1. หาก Property นั้นมีทั้ง get และ set accessor เราจะเรียกว่าเป็น read-write property<br />
2. หาก Property นั้นมีทั้ง get accessor เราจะเรียกว่าเป็น read-only property<br />
3. หาก Property นั้นมีทั้ง  set accessor เราจะเรียกว่าเป็น write-only property</li>
</ul>
<img src="http://don-jai.com/?ak_action=api_record_view&id=126&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://don-jai.com/cunit5-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[C#]Unit 1 พื้นฐาน C# ตอน1</title>
		<link>http://don-jai.com/cunit-1-%e0%b8%9e%e0%b8%b7%e0%b9%89%e0%b8%99%e0%b8%90%e0%b8%b2%e0%b8%99-c-%e0%b8%95%e0%b8%ad%e0%b8%991/</link>
		<comments>http://don-jai.com/cunit-1-%e0%b8%9e%e0%b8%b7%e0%b9%89%e0%b8%99%e0%b8%90%e0%b8%b2%e0%b8%99-c-%e0%b8%95%e0%b8%ad%e0%b8%991/#comments</comments>
		<pubDate>Wed, 11 Jun 2008 02:26:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ซีชาร์ป]]></category>
		<category><![CDATA[พื้นฐาน]]></category>
		<category><![CDATA[เขียนโปรแกรม]]></category>

		<guid isPermaLink="false">http://don-jai.com/?p=121</guid>
		<description><![CDATA[Unit 1 : พื้นฐาน C#
องค์ประกอบพื้นฐานในการเขียนโปรแกรม

Comment  &#62;&#62; เป็นการแทรกคำอธิบาย หรือ  ...]]></description>
			<content:encoded><![CDATA[<p>Unit 1 : พื้นฐาน C#</p>
<p><img src="http://don-jai.com/wp-content/uploads/2008/05/bot2.gif" alt="bot2.gif" />องค์ประกอบพื้นฐานในการเขียนโปรแกรม</p>
<ul>
<li>Comment  &gt;&gt; เป็นการแทรกคำอธิบาย หรือ  ละเว้นการทำงานของบริเวณที่ถูก Comment โดยมี 2 วิธีคือ11. ใช้ //  เป็นการ  Comment บรรทัดเดียว โดยโปรแกรมจะละเว้นการทำงาน ตั้งแต่เจอ // จนสิ้นสุดบรรทัดเช่น<br />
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">// This is the first loop</td>
</tr>
</tbody>
</table>
<p>2. ใช้ /*….*/ เป็นการ Comment  หลายบรรทัด  เหมือนกับการใช้// หลายๆครั้ง เช่น</p>
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">/*int x =2;int y =1;</p>
<p>x += y;</p>
<p>*/</td>
</tr>
</tbody>
</table>
</li>
</ul>
<ul>
<li>Block &gt;&gt; C# จะใช้ block {&#8230;} ในการกำหนดจุดเริ่มและจุดสิ้นสุดของการทำงานแต่ละส่วน<br />
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">class xxx {if(..){</p>
<p>}</p>
<p>}</td>
</tr>
</tbody>
</table>
</li>
<li>เครื่องหมายสิ้นสุดคำสั่ง (;) &gt;&gt; C# จะใ้ช้ ; เป็นตัวแสดงจุดสิ้นสุดของแต่ละคำสั่ง หากไม่ใส่จะเกินข้อผิดพลาด<br />
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">x = 100; // ไม่เกิดข้อผิดพลาดy = &#8220;123&#8243; //เกิดข้อผิดพลาดเนื่องจากไม่ได้ใส่ ; ท้ายคำสั่ง</td>
</tr>
</tbody>
</table>
</li>
<li>Keywords &gt;&gt; เป็นคำสงวนไว้ใช้เป็นคำสั่งใน C# เราไม่สามารถนำคำเหล่านี้ไปกำหนดเป็นชื่ออย่างอื่นได้<br />
<table border="1" width="650">
<tbody>
<tr>
<td align="left" valign="top">
<table border="0" width="640">
<tbody>
<tr>
<td valign="top">abstract</td>
<td align="left" valign="top">as</td>
<td align="left" valign="top">base</td>
<td align="left" valign="top">bool</td>
<td align="left" valign="top">break</td>
</tr>
<tr>
<td align="left" valign="top">byte</td>
<td align="left" valign="top">case</td>
<td align="left" valign="top">catch</td>
<td align="left" valign="top">char</td>
<td align="left" valign="top">checked</td>
</tr>
<tr>
<td align="left" valign="top">class</td>
<td align="left" valign="top">const</td>
<td align="left" valign="top">continue</td>
<td align="left" valign="top">decimal</td>
<td align="left" valign="top">default</td>
</tr>
<tr>
<td align="left" valign="top">delegate</td>
<td align="left" valign="top">do</td>
<td align="left" valign="top">double</td>
<td align="left" valign="top">else</td>
<td align="left" valign="top">enum</td>
</tr>
<tr>
<td align="left" valign="top">event</td>
<td align="left" valign="top">explicit</td>
<td align="left" valign="top">extern</td>
<td align="left" valign="top">false</td>
<td align="left" valign="top">finally</td>
</tr>
<tr>
<td align="left" valign="top">fixed</td>
<td align="left" valign="top">float</td>
<td align="left" valign="top">for</td>
<td align="left" valign="top">foreach</td>
<td align="left" valign="top">goto</td>
</tr>
<tr>
<td align="left" valign="top">if</td>
<td align="left" valign="top">implicit</td>
<td align="left" valign="top">in</td>
<td align="left" valign="top">int</td>
<td align="left" valign="top">interface</td>
</tr>
<tr>
<td align="left" valign="top">internal</td>
<td align="left" valign="top">is</td>
<td align="left" valign="top">lock</td>
<td align="left" valign="top">long</td>
<td align="left" valign="top">namespace</td>
</tr>
<tr>
<td align="left" valign="top">new</td>
<td align="left" valign="top">null</td>
<td align="left" valign="top">object</td>
<td align="left" valign="top">operator</td>
<td align="left" valign="top">out</td>
</tr>
<tr>
<td align="left" valign="top">override</td>
<td align="left" valign="top">params</td>
<td align="left" valign="top">private</td>
<td align="left" valign="top">protected</td>
<td align="left" valign="top">public</td>
</tr>
<tr>
<td align="left" valign="top">readonly</td>
<td align="left" valign="top">ref</td>
<td align="left" valign="top">return</td>
<td align="left" valign="top">sbyte</td>
<td align="left" valign="top">sealed</td>
</tr>
<tr>
<td align="left" valign="top">short</td>
<td align="left" valign="top">sizeof</td>
<td align="left" valign="top">stackalloc</td>
<td align="left" valign="top">static</td>
<td align="left" valign="top">string</td>
</tr>
<tr>
<td align="left" valign="top">struct</td>
<td align="left" valign="top">switch</td>
<td align="left" valign="top">this</td>
<td align="left" valign="top">throw</td>
<td align="left" valign="top">true</td>
</tr>
<tr>
<td align="left" valign="top">try</td>
<td align="left" valign="top">typeof</td>
<td align="left" valign="top">unit</td>
<td align="left" valign="top">ulong</td>
<td align="left" valign="top">unchecked</td>
</tr>
<tr>
<td align="left" valign="top">unsafe</td>
<td align="left" valign="top">ushort</td>
<td align="left" valign="top">using</td>
<td align="left" valign="top">virtual</td>
<td align="left" valign="top">void</td>
</tr>
<tr>
<td align="left" valign="top">volatile</td>
<td align="left" valign="top">while</td>
<td align="left" valign="top"></td>
<td align="left" valign="top"></td>
<td align="left" valign="top"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</li>
</ul>
<img src="http://don-jai.com/?ak_action=api_record_view&id=121&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://don-jai.com/cunit-1-%e0%b8%9e%e0%b8%b7%e0%b9%89%e0%b8%99%e0%b8%90%e0%b8%b2%e0%b8%99-c-%e0%b8%95%e0%b8%ad%e0%b8%991/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
