ASP.NET Razor - C# Variables
ကိန်းရှင်များကို ဒေတာသိမ်းဆည်းရန် အသုံးပြုသည့် အရာများဟု အမည်ပေးထားသည်။
ကိန်းရှင်များ
ဒေတာသိမ်းဆည်းရန် ကိန်းရှင်များကို အသုံးပြုသည်။
ကိန်းရှင်တစ်ခု၏အမည်သည် အက္ခရာစာလုံးဖြင့် အစပြုရမည်ဖြစ်ပြီး နေရာလွတ် သို့မဟုတ် သီးသန့်စာလုံးများ မပါဝင်နိုင်ပါ။
ကိန်းရှင်သည် သိမ်းဆည်းထားသည့် ဒေတာအမျိုးအစားကို ညွှန်ပြသော အမျိုးအစားတစ်ခုဖြစ်သည်။ ကြိုးတန်းကိန်းရှင်များသည် string တန်ဖိုးများကို သိမ်းဆည်းသည် ("W3Schools မှကြိုဆိုပါတယ်")၊ ကိန်းပြည့်ကိန်းရှင်များ သိမ်းဆည်းထားသော နံပါတ်တန်ဖိုးများ (103)၊ ရက်စွဲကိန်းရှင်များ သိမ်းဆည်းသည့် ရက်စွဲတန်ဖိုးများ စသည်ဖြင့် ကိန်းရှင်များ
ကို var သော့ချက်စာလုံးကို အသုံးပြု၍ သို့မဟုတ် အမျိုးအစားကို အသုံးပြု၍ (သို့) အမျိုးအစားကို အသုံးပြုခြင်းဖြင့် (ကြေငြာလိုပါက၊ type) သို့သော် ASP.NET သည် အများအားဖြင့် ဒေတာအမျိုးအစားများကို အလိုအလျောက် ဆုံးဖြတ်နိုင်သည်။
ဥပမာများ
//
Using the var keyword:
var greeting = "Welcome to W3Schools";
var
counter = 103;
var today = DateTime.Today;
// Using data types:
string greeting = "Welcome to W3Schools";
int counter = 103;
DateTime
today = DateTime.Today;
ဒေတာအမျိုးအစားများ
အောက်တွင် အသုံးများသော ဒေတာအမျိုးအစားများစာရင်းဖြစ်သည်-
Type | Description | Examples |
---|---|---|
int | Integer (whole numbers) | 103, 12, 5168 |
float | Floating-point number | 3.14, 3.4e38 |
decimal | Decimal number (higher precision) | 1037.196543 |
bool | Boolean | true, false |
string | String | "Hello W3Schools", "John" |
လုပ်ငန်းရှင်များ
အော်ပရေတာတစ်ခုသည် စကားရပ်တစ်ခုတွင် လုပ်ဆောင်ရမည့် command အမျိုးအစားကို ASP.NET အား ပြောပြသည်။
C# ဘာသာစကားသည် အော်ပရေတာများစွာကို ပံ့ပိုးပေးသည်။ အောက်တွင် ဘုံအော်ပရေတာများစာရင်းဖြစ်သည်-
Operator | Description | Example |
---|---|---|
= | Assigns a value to a variable. | i=6 |
+ - * / |
Adds a value or variable. Subtracts a value or variable. Multiplies a value or variable. Divides a value or variable. |
i=5+5 i=5-5 i=5*5 i=5/5 |
+= -= |
Increments a variable. Decrements a variable. |
i += 1 i -= 1 |
== | Equality. Returns true if values are equal. | if (i==10) |
!= | Inequality. Returns true if values are not equal. | if (i!=10) |
< > <= >= |
Less than. Greater than. Less than or equal. Greater than or equal. |
if (i<10) if (i>10) if (i<=10) if (i>=10) |
+ | Adding strings (concatenation). | "w3" + "schools" |
. | Dot. Separate objects and methods. | DateTime.Hour |
() | Parenthesis. Groups values. | (i+5) |
() | Parenthesis. Passes parameters. | x=Add(i,5) |
[] | Brackets. Accesses values in arrays or collections. | name[3] |
! | Not. Reverses true or false. | if (!ready) |
&& || |
Logical AND. Logical OR. |
if (ready && clear) if (ready || clear) |
ဒေတာအမျိုးအစားများကို ပြောင်းလဲခြင်း။
ဒေတာအမျိုးအစားတစ်ခုမှ အခြားတစ်မျိုးသို့ ပြောင်းလဲခြင်းသည် တစ်ခါတစ်ရံတွင် အသုံးဝင်သည်။
အသုံးအများဆုံးဥပမာမှာ ကိန်းပြည့် သို့မဟုတ် ရက်စွဲကဲ့သို့ string input ကို အခြားအမျိုးအစားသို့ ပြောင်းရန်ဖြစ်သည်။
စည်းမျဉ်းအရ၊ အသုံးပြုသူသည် နံပါတ်တစ်ခုထည့်ထားသော်လည်း၊ အသုံးပြုသူထည့်သွင်းမှုသည် စာကြောင်းများအဖြစ်လာသည်။ ထို့ကြောင့်၊ ဂဏန်းထည့်သွင်းမှုတန်ဖိုးများကို တွက်ချက်ရာတွင် အသုံးမပြုမီ ဂဏန်းများအဖြစ်သို့ ပြောင်းရပါမည်။
အောက်တွင် ဘုံပြောင်းလဲခြင်းနည်းလမ်းများ စာရင်းတစ်ခုဖြစ်သည်။
Method | Description | Example |
---|---|---|
AsInt() IsInt() |
Converts a string to an integer. | if (myString.IsInt()) {myInt=myString.AsInt();} |
AsFloat() IsFloat() |
Converts a string to a floating-point number. | if (myString.IsFloat()) {myFloat=myString.AsFloat();} |
AsDecimal() IsDecimal() |
Converts a string to a decimal number. | if (myString.IsDecimal()) {myDec=myString.AsDecimal();} |
AsDateTime() IsDateTime() |
Converts a string to an ASP.NET DateTime type. | myString="10/10/2012"; myDate=myString.AsDateTime(); |
AsBool() IsBool() |
Converts a string to a Boolean. | myString="True"; myBool=myString.AsBool(); |
ToString() | Converts any data type to a string. | myInt=1234; myString=myInt.ToString(); |