namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
/*
//表达式与运算符
int a = 5;
int b = 10;
int result = a + b;//a,b操作数,+操作符
Console.WriteLine(result);
//字面值
//1.整型字面值
Console.WriteLine("{0}", 1024);
Console.WriteLine("{0}", 1024L);
Console.WriteLine("{0}", 1024U);
Console.WriteLine("{0}", 1024UL);
//2.浮点型字面值
Console.WriteLine("{0}", 3.14);
Console.WriteLine("{0}", 3.14f);
Console.WriteLine("{0}", 3.14m);
//3.字符型字面值
Console.WriteLine("{0}", 'd');
Console.WriteLine("{0}", '\n');
Console.WriteLine("{0}", Char.ToUpper ('a'));
Console.WriteLine("a{0}b", '\t');
Console.WriteLine("{0}", '\x0023');
//4.字符串字面值
Console.WriteLine("{0}", "ABCD您好");
Console.WriteLine("{0}", "\u4e2d您好A\tB");
Console.WriteLine("{0}", "\u4e2d您好A\\tB");
Console.WriteLine("{0}", @"\u4e2d您好A\tB"); //原样打印
Console.WriteLine("{0}", @"\u4e2d您好""tB"); //原样打印的一个例外
*/
//运算符与表达式
//1.简单数学运算与取余
//int x1 = 3 + 4;
//int x2 = 12 - 5;
//int x3 = 5 * 8;
//int x4 = 10 / 3;
//double x5 = 10 / 3;
//var x6 = 10.0 / 3;
//Console.WriteLine($"x1={x1}");
//Console.WriteLine($"x2={x2}");
//Console.WriteLine($"x3={x3}");
//Console.WriteLine($"x4={x4}");
//Console.WriteLine($"x5={x5}");
//Console.WriteLine($"x6={x6}");
//var a = 10 % 3;
//var b = -10 % -3;
//var c = -10 % 3;
//var d = 10 % -3;
//Console.WriteLine($"a={a}");
//Console.WriteLine($"b={b}");
//Console.WriteLine($"c={c}");
//Console.WriteLine($"d={d}"); //余数符号一定与被除数符号一致.
//2.关系与比较运算符(返回值是bool型)
// double a = 75.0;
// double b = 59.3;
// double c = 60.0;
// bool result = a == b;
// Console.WriteLine(result);
// Console.WriteLine("a>b={0}",a>b);
// Console.WriteLine("c<b={0}", c < b);
// Console.WriteLine("c>=60.0={0}", c >=60.0);
// Console.WriteLine("c!=60.0={0}", c!=60.0);
// //引用比较
// Student s1 = new Student();
// s1.score = 90;
// Student s2 = new Student();
// s2.score = 90;
// Console.WriteLine("s1==s2 结果是:{0}", s1==s2);//为什么是False???? 引用类型比较的是地址.
// Console.WriteLine("s1.score==s2.score 结果是:{0}", s1.score == s2.score);
// string x = "abc";
// string y = "abc";
// Console.WriteLine("x==y 结果是:{0}", x == y);//string也是引用类型,为什么结果是True
//3.自增自减运算符 ++i i++ --i i--
// int i = 5;
// int j;
j = i++; // 6,5
// j = ++i; //6,6
// Console.WriteLine("i={0},j={1}", i, j);
// //4.条件逻辑运算符
// Employee emp1 = new Employee();
// emp1.name = "TOM";
// emp1.salary = 7000m;
// emp1.workYear = 10;
// Employee emp2 = new Employee();
// emp2.name = "ROSE";
// emp2.salary = 8000m;
// emp2.workYear = 8;
// //判断某个员工是否符合加薪条件
// //现有薪资低于7500并且工作年限大于10年
// Console.WriteLine("TOM是否符合加薪条件:{0}", emp1.salary < 7500m && emp1.workYear >= 10);
// Console.WriteLine("TOM是否符合加薪条件:{0}", emp1.salary < 7000m && emp1.workYear >= 10);
// //现有薪资低于7500或者工作年限大于10年
// Console.WriteLine("TOM是否符合加薪条件:{0}", emp1.salary < 7500m || emp1.workYear >= 10);
// Console.WriteLine("TOM是否符合加薪条件:{0}", emp1.salary < 7000m || emp1.workYear >= 10);
// //第二个员工的工资是否>=8000;
// Console.WriteLine(emp2.salary >=8000m);
// Console.WriteLine(!(emp2.salary >= 8000m));
// bool result1,result2;
// result1 = (1 == 2) && (2 == 2);
// Console.WriteLine(result1);
// result1 = (1 == 1) || (1 == 2);
// Console.WriteLine(result2);
//5.位运算符(优化算法,提高速度)
byte x = 12, y = 10;
sbyte result;
//result =(sbyte)(x & y); //位与
//result = (sbyte)(x | y);//位或
//result =(sbyte)(~x); //位非
//result = (sbyte)(x ^ y); //异或
//result = 112 >> 3;
result = 14 << 3;
Console.WriteLine(result);
//6.赋值运算
int x1 = 5;
int y1 = 3;
//x1 = x1 + y1;
x1 += y1;
Console.WriteLine(x1);
//7.三元运算符与一元运算符
//一元运算符
int num = +10;
num = -num;
//三元运算符 ? :
double score = 63.5;
string msg;
//if (score >= 60)
//{
// msg = "OK!";
//}
//else
//{
// msg = "NO!";
//}
// Console.WriteLine(msg);
msg = score >= 60 ? "OK!" : "NO!";
Console.WriteLine(msg);
}
}
class Student
{
public int score;
}
class Employee
{
public string name;
public decimal salary;
public int workYear;
}
}