C#,Keywords မ်ား(၁)

Thursday, July 1, 2010

C# မွာ keywords အမ်ိဳးအစား မ်ား (၁၁) မ်ိဳးရွိတယ္ ။
(၁) types အမ်ိဳးအစားကိုေဖာ္ျပတဲ႔ကီးဝါ႔ဒ္ေတြ
(၂) modifiers keywords မ်ား
(၃) Statement keywords မ်ား
(၄) Parameter keywords မ်ား
(၅)namespace keywords မ်ား
(၆) operator keywords မ်ား
(၇) Conversion keywords မ်ား
(၈)Access keywords မ်ား
(၉)Literal keywords မ်ား
(၁၀) Contextual keywords မ်ား
(၁၁)Quary keywords မ်ား

(၁) types အမ်ိဳးအစားကိုေဖာ္ျပတဲ႔ကီးဝါ႔ဒ္မ်ား

Types အမ်ိဳးအစားကိုေဖာ္ျပတဲ႔ကီးဝါ႔ဒ္ေတြမွာဆိုရင္
(၁) values types
(၂) reference types
(၃)pointer types

ဆိုၿပီး ၃ မ်ိဳးရွိ တယ္ ။

Value types မ်ား

(၁)Bool
- System.Boolean ရဲ့အစားအေနနဲ႔သံုးတယ္ ။ true နဲ႔ false တန္းဖိုးေတြကို ထိန္းသိမ္းနိုင္ဖို႔ေၾကျငာတယ္။
0 မွ 255 ထိပမာဏရွိၿပီးေတာ႔ သူရဲ့အရြယ္စားေနရာယူမွဳကေတာ႔ Unsigned 8-bit integerျဖစ္ပါတယ္
Byte ကေနၿပီးေတာ႔ short, ushort, int, uint, long, ulong, float, double, or decimal. တို႔ကို ေျပာငး္လဲေပးလို႔ရပါတယ္။

byte x = 10, y = 20;
byte z = x + y;
လို႔တိုက္ရိုက္ေပါင္းလို႔မရပါဘူး ဘာလို႔လဲဆိုေတာ႔ assigment ရဲ့ ညာဘက္ကိန္းဟာ integer ကိန္း default ျဖစ္ေနလို႔ပါပဲ ။ဒါေၾကာင္႔
byte z = (byte)(x + y);
လို casting လုပ္ေပးရပါတယ္ ။

(၂) char key word
char keyword ကို unicode character ေတြကိုေၾကျငာဖို႔ အသံုးျပဳပါတယ္ ။
သူရဲ့ range ကေတာ႔ U+0000 ကေနၿပီး U+ffff ထိပါ ။ size ကေတာ႔ Unicode 16-bit character
ျဖစ္ပါတယ္ ။ character မွ ushort, int, uint, long, ulong, float, double, or decimal. တို႔ကိုေျပာင္းလဲေပးနိင္ပါတယ္ ။ ဒါေပမဲ႔ တျခားတိုပ္ေတြကေန char ကို implicit အျဖစ္ေျပာင္းလဲေပးလို႔မရနိင္ပါဘူး ။
(၃)decimal
decimal keyword ကေတာ႔ 128 bit ေဒတာအမ်ိဳးအစားေတြကိုျပဆိုပါတယ္ ။ float နဲ႔ဆင္တယ္
ဒါေပမဲ႔ float ထက္ပိုၿပီး range နည္းၿပီးေတာ႔ ပိုၿပီး အေသစိတ္တိက်နိုင္ပါတယ္ ။ ဒါေၾကာင္႔
စီးပြားေရး နဲ႔ ေငြေရးေၾကးေရးဆိုင္ရာတြက္ခ်က္မွုေတြမွာ decimal ကိုသံုးၾကပါတယ္ ။
decimal
range- (-7.9 x 1028 to 7.9 x 1028) / (100 to 28)
size - 28-29 significant digits
Decimal ကိုသံုးမယ္ဆိုရင္ suffix (ေနာက္ဆက္တြဲအေနနဲ႔) m ဒါမွမဟုတ္ M ကိုထည့္ေပးရပါမယ္ ။
ဥပမာ - decimal myMoney = 300.5m;
တကယ္လို႔ suffix မပါဘူးဆိုရင္ေတာ႔ compiler က double အေနနဲ႔ပဲသိမွာပါ ။
Intiger type ကေန decimal ကိုတိုက္ရိုက္ေျပာင္းလို႔ရပါတယ္ ။ ဒါေၾကာင္႔
decimal myMoney = 300;
ပံုစံမ်ိဳးေရးသားနိုင္ပါတယ္ ။
Float type ကေန decimal ေျပာင္းတဲ႔အခါမွာေတာ႔တိုက္ရိုက္ေျပာင္းလို႔မရပါဘူး ဒါေၾကာင္႔ casting လုပ္ေပးရပါမယ္ ။

decimal myMoney = 99.9m;
double x = (double)myMoney;
myMoney = (decimal)x;

(၄)double
double keyword ကေတာ႔ float value ကို 64 အေနနဲ႔သိမ္းဆည္းနိဳင္မဲ႔ ရိုးရိုး အမ်ိဳးစားတစ္ခုပါပဲ ။
double
±5.0 × 10−324 to ±1.7 × 10308
15-16 digits
အေပၚကသူ႔ရဲ့ range နဲ႔ precision ပါ ။
integer တန္ဖိုးကို double အေနနဲ႔အလြယ္တစ္ကူေျပာင္းခ်င္တယ္ဆိုရင္ suffix d သို႔ D ထည့္ေပးရံုနဲ႔အဆင္ေျပပါတယ္ ။
double x = 3D;
(၅)enum
enum keyword ကိုေတာ႔ enumerator list အစုေတြပါဝင္တဲ႔ enumation ေတြကို ေၾကျငာဖို႔သံုးပါတယ္ ။ ပံုမွန္အားျဖင္႔ေတာ႔ ပထမဆံုး enumerator ရဲ့ တန္ဖိုး ဟာ ၀ (သုည) ျဖစ္ၿပီးေတာ႔ enumerator တစ္ခုတိုးတိုင္း ၁ တိုးသြားပါတယ္ ။

enum Days {Sat, Sun, Mon, Tue, Wed, Thu, Fri};
ဒီ ျပထားတဲ႔ ဥပမာ မွာဆိုရင္ enumerator sat ရဲ့ တန္ဖိုးဟာ ၀ ျဖစ္ၿပိး sun=2,Mon=3,...
လို႔တိုးသြားပါတယ္ ..။

(၆)float
Float ကို 32-bit floating point value ေတြသိမ္းဆည္းထားတဲ႔ simple type အေနနဲ႔သံုးတယ္ ။
သူရဲ့ range ကေတာ႔ -3.4 × 1038 to +3.4 × 1038 ျဖစ္ပါတယ္ ။ float တန္းဖိုးေတြကို သိသာေအာင္
အတိုေကာက္အေနနဲ႔ ေနာကက္ေနၿပီး “F” ထည့္ေပးပါတယ္ ။
float x = 3.5F;
တကယ္လို႔ ေနာက္ကေန F မထည့္ေပးခဲ႔ဘူးဆိုရင္ ေတာ႔ compile error ျပမွာပါ ။ဘာလို႔လဲဆိုေတာ႔ Fမပါဘူးဆိုရင္ double type အျဖစ္ပဲ ကြန္ပ်ဴတာကသိမွာပါ ။ ဒါေၾကာင္႔ double တန္ဖိုးကို float ထဲမွာသြား ၿပီး ထားသလိုျဖစ္ေနလို႔ error ျပမွာပါ ။
Floating_point expression မွာဆိုရင္
Positive and negative zero
Positive and negative infinity
Not-a-Number value (NaN)
The finite set of nonzero values
ေတြပါဝင္ပါတယ္ ။
class FloatTest
{
static void Main()
{
int x = 3;
float y = 4.5f;
short z = 5;
var result = x * y / z;
Console.WriteLine("The result is {0}", result);
Type type = result.GetType();
Console.WriteLine("result is of type {0}", type.ToString());
}
}
/* Output:
The result is 2.7
result is of type System.Single //'float' is alias for 'Single'
*/

(၇) int
int keyword ကေတာ႔ integral type value ေတြ ကို သိမ္းဆည္းနိုင္မွာျဖစ္တယ္ ။သူရဲ့ range က -2,147,483,648 to 2,147,483,647 ရွိၿပိးေတာ႔ ၊ size ကေတာ႔ Signed 32-bit integer ၊ နဲ႔
.Net Frame Work type ကေတာ႔ System.Int32 ေအာက္မွာရွိပါတယ္ ။
int i = 123;
int က ေနၿပီး long, float, double, or decimal. ေတြကို တန္ဖိုးတိုက္ရိုက္ေျပာင္းလဲနိုင္ပါတယ္ (implicit ျဖစ္တယ္လို႔ေျပာနိုင္)
// '123' is an int, so an implicit conversion takes place here:
float f = 123;
sbyte, byte, short, ushort, or char ကေနၿပီး int ကိုတိုက္ရိုက္ (implicit) အျဖစ္ေျပာင္းလဲနိုင္ေပမဲ႔
long, float, double, or decimal. တို႔ကေနၿပီး Int ကိုေျပာင္းရမွာေတာ႔ သြယ္ဝိုက္ပဲေျပာင္းလို႔ရပါတယ္(explicit) ။ ေျပာင္းလို႔ အဆင္ေျပခ်င္ရင္ casting သံုးရမွာျဖစ္ပါတယ္ ။
long aLong = 22;
int i1 = aLong; // Error: no implicit conversion from long.
int i2 = (int)aLong; // OK: explicit conversion.


(၈) long
long keyword ကလည္း integral type ေတြကို store လုပ္မဲ႔ အမ်ိဳးစားပါပဲ ။
Type - long
Range - –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Size - Signed 64-bit integer
.NET Framework type - System.Int64
example:
long long1 = 4294967296;


long ကိုပိုၿပီးမွန္ကန္ေစခ်င္ရင္ေတာ႔ suffix L ထည့္ၿပိးသံုးနိုင္ပါတယ္ ။
long long2 = 4294967296L;

long မွ float, double, or decimal. Long ေတြကို တိုက္ရုိက္(implicit) ေျပာငး္လဲနိုင္ပါတယ္
sbyte, byte, short, ushort, int, uint, or char မွ Long ကို တိုက္ရိုက္ (implicit) အေနနဲ႔ေျပာင္းလဲနိုင္ၿပီး က်န္တဲ႔ value type ေတြမွာေတာ႔ casting လုပ္ၿပီး သြယ္ဝိုက္ၿပီး(explicit) သာေျပာင္းလဲနိုင္ပါတယ္ ။
long x = 3.0; // Error: no implicit conversion from double
long y = (long)3.0; // OK: explicit conversion

0 comments:

Post a Comment

ဒီPost ရဲ႕ေရးသားခ်က္နဲ႕ပက္သက္ျပီး ေ၀ဖန္အၾကံျပဳႏုိင္ပါတယ္။