Type of Keyword
กิจจา กิจประเสริฐ 650710526
ใน C# นั้น มี Keywords อยู่ด้วยกันทั้งหมด 78ตัว ซึ่ง สามารถแบ่งกลุ่มออกได้เป็น 10กลุ่มหลัก ๆ ที่มีการเรียกใช้งานที่แตกต่างกัน ได้แก่
1. Value Type Keywords :
Value Type Keyword คือ Keyword ที่ใช้ในการกำหนดชนิดของตัวแปร โดยมีด้วยกันทั้งสิ้น 15ตัว ได้แก่
enum
float
int
long
sbyte
short
struct
unit
ulong
short
เปรียบเทียบกับ....
Python : Value Keyword ของ Python หมายถึง Keyword ที่ใช้ในการกำหนดค่าของ boolean ซึ่งค่าพวกนี้จัดเป็น Singleton ที่สามารถเรียกใช้ซ้ำไปซ้ำมาได้เรื่อย ๆ โดยมีอยู่ด้วยกัน 3 ตัว คือ true , false, none
3 ตัว คือ true , false, noneJava : ใน Java เรียก Primitive Data Type มีอยู่ด้วยกัน 8 ตัว byte , short , int , long , float , double , char , boolean
8 ตัว byte , short , int , long , float , double , char , boolean C : ใน C เรียก Primary Data Type มีอยู่ด้วยกัน 4 ตัว ได้แก่ Integer, Floating-point (float), double, string. ทำหน้าที่เหมือนกันกับ data type ใน C# ยกเว้น string
Example :
using System;
class VTK {
static public void Main () {
byte a = 47;
bool b = true;
double c = 0.42e2;
float d = 134.45E-2f;
decimal e = 1.5E6m;;
char g = 'G';
int h = 10;
long i = 15000000000L;
Console.WriteLine("The byte of a is: {0}",a);
Console.WriteLine("The bool of b is: {0}",b);
Console.WriteLine("The double of c is: {0}",c);
Console.WriteLine("The float of d is: {0}",d);
Console.WriteLine("The decimal of e is: {0}",e);
Console.WriteLine("The char of g is: {0}",g);
Console.WriteLine("The int of h is: {0}",h);
Console.WriteLine("The long of i is: {0}",i);
}
}Output :
2. Reference Type Keywords :
Reference Type Keyword คือ Keyword ที่ใช้ในการเก็บการอ้างอิงถึงข้อมูลหรือตัว Object ต่างๆ โดย Keywords ในกลุ่มนี้นั้น มีทั้งหมด 6ตัว ได้แก่
object
string
void
เปรียบเทียบกับ....
Python : ใน Python เรียก Declaration Keyword ใช้ในการประกาศตัวแปร ฟังก์ชัน คลาส และ องค์ประกอบอื่น ๆ Keyword ได้แก่ def, class, lambda, global, nonlocal, etc.
Java : ใน Java จะใช้ในการชี้ไปยังตัว Object/ค่าต่าง ๆ คลาส, interface, อาเรย์, enum , annotation จะเก็บ object และค่าต่าง ๆ เอาไว้ในตัวอ้างอิง ซึ่งตัวแปรสามารถเก็บค่าที่เป็น nullได้ด้วย ในการเข้าถึง object ของสมาชิก สามารถทำได้ด้วย dot (.)
C: ใน C เรียกว่า Pointer ใช้ * แทนตัว Pointer(Pointer Variable) เป็นตัวแปรพิเศษในการจัดเก็บตำแหน่งของค่าของตัวแปรต่าง ๆ
Example :
Output :
3. Modifier Keywords :
Modifier Keywords คือ Keyword ที่ใช้ในการเปลี่ยนแปลง / จำกัด การเข้าถึงตัวของข้อมูลต่าง ๆ Keywords ในกลุ่มนี้มีด้วยกันทั้งสิ้น 17ตัว ได้แก่
const
event
extern
new
override
partial
readonly
sealed
static
unsafe
virtual
volatile
เปรียบเทียบกับ....
Python : ใน Python ตัว Modifier Keyword จะใช้กำหนดการเข้าถึงตัวคลาส - public , private , protected
Java : Java แบ่ง modifier ออกเป็น 2 ประเภท ได้แก่ Access Modifier และ Non-Access Modifier โดย Access Modifier จะมี public , private , default , protected ส่วน Non-Access Modifier จะมี final , static, abstract transient, synchronized, volatile
C: ใน C modifier keyword มีเพียง 4 ตัวเท่านั้น ได้แก่ short, long, signed, unsigned เป็น Keyword ที่ใช้ในการปรับเปลี่ยนคุณสมบัติเริ่มต้นของชนิดข้อมูลต่าง ๆ
Example :
Output :
4. Statements Keywords :
Statements Keywords คือ Keyword ที่ใช้ในการสั่งการให้โปรแกรมทำคำสั่งใด ๆ มีอยู่ด้วยกันทั้งหมด 18ตัว ได้แก่
foreach
in
while
break
continue
goto
return
throw
try
catch
finally
checked
unchecked
เปรียบเทียบกับ....
Python : ใน python มี Statement Keyword อยู่ด้วย กัน 6 ตัว ได้แก่ if, while, for, try, with, match และ ยังมี Keyword ย่อยอีก 4 ตัว ได้แก่ except, except*, else, finally โดย 4 ตัวย่อยนี้มักจะใช้อยู่ภายใต้ try
Java : มี Statement 2 ประเภท ได้แก่ decision-making statements (if-then, if-then-else, switch), และ looping statements(for, while, do-while)
C : มีการแบ่ง statements ออกเป็นกลุ่มย่อยหลาย ๆ กลุ่ม ขึ้นอยู่กับ การใช้งาน ดังนี้ if Statement, if-else Statement, Nested if Statement, if-else-if Ladder switch Statement, Conditional Operator, Jump Statements(break, continue, goto, return)
Example :
Output :
5. Method Parameters Keywords :
Method Parameters Keywords คือ Keyword ที่ใช้ในการเปลี่ยนแปลงการกระทำของตัว parameters ต่างๆ ที่ถูกใส่เข้าไปใน methods นั้นๆ Keyword กลุ่มนี้มีอยู่ด้วยกัน 4 ตัว ได้แก่
params
in
ref
out
เปรียบเทียบกับ....
Python : Keyword สำคัญสำหรับการประกาศ method parameter ของ python คือ def ตามด้วย function_name(parameter)
Java : ใน Java มีความคล้ายคลึงกันกับ C# แต่ใน Java จะส่ง parameters เป็นแบบ value เสมอ
C: ใน C method parameter จะต้องประกอบไปด้วย returnType functionName(parameter1, parameter2, ...){}
Example :
Output :
6. Namespace Keywords :
Namespace Keywords คือ Keyword ที่ใช้ในการประกาศขอบเขตที่จะใช้ในการจัดเก็บกลุ่มของ Object ที่มีความเกี่ยวข้องกันไว้ใน Namespace ใด ๆ ทั้งนี้ Object / ชื่อคลาส ต่าง ๆ ที่ถูกประกาศไว้ใน namespace ใด ๆ แล้ว จะไม่เกิดการขัดแย้งต่อ Object / ชื่อคลาส ที่เหมือนกัน ที่ถูกประกาศไว้ใน namespace อื่น โดยเราสามารถใช้ namespace ในการจัดระเบียบของโค้ดและสร้างประเภทเฉพาะของตัว global โดยมี Keyword ที่ใช้อยู่ด้วยกันทั้งหมด 3 ตัว ได้แก่
namespace
using
extern
เปรียบเทียบกับ....
Python : ใน Python สามารถแบ่ง namespace ออกได้เป็น 4 ประเภท ได้แก่ Built-in, Global, Enclosing, Local ซึ่ง namespace เหล่านี้จะเปรียบเสมือนตัว dictionary
Java : ใน Java. namespace สามารถสร้างขึ้นมาได้ โดยการเรียกใช้ package keyword ตามด้วยชื่อ "namespace" ที่ต้องการ
C : ไม่มี namespace แต่มี scope ที่มีแนวคิดใกล้เคียงกับ namespace
Example :
Output :
7. Operator Keywords :
Operator Keywords คือ Keyword ที่มีการใช้งานที่แตกต่างกันขึ้นอยู่กับวัตถุประสงค์ที่ต้องการจะให้เป็น โดยอาจจะเป็นการสร้าง Object , รับขนาดของ Object มีอยู่ด้วยกันทั้งสิ้น 8 ตัว ได้แก่
as
is
new
sizeof
typeof
true
false
stackalloc
เปรียบเทียบกับ....
Python : ใน Python มี Operator อยู่ด้วยกัน 5 ตัว ได้แก่ and, or, not, in, is ซึ่ง 3 ตัวแรก จะทำหน้าที่เหมือนกับสัญลักษณ์ทางตรรกศาสตร์ในเชิงคณิตศาสตร์
Java : Java ไม่มี Operator Keyword ที่แน่ชัด แต่สนับสนุนการตัวดำเนินการที่หลากหลายแทน แบ่งออกได้เป็น 8 กลุ่ม - Unary, Arithmetic, Shift, Relational, Bitwise, Logical, Ternary, Assignment Operator
C : C มี Operator ที่ค่อนข้างคล้ายกับ Java เพียงแต่ C จะไม่มี Shift Operator และมี Sizeof , Comma, Member Selection Operator เพิ่มเข้ามา
Output :
8. Conversion Keywords :
Conversion Keywords คือ Keyword ที่ใช้ในการแปลงประเภทของข้อมูลไปเป็นอีกประเภทหนึ่ง มี Keyword ด้วยกันทั้งสิ้น 3 ตัว ได้แก่
explicit
implicit
operator
เปรียบเทียบกับ....
Python : มีการ Conversion อยู่ 2 รูปแบบ - Implicit Conversion หรือ การ Conversion เองโดยอัตโนมัติของตัวโค้ดเอง และ Explicit Conversion หรือ การ Conversion ด้วยตัวเองโดยการเขียนโค้ดกำหนดการแปลงลงไป
Java : มีการ Conversion 4 รูปแบบ - Widening (Automatic), Narrowing (Explicit), Type Promotion in Expression และ Explicit Type Casting in Expressions
C : C มีรูปแบบการ Conversion อยู่ 2 รูปแบบ เช่นเดียวกันกับ Python คือ Implicit และ Explicit Conversion
Example :
Output :
9. Access Keywords :
Access Keywords คือ Keyword ที่ใช้ในการเข้า/อ้างอิงถึง คลาสหรือ instance ของคลาสใด ๆ มี Keyword ทั้งหมด 2 ตัว ได้แก่
base
this
เปรียบเทียบกับ....
Python : ใน Python ไม่มี Access Keyword ที่เจาะจงเฉพาะแน่นอน
Java : ใน Java Access เกี่ยวข้องกับ ตัว Modifier หรือก็คือ ใช้ Keyword เดียวกัน ซึ่งก็คือ public, private, default , protected
C++ : ใน C++ มี Keyword ที่ใช้ในการ Access เช่นเดียวกันกับ Java เพียงแต่จะไม่มีตัว default เท่านั้น
Example :
Output :
10. Literal Keywords :
Literal Keywords คือ Keyword ที่ใช้ในแทนตัวอักษรหรือค่าคงที่ มีอยู่ด้วยกัน 2 ตัว ได้แก่
null
default
เปรียบเทียบกับ....
Python : ใน Python literal นับเป็นตัวแทนของค่าที่ถูกแก้ไขแล้วในโปรแกรม สามารถอยู่ในรูปแบบใดก็ได้ ไม่ว่าจะเป็น ตัวเลข ตัวอักษร หรือ ประโยค
Java : ใน Java. Literal คือ ค่าทุกอย่างที่ถูกกำหนดไว้ให้กับตัวแปรต่าง ๆ เช่น boolean, numeric, character, string จัดได้ 5 ประเภท คือ Integer(Decimal literals (Base 10), Octal literals (Base 8), Hexa-decimal literals (Base 16), Binary literals), Floating-point (Decimal literals(Base 10)), Char(Single quote, Char literal as Integral literal, Unicode Representation, Escape Sequence), String และ boolean literal
C : มี Literal อยู่ด้วยกัน 4 ประเภท ได้แก่ Integer, Float Character และ String Literal ส่วนของ Integer Literal จะแบ่ง ได้อีก 4 แบบย่อย คือ Decimal-literal(base 10) , Octal-literal(base 8) , Hex-literal(base 16) , Binary-literal(base 2)
Example :
Output :
Video :
---
Slide :
---
Reference :
C# Keyword & Code :
Keyword (เพิ่มเติมส่วนของ namespace) : https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/namespace
(Value)int/byte/bool : https://www.geeksforgeeks.org/c-sharp-keywords/?ref=shm
(Value)double/float/decimal : https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types
(Value)long : https://www.w3schools.com/cs/cs_data_types.php
Reference (Code)https://www.w3schools.com/cs/cs_interface.php
Modifier/Statements/Operator/Literal (Code) https://www.geeksforgeeks.org/c-sharp-keywords/?ref=shm
Method Parameter(Code)https://www.scholarhat.com/tutorial/csharp/csharp-method-parameters
Namespace/Access (Code) https://www.javatpoint.com/c-sharp-namespaces
Conversion (Code) https://dev.programiz.com/csharp-programming/type-conversion
Python Keyword Reference & Code :
Java Keyword Reference & Code :
C Keyword Reference & Code :
C++ Keyword Reference & Code :
Last updated