代码:
string name = "小赵";
//条件判断
if (name == "小赵")
{
Console.WriteLine("我是小赵");
}
else
{
Console.WriteLine("我不是小赵");
}
// switch条件判断
switch (name)
{
case "小赵":
Console.WriteLine("我是小赵");
break;
case "小房":
case "小范":
Console.WriteLine("我是小赵好朋友");
break;
default:
Console.WriteLine("我是陌生人");
break;
}
//方法二
string res = name switch
{
"小赵" => "小赵",
"小范" => "小范",
"小房" => "小房",
_ => "陌生人",
};
//循环
//string[] nameAge = new string[3];//
string[] nameAge = new string[] { "小赵", "小范", "小房" }; //数组
for (int i = 0; i < nameAge.Length; i++)
{
Console.WriteLine($"我是{i}");
}
//while循环
int age = 10;
while (age <= 20)
{
Console.WriteLine($"{age}");
age++;
};
//do,while循环
do
{
Console.WriteLine($"{age}");
age++;
}while(age<30);