常量
csharp
//常量
//不能修改,运行时
//const
const int achang = 12;
const double paichang = 3.14;
const char cchang= 'F';
int achang1 = achang + 2;
int bchang1 = 22;
double abchang = paichang * bchang1;
Console.WriteLine("achang=" + achang + ",achang1=" + achang1
+ ",abchang=" + abchang);

浮点常量
csharp
//整数常量
//八进制 十进制 十六进制
//浮点常量
const double pi = 3.14;
const double afudianc = 3e3;//指数形式 修正
double bfudianc = afudianc * 4;
const float cfudiancf = 1.2224f;
Console.WriteLine("bfudianc:=\'"+bfudianc+"\',cfidianc:\'"+cfudiancf+"\'");

字符常量
csharp
//字符常量
const char czifu= 'a';
const char dzifu = '\t';
Console.WriteLine("优酷:\twww.mycraft.com\r\n");
Console.WriteLine(czifu + "," + dzifu + "\\?"+"\\211"+"\r\n");

字符串常量
csharp
//字符串常量
const string wangzhan = "www.mycraft.com";
const string zifuc = @"ssadas";
Console.WriteLine("wangzhan:\'" + wangzhan + "\',zifuchaun:" + zifuc);

流程控制
if
csharp
namespace LiuChenPanDuan
{
internal class Program
{
static void Main(string[] args)
{
int age = 11;
if (age == 18) { Console.WriteLine("you are too y"); }
else { Console.WriteLine("AGE:"+age); }
age++;
Console.WriteLine("Hello, World!");
}
}
}

csharp
decimal price = 1399.5m;
if (price > 1000)
{
Console.WriteLine("price too high");
} else {
Console.WriteLine("price is normal");
}

csharp
//if else if
Console.WriteLine("Please input the price");
int priceCs = Convert.ToInt32(Console.ReadLine());
if (priceCs < 0) {
Console.WriteLine("wrong");
}
else if (priceCs >= 0 && priceCs < 200) {
Console.WriteLine("you cannot buy anything");
}
else if (priceCs >=200 && priceCs <2000)
{
Console.WriteLine("you can buy gun,like use or " +
"can buy smoke,flash..or clothes");
}
else if(priceCs >=2000 )
{
Console.WriteLine("YOU can buy exllent gun,like p90");
}


switch
csharp
//switch
Console.WriteLine("Pl input a name");
string rename = Console.ReadLine();
switch (rename)
{
case "siye":
Console.WriteLine("classroom");
break;
case "faker":
Console.WriteLine("god");
break;
case "":
Console.WriteLine("5555");
break;
default:
Console.WriteLine("A NAME");
break;
}
Console.WriteLine("PL input a count");
int count = 3;
switch (count)
{
case 1:
Console.WriteLine("exllent"); break;
case 2:
Console.WriteLine("wonderful"); break;
case 3:
Console.WriteLine("god"); break;
}


for






进行条件判断,如果为 true,则执行循环主体,如果为假,则跳出 for 循环,











csharp
//for循环
Console.WriteLine("pl input a str,str.length have to >5");
string str1=Console.ReadLine();
if (str1.Length < 5) { Console.WriteLine("str.length<5");
return;}
for (int i = str1.Length; i > 5; i--)
{Console.WriteLine(str1[i-1]);
str1 = "0" + str1;
}
Console.WriteLine(str1);
}

csharp
Console.WriteLine(str1);
string str2 = Console.ReadLine();
for(int i=str2.Length; i < 5; i++)
{
str2 = "1" + str2;
}
Console.WriteLine(str2);
}
csharp
Console.WriteLine(str2);
string str3 = Console.ReadLine();
for (int i = 0; i < str3.Length; i++)
{
if (i > 0 && i < str3.Length)
{ Console.WriteLine(""); }
Console.WriteLine(str3[i]);
}

乘法表
csharp
//for 嵌套
for (int i = 1; i <= 9; i++)
{ for(int j = 1; j <= i; j++)
{
int reu = i * j;
string result = reu.ToString().Length == 1 ? reu + "" : reu
.ToString();
Console.Write("{0}x{1}={2}",j,i,result);
}
Console.WriteLine();

无限循环
csharp
//无限循环
for (int i = 0;;i++)
{
if (i < 10)
{
Console.WriteLine("执行中");
}
else
break;
}

csharp
int j1 = 0;
for (int i = 0; ; i++)
{ j1++; }

csharp
string[] names = new string[] { "lk", "kok", "ln", "li" };
foreach (string name in names)
{
Console.WriteLine("{0}", name);
}

while
csharp
//while
int iw = 1;
int sum = 0;
while (iw <= 100)
{
sum = sum + iw;
iw++;
}
Console.WriteLine("1到100的和是:"+sum);

csharp
int i9 = 1;
while (i9 <= 9)
{
int j9 = 1;
while (j9 <= i9)
{
int res = i9 * j9;
string result = res.ToString().Length==1?res+"":res.ToString();
//字符串1的长度为1吗?14长度为2吗 这里就是格式上个位(一位数)和两位数对齐吗?
//是
Console.Write("{0} x {1}={2}", j9, i9, result);
j9++;
}i9++;
Console.WriteLine(); }

do while
csharp
//do while
int doi = 1;
int dosum = 0;
do
{
dosum += doi;
doi++;
} while (doi <= 5);
Console.WriteLine("dosum:"+dosum);
int do9i = 1;



csharp
int do9i = 1;
do
{
int do9j = 1;
do
{
int resdo = do9i * do9j;
string resultdo = resdo.ToString().Length == 1 ? resdo + "" : resdo.ToString();
Console.Write("{0} x {1} = {2} " ,do9i,do9j,resultdo);
} while (do9j <= do9i);
do9i++;
Console.WriteLine();
} while (do9i <= 9);

csharp
int do9i = 1;
do
{
int do9j = 1;
do
{
int resdo = do9i * do9j;
string resultdo = resdo.ToString().Length == 1 ? resdo + "" : resdo.ToString();
Console.Write("{0} x {1} = {2} " ,do9i,do9j,resultdo);
do9j++;
} while (do9j <= do9i);
do9i++;
Console.WriteLine();
} while (do9i <= 9);


break
直接跳出循环
1+...4
csharp
int sumb = 0;
for (int i = 0; i < 10; i++)
{
if (i == 5)
break;
sumb += i;
}

continue
1+...4 +6+...9
跳过余数是5的循环
csharp
//continue
int sumc= 0;
for(int i = 0;i < 10; i++)
{
if (i%5==0)
{
continue;
}
sumc += i; }
Console.WriteLine("sumc:"+sumc);




