玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
【C#】 0323
今日進度:
C# Operators: Comparison & Logical
C# Math
C# Strings:
Strings, Concatenation, Interpolation
.
先開噗 (用上新撿到的柴柴表符
latest #21
掰噗~
1 months ago
喔?
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
本日復習:
using System;
namespace 我好像真的背起來ㄌ誒
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“只是還沒搞懂各部分是什麼意思”);
}
}
}
立即下載
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
=
接上回

3. 關係運算子 Comparison Operators:
比較兩 值/變數
→只會得 True/False 兩種結果

== Equal to
!= Not Equal
> 大於
< 小於
>= 大於等於
<= 小於等於
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
-
int a=1, b=2;
Console.WriteLine(a==b); // False
Console.WriteLine(a!=b); // True
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
4. 邏輯運算子 Logical Operators
評斷兩個“條件”是否成立 True/False

&& Logical and 前後條件都要為真,則為真
|| Logical or 前後條件其一為真,則為真
! Logical not 取反:
!( && )→將(A&&B)結果“取反”
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
-
int x=5;
Console.WriteLine( x>3 && x>10 ); // False
Console.WriteLine( x>3 || x>10 ); // True
Console.WriteLine( !(x>3&&x<10));// True
=
Math 類別進行數學運算
Math.Max:最大值
Math.Min:最小值
Math.Sqrt:平方根 Square Root
Math.Abs:絕對值 Absolute (positive) value
Math.Round:取最接近整數
→小數點≦0.5捨去,>0.5進位
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
-
int x=5, y=10;
Console.WriteLine(Math.Max (x,y)); // 10
-
Console.WriteLine(Math.Round(0.51)); // 1
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
=
Strings 字串
1. 變數.Length:計算字串長度
-
string txt = “ iPhone 15 “;
Console.WriteLine(“字串長度總共是: “+txt.Length);
// 字串長度總共是: 11
2. 變數.ToUpper():大寫
-
Console.WriteLine(txt.ToUpper());
// IPHONE 15
3. 變數.ToLower():小寫
-
Console.WriteLine(txt.ToLower());
// iphone 15
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
4. string.Concat( , ):
串聯多個字串 Concatenation
-
string firstname=“Madge “, lastname=“Lee”;
string name= firstname + lastname
// 運用 “+” 進行串接
Console.WriteLine(name); // Madge Lee
-
Console.WriteLine(string.Concat(firstname, lastname);
// Madge Lee
注意:“+” 可用於相加串接兩種狀況
數值→相加;數「字」→串接
-
int a=10, b=20;
Console.WriteLine(a+b); // 10+20=30
-
string a=“10”, b=“20”;
Console.WriteLine(a+b);
//文字「10」串接文字「20」=1020
玖。|ू •̀ω•́ )۶
1 months ago @Edit 1 months ago
5. $”{}{}” :字串差補Interpolation
將字串常值識別為「插補字串」
-
string NAME =$”My full name is {firstname}{lastname}”;
Console.WriteLine(NAME);
// My full name is Madge Lee

以上兩行也可以合併成
Console.WriteLine($”My full name is {firstname}{lastname}”);
=
放點之後再看的參考資料w
back to top