C#自学笔记之逻辑运算
- 除按位非运算符以外,都是二元左结合运算符,因为按位非是一元运算符。
class Program
{
static void Main(string[] args)
{
//const 修饰变量为只读变量
const byte x = 12, y = 10;
int a = x & y;
int b = x | y;
int c = x ^ y;
int d = ~x;
Console.WriteLine("x&y:{0}", a);
Console.WriteLine("x|y:{0}", b);
Console.WriteLine("x^y:{0}", c);
Console.WriteLine("~x:{0}", d);
Console.ReadKey();
}
}
运行结果: