㺧ҹ·Õè 2
µÑÇ´Óà¹Ô¹¡ÒÃáÅйԾ¨¹ì¤³ÔµÈÒʵÃì
2.1
µÑÇ´Óà¹Ô¹¡Ò÷ҧ¤³ÔµÈÒʵÃì(Arithmetic
Operation)
µÑÇ´Óà¹Ô¹¡Òà |
¤ÇÒÁËÁÒ |
µÑÇÍÂèÒ§ |
¼ÅÅѾ¸ì (X=11,Y=5) |
+ |
ºÇ¡(Additon)
|
X + Y |
|
-
|
ź(Subtraction) |
X – Y |
|
*
|
¤Ù³(Multiplication) |
X * Y |
|
/
|
ËÒÃ(Division) |
X / Y |
|
\
|
¼ÅËÒ÷Õèà»ç¹¨Ó¹Ç¹àµçÁ |
X \ Y |
|
mod
|
ËÒÃàÍÒ¼ÅÅѾ¸ì੾ÒÐàÈÉ(Modulus) |
X mod Y |
|
&
|
àª×èÍÁµÑÇÍÑ¡¢ÃÐ |
X & Y |
|
2.2 µÑÇ´Óà¹Ô¹¡ÒÃà»ÃÕºà·Õº (Comparative Operation) ¼ÅÅѾ¸ì¨Ò¡¡ÒÃà»ÃÕºà·Õºà»ç¹¨ÃÔ§(True) ËÃ×Í à·ç¨ (False) «Öè§ÁÕà¤Ã×èͧËÁÒ´ѧ¹Õé
µÑÇ´Óà¹Ô¹¡Òà |
¤ÇÒÁËÁÒ |
µÑÇÍÂèÒ§ |
¼ÅÅѾ¸ì (X=11,Y=5) |
> |
ÁÒ¡¡ÇèÒ(Greater Than)
|
X > Y |
|
<
|
¹éÍ¡ÇèÒ(Less Than) |
X < Y |
|
>=
|
ÁÒ¡¡ÇèÒËÃ×Íà·èҡѺ(Greater Than or Equal) |
X >= Y |
|
<=
|
¹éÍ¡ÇèÒËÃ×Íà·èҡѺ(Less Than or Equal) |
X <= Y |
|
=
|
à·èҡѺ(Equal) |
X = Y |
|
<>
|
äÁèà·èҡѺ(Not Equal) |
X <> Y |
|
2.3 µÑÇ´Óà¹Ô¹¡Ò÷ҧµÃáÐ(Logical Operation) à»ç¹à¤Ã×èͧËÁÒÂãªéà»ÃÕºà·Õº·Ò§µÃáР¼ÅÅѾ¸ì·Õèä´é¨Ðà»ç¹¨ÃÔ§ (True) ËÃ×Íà·ç¨(False) ´Ñ§¹Õé
µÑÇ´Óà¹Ô¹¡Òà |
¤ÇÒÁËÁÒ |
µÑÇÍÂèÒ§ (X=11,Y=5) |
¼ÅÅѾ¸ì |
And |
áÅÐ(And)
|
(X > 10) And (Y<15) |
|
OR
|
ËÃ×Í(Or) |
(X > 10) Or ( X<15) |
|
NOT
|
äÁè(Not) |
NOT (X > 10) And (Y<15) |
|
2.4 ÅӴѺ¡ÒûÃÐÁÇżŢͧ¹Ô¾¨¹ì
à¤Ã×èͧËÁÒ |
ÅӴѺ¡ÒûÃÐÁÇżŠ|
( ) |
1
|
^
|
2 |
* /
|
3 |
mod
|
4 |
+ -
|
5 |
µÑÇÍÂèÒ§ 1 10 + 2 * 8 / 4 * 5 –3 |
µÑÇÍÂèÒ§ 1 (10 + 2) * 8 / (4 * 5 –3) |
|
|
2.5à»ÃÕºà·ÕºµÑÇ´Óà¹Ô¹¡Ò÷ҧ¤³ÔµÈÒʵÃìáÅеÃáÐÃÐËÇèÒ§
VB.Net ¡Ñº C#
VB.Net |
C# |
¤Ó͸ԺÒ |
+
- * / Mod |
+
- * / % |
ºÇ¡ , ź , ¤Ù³ , ËÒà , ËÒÃẺ Modulas(ËÒÃàÍÒàÈÉ) |
äÁèÁÕ |
+= -= *= /= %= |
ºÇ¡áÅСÓ˹´¤èÒ, źáÅСÓ˹´¤èÒ, ¤Ù³áÅСÓ˹´¤èÒ, ËÒÃáÅСÓ˹´¤èÒ, ËÒÃàÍÒàÈÉáÅСÓ˹´¤èÒ |
äÁèÁÕ |
++
-- |
à¾ÔèÁ¤èÒ¢Öé¹ 1 , Å´¤èÒŧ 1 |
< > <= >= |
<
>
<= >= |
¹éÍ¡ÇèÒ, ÁÒ¡¡ÇèÒ, ¹éÍ¡ÇèÒËÃ×Íà·èҡѺ, ÁÒ¡¡ÇèÒËÃ×Íà·èҡѺ |
= <> |
== != |
à·èҡѺ, äÁèà·èҡѺ |
^ \ |
äÁèÁÕ |
¡¡ÓÅѧ, ËÒÃẺ¨Ó¹Ç¹àµçÁ (»Ñ´àÈÉ·Ôé§) |
& ËÃ×Í + |
+ |
àª×èÍÁ¢éͤÇÒÁ |
On Error |
Try Catch |
µÃǨÊͺ¢éͼԴ¾ÅÒ´¢Í§â»Ãá¡ÃÁ |
And Or Not |
&& || ~ |
áÅÐ, ËÃ×Í , ¹Ôàʸ ( ãªé´Óà¹Ô¹¡Ò÷ҧµÃáР) |
a = a + 1 |
a++ ËÃ×Í ++a |
à¾ÔèÁ¤èҢͧµÑÇá»Ã a ¢Öé¹ 1 |
a = a - 1 |
a-- ËÃ×Í --a |
Å´¤èҢͧµÑÇá»Ã a ŧ 1 |
a = a + 2 |
a+ = 2 |
¹Ó¤èҢͧµÑÇá»Ã a ÁҺǡ 2 áÅéÇà¡çº¼ÅÅѾ¸ìäÇéã¹µÑÇá»Ã a |
s = s + ”Hello” |
s += ”Hello” |
¹Ó¤èҢͧµÑÇá»Ã s ÁÒàª×èÍÁµè͡Ѻ¤ÓÇèÒ Hello áÅéÇà¡çº¼ÅÅѾ¸ìäÇéã¹µÑÇá»Ã s |
2.7 à»ÃÕºà·Õº¤ÓÊÑ觵ÃǨÊͺà§×͹ä¢ÃÐËÇèÒ§
VB.Net ¡Ñº C#
VB.Net |
C# |
If x =10 then y=30 |
If(x == 10) y=30; |
If(x=10) or (y>=15) then z=30 |
If((x == 10) || (y>=15)) z=30; |
If(x<>10) and (y=15) then z=30 |
If((x != 10) && (y==15)) z=30; |
If x>10 then ' ¤ÓÊÑè§ 1 Else ' ¤ÓÊÑè§ 2 End if |
If (x>10) { //¤ÓÊÑè§
1 } Else { //¤ÓÊÑè§ 2 } End if |
Select Case X
Case 10, 20
' ¤ÓÊÑè§ 1
Case 30
' ¤ÓÊÑè§ 2
Case >=31
' ¤ÓÊÑè§ 3
Case Else
' ¤ÓÊÑè§ 4 End Select |
switch(X) {
case “
case “
//¤ÓÊÑè§ 1
; break;
case “
//¤ÓÊÑè§ 2
; break; default :
if(x>=31)
{
// ¤ÓÊÑè§ 3;
} else
{
// ¤ÓÊÑè§ 4;
}
break; } |
2.8 à»ÃÕºà·Õº¤ÓÊÑè§Ç¹ÅÙ»ÃÐËÇèÒ§
VB.Net ¡Ñº C#
VB.Net |
C# |
Dim I As Short For i=1
To 10 ' ¤ÓÊÑè§ Next i |
for(short i=1; i<=10; i++) { // ¤ÓÊÑè§ 1; } |
Dim I As Short For i=1 To 10 Step 2 ' ¤ÓÊÑè§ Next i |
for(short i=1;
i<=10; i+=2) { // ¤ÓÊÑè§ ; } |
Dim I As Short For i=1 To 10 Step -2 ' ¤ÓÊÑè§ Next i |
for(short i=1;
i<=10; i-=2) { // ¤ÓÊÑè§ ; } |
For Each field in Record
' ¤ÓÊÑè§ Next |
foreach (field in Record) { // ¤ÓÊÑè§ ; } |
Do While x=10 ' ¤ÓÊÑè§ |
while (x ==10) { // ¤ÓÊÑè§ ; } |
Do Until x<>10
' ¤ÓÊÑè§ |
while (x !=10) { // ¤ÓÊÑè§ ; } |
Do
' ¤ÓÊÑè§ Loop While x=10 |
do { // ¤ÓÊÑè§ ; } while(x ==10); |
Do
' ¤ÓÊÑè§ Loop Until x<>10 |
do { // ¤ÓÊÑè§ ; } while(x!=10); |
2.9 à»ÃÕºà·Õº¿Ñ§¡ìªÑ¹áÅЫѺÃÙ·Õ¹ÃÐËÇèÒ§
VB.Net ¡Ñº C#
VB.Net |
C# |
Function Test(ByVal a As Short) As String ' ¤ÓÊÑè§
Return
"¤èÒ·ÕèÊ觤׹¨Ò¡¿Ñ§¡ìªÑ¹"
Exit Function End Function |
String Test(short a) { // ¤ÓÊÑè§ 1; Return "¤èÒ·ÕèÊ觤׹¨Ò¡¿Ñ§¡ìªÑ¹" } |
Sub Test2(ByRef a As String) ' ¤ÓÊÑè§ End Sub |
void Test2(ref string a) { // ¤ÓÊÑè§
1; } |
µÑÇÍÂèÒ§¡ÒÃàÃÕ¡ãªé¿Ñ§¡ìªÑ¹áÅЫѺÃÙ·Õ¹ |
|
VB.Net |
C# |
' ¡ÒÃàÃÕ¡ãªé¿Ñ§¡ìªÑ¹ Dim strRec As String strRec = Sum(11) |
// ¡ÒÃàÃÕ¡ãªé¿Ñ§¡ìªÑ¹ string strRec ; strRec = Sum(11); |
' ¡ÒÃàÃÕ¡ãªé«ÑºÃÙ·Õ¹ Call Sum( "Hello" ) |
// ¡ÒÃàÃÕ¡ãªé«ÑºÃÙ·Õ¹ // (¿Ñ§¡ìªÑ¹·ÕèäÁè¤×¹¤èÒã´æ
¡ÅѺÁÒ) Sum(ref "Hello" ); |
2.10 à»ÃÕºà·Õºª¹Ô´¢éÍÁÙÅ C# ¡Ñº VB.NET
VB.Net |
C# |
¤Ó͸ԺÒ |
|
Date |
System.DateTime |
¢¹Ò´ 64 ºÔµà¡çºÇѹ·Õè 1 Á¡ÃÒ¤Á »Õ 1 ¶Ö§ 31 ¸Ñ¹ÇÒ¤Á |
|
SByte |
sbyte |
¢¹Ò´ 8 ºÔµà¡çº¤èÒàÅ¢¨Ó¹Ç¹àµçÁµÑé§áµè -128 ¶Ö§ 127 |
|
Byte |
byte |
¢¹Ò´ 8 ºÔµà¡çº¤èÒàÅ¢¨Ó¹Ç¹àµçÁµÑé§áµè 0 ¶Ö§ 255 |
|
Boolean |
bool |
¢¹Ò´ 16 ºÔµà¡çº¤èÒµÃáРtrue(¨ÃÔ§) ËÃ×Í false(à·ç¨) |
|
Short |
short |
¢¹Ò´ 16 ºÔµà¡çº¤èÒàÅ¢¨Ó¹Ç¹àµçÁµÑé§áµè -32,768 ¶Ö§ 32,767 |
|
Integer |
int |
¢¹Ò´ 32 ºÔµà¡çº¤èÒàÅ¢¨Ó¹Ç¹àµçÁµÑé§áµè -2,147,483,648 ¶Ö§ 2,147,483,647 |
|
Long |
long |
¢¹Ò´ 64 ºÔµà¡çº¤èÒàÅ¢¨Ó¹Ç¹àµçÁµÑé§áµè -9,223,372,036,854,775,808 ¶Ö§ -9,223,372,036,854,775,807 |
|
UInt16 |
ushort |
¢¹Ò´ 16 ºÔµà¡çº¤èÒàÅ¢¨Ó¹Ç¹àµçÁµÑé§áµè 0 ¶Ö§ 65,535 |
|
UInt32 |
uint |
¢¹Ò´ 32 ºÔµà¡çº¤èÒàÅ¢¨Ó¹Ç¹àµçÁµÑé§áµè 0 ¶Ö§ 4,294,967,295 |
|
UInt64 |
ulong |
¢¹Ò´ 64 ºÔµà¡çº¤èÒàÅ¢¨Ó¹Ç¹àµçÁµÑé§áµè 0 ¶Ö§ 184,467,440,737,095,551,615 |
|
Single |
float |
¢¹Ò´ 32 ºÔµà¡çº¤èÒàÅ¢¨Ó¹Ç¹·È¹ÔÂÁµÑé§áµè -3.4028235E+38 ¶Ö§ -1.401298E-45 ÊÓËÃѺ¤èÒź áÅеÑé§áµè -1.401298E-45 ¶Ö§ 3.4028235E+38 ÊÓËÃѺ¤èҺǡ |
|
Double |
double |
¢¹Ò´ 64 ºÔµà¡çº¤èÒàÅ¢¨Ó¹Ç¹·È¹ÔÂÁµÑé§áµè -1.79769313486231570E+308 ¶Ö§ -4.94065645841246544E-324 ÊÓËÃѺ¤èÒź áÅеÑé§áµè ¶Ö§ -4.94065645841246544E-324 ¶Ö§1.79769313486231570E+308 ÊÓËÃѺ¤èҺǡ |
|
Char |
char |
¢¹Ò´ 16 ºÔµà¡çºµÑÇÍÑ¡É÷ÕèàªéÒËÑÊẺ Unicode 1 µÑÇÍÑ¡Éà |
|
String |
string |
à¡çº¢éͤÇÒÁã´æ â´Â¢Ò´·Õèãªé¨Ð¢Öé¹ÍÂÙè¡Ñº¨Ó¹Ç¹µÑÇÍÑ¡ÉÃ㹪éͤÇÒÁ¹Ñé¹ |
|
Object |
object |
¢¹Ò´ 32 ºÔµ·Õèãªéà¡çºáÍ´à´ÃʢͧÍͺà¨ç¤ª¹Ô´ã´¡çä´é ª¹Ô´¢éÍÁÙŹÕé¨Ö§ÊÒÁÒöãªéà¡çº¤èÒª¹Ô´¢éÍÁÙÅÍ×è¹æ ä´é·Ñé§ËÁ´ |
|
µÑÇÍÂèÒ§¡ÒûÃСÒȵÑÇá»Ã |
|||
VB.Net |
C# |
||
Dim strName As String |
string strName ; |
||
Dim strName As String="Tom" |
string strName = "Tom" ; |
||
Dim strA, strB As String |
string strA
, strB ; |
||
Dim cat As New Animal |
Animal cat= new Animal ; |
||
Dim Fname(3) As String |
string[] Fname=new string[3]; |
||
Dim Name(3,3) As String |
String[,] Name = new string[3,3] ; |
||