c#,運算符,if else 語句

運算符
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;spa

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
//數學運算符加減乘除模
int a = 1;
int b = 2;
int c = a + b;
c = a++;//a++至關於a=a+1,++a=a先計算a前面的後加
Console.WriteLine(c);
Console.WriteLine(a);
//比較運算符:> < >= <= <> == !=
// bool bo=a==b;
// Console.WriteLine(bo);
//邏輯運算符 && || !,!用在小括號前面的
bool bo;
bo = a > b && a > 2;
Console.WriteLine();
//賦值運算符+=、-=、*=、/=、&=、||=、%=、
a = a + b;//等同於a+=b數學

//條件運算符(比較表達式)?(語句一):(語句二);
//知足條件運行語句一,不知足條件運行語句二
c=(a > b)?(a +1):(b+1);
Console.WriteLine(c);
string s;
s = Console.ReadLine();
a = a+int.parse(s.tostring());
Console.WriteLine(s);
Console.ReadLine();
}
}
}
/*語句:
* 分支語句 :if,if else ,if elseif else, switch case
* 循環語句:for,while,do while,foreach
* 跳轉語句:break,continue
* 異常語句:try, catch ,finally
**/
int a = 0;
if (a > 0)
{
Console.WriteLine("這是一個正數");
if (a > 10)
{
Console.WriteLine("這是一個大於十的數");
}string

}
else
{
Console.WriteLine("這是一個小於0的數");
}
Console.ReadLine();it

相關文章
相關標籤/搜索