string类型:

string a="abcdefg";

int b=a.Length;//属性 长度 计算字符串的长度;

Console.ReadLine(b);

string c=a.Trim();//去掉前后空格;

Console.ReadLine(c);

string d=a.TrimEnd();//去掉后空格

Console.ReadLine(d);

string e=a.TrimStart();//去掉前空格

Console.ReadLine(e);

string f=a.ToUpper();//将全部小写字母变成大写

string g=a.ToLower();//将全部大写字母变成小写

string h=a.Substring(4);//里面的数,表示从这个索引开始一直截取到最后

Console.WriteLine(a.substring(8));

a=a.Substring(8);//如果不赋值,a是不变的

string i=a.Substring(4,3);//俩个值,表示从哪个索引号开始,截取多少长度

a=a.rReplace("de" ,"DE");//指定的字符串 被指定的字符串替换

string j="'2012 12 23"'

string【】aa=j.Split(); //分割字符串 以什么字符

bool w=a.Contains("d");//是否包含此字符串,返回true或者false

int c=a,IndexOf("d")//返回第一次出现字符串的索引

int d=a.IndexOf("d")//返回最后一次出现字符串的索引

Math类:

double a=4.14;

Console.WriteLine(Math.Ceiling(a));//去上线

Console.Writeline(Math.Floor(a));//去下线

Console.WriteLine(Math.PI*a);//圆周率

Console.WriteLine(Math.Sqrt(a));//开平方

Console.WriteLine(Math.Round(a));//四舍五入,奇数.5的情况下,取上线 偶数.5情况下 去下线

练习:百鸡百钱 公鸡2文钱一只;母鸡1文;小鸡半文;共100文钱,如何在凑够100只鸡的情况下花完100文?

int g;m;x;

for(int g=0;g<=50;g++)//公鸡情况

{

for(int m=0;m<=100;m++)//母鸡情况

{

for(int x=0;x<=200;x++)//小鸡情况

{

if(g+m+x==100&&2g+m+0.5x=100)//满足条件

Console.Wrinte(g,m,x);

}

}

}

}

异常语句 try catch finally   

try//保护执行里面的代码,若其中有错,直接跳到catch 不管下面内容

{

Console.Write("输入一个整数");

int a=int.Parse(Console.ReadLine());

Console.ReadLine("a');

}

catch//try中发现异常 直接执行,否则不执行

{

console.write("输入有误");

}

finally//都要执行

{

console.write("谢谢使用再见");不管上面对错。

}

原文地址:https://www.cnblogs.com/kevin2016/p/5267668.html