1.==,!=,<,<=,>,>=
2.逻辑运算符:&&,||
3.运算符的优先级
4.if语句,级联的IF语句
eg:WPF DEMO Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SelectionDemo
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Compare_Click(object sender, RoutedEventArgs e)
{
int diff = dateCompare(first.SelectedDate.Value, second.SelectedDate.Value);
info.Text = "";
show("first ==second", diff==0);
show("first !=second", diff != 0);
show("first < second", diff < 0);
show("first <=second", diff <= 0);
show("first > second", diff > 0);
show("first >=second", diff >= 0);
}
public void show(string exp,bool result) {
info.Text += exp;
info.Text += ":"+result.ToString();
info.Text += "\r\n";
}
public int dateCompare(DateTime leftHandSide, DateTime rightHandSide)
{
int result;
if (leftHandSide.Year > rightHandSide.Year)
{
result= 1;
}
else if (leftHandSide.Year < rightHandSide.Year)
{
result = -1;
}
else if (leftHandSide.Month > rightHandSide.Month)
{
result = 1;
}
else if (leftHandSide.Month < rightHandSide.Month)
{
result = -1;
}
else if (leftHandSide.Date > rightHandSide.Date)
{
result = 1;
}
else if (leftHandSide.Date < rightHandSide.Date)
{
result = -1;
}
else
{
result = 0;
}
return result;
}
}
}
5.switch语句:
a.case语句后只能跟int,string类型等原始数据类型
b.case语句只能跟值固定的表达式(只能跟具体值,不能跟变量值)
c.case语句后面的表达式必须唯一,不能出现两个case语句拥有相同的值.
eg:1.WPF DEMO Source Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SwitchStatement
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void copy_Click(object sender, RoutedEventArgs e)
{
target.Text = "";
string from = source.Text;
for (int i = 0; i != from.Length; i++)
{
char current = from[i];
copyOne(current);
}
}
private void copyOne(char current)
{
switch (current)
{
case '>':
target.Text += ">";
break;
case '<':
target.Text +="<";
break;
case '\"':
target.Text +=""";
break;
case '\'':
target.Text += "'";
break;
default:
target.Text += current;
break;
}
}
}
}
2.Console DEMO:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SwitchDemo
{
class Program
{
static void Main(string[] args)
{
int day;
string dayName;
day =int.Parse( Console.ReadLine());
switch (day)
{
case 0:
dayName = "Sunday";
break;
case 1:
dayName = "Monday";
break;
case 2:
dayName = "Tuesday";
break;
case 3:
dayName = "Wednesday";
break;
case 4:
dayName = "Thursday";
break;
case 5:
dayName = "Friday";
break;
case 6:
dayName = "Saturday";
break;
default:
dayName="Unkown";
break;
}
Console.WriteLine(dayName);
}
}
}