Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @{
- //多半用var來宣告變數型態,並且強制初始值
- var say = "大家安安";
- @* 若有特殊符號(脫逸字元)要在前面加@ *@
- var name = @"\Razor/";
- //加雙引號的方法 "" ( 為什麼不是 \" 啊... )
- var Weight = @"體重有""20""公頓";
- /* 也可以直接宣告變數型態 */
- int height = 180;
- @*
- 變數型態轉換
- *@
- var birthdayStr = "2010/1/1";
- var birthday = default(DateTime);
- if (birthdayStr.IsDateTime()) //可預防exception
- {
- birthday = birthdayStr.AsDateTime();
- }
- //可以玩條件判斷唷
- var msg = "";
- if (DateTime.Now.Hour >= 12)
- {
- msg = "下午時段";
- }
- else
- {
- msg = "早唷!";
- }
- }
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width" />
- <title></title>
- </head>
- <body>
- <div>
- @say 我的名字叫: @name
- <br>
- 身高是:@(@height)公分<br>
- @Weight<br>
- 出生於:@birthday<br>
- @msg
- <br>
- 現在:@{@DateTime.Now.Hour;}點<br>
- @{
- int total = 0;
- for (int i = 1; i <= 10; i++)
- {
- @:i=@i.ToString(); <br />
- total += i;
- }
- @total;
- }
- <br />
- <!-- 可以用while迴圈很潮吧! -->
- @{
- var total2 = 0;
- var i2 = 1;
- while (i2 <= 10)
- {
- total2 += i2;
- i2++;
- }
- }
- while迴圈的結果:@total2
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement