码迷,mamicode.com
首页 > 其他好文 > 详细

3月11日 异常语句 类

时间:2016-03-11 23:54:58      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

一、异常语句 try catch finally

try ;保护执行里面的代码,若其中有一句有误,直接跳转到catch,不会管下面的内容

try

{

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

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

Comsole.WriteLine("hello");

}

catch//try中发现异常,直接执行,若try中无错则不执行

{

Console.WriteLine("输入有误!");

}

finally//无论上面有没有错都需要执行;

{

Console.WhiteLine("谢谢使用,再见");

}

Console.ReadLine();

二、类

(一)String类

string a=("    abcefg    ");
int b=a.Length;//长度
Console.WhiteLine(b);

string c=a.Trim();//去掉前后空格;
Console.WhiteLine(c);
Console.White("\n");
string d=a.TrimStart();//去掉前空格;
Console.WhiteLine(d);
Console.White("\n");
string e=a.TrimEnd();//去掉后空格;
Console.WhiteLine(e);
Console.White("\n");
string f=a.ToUpper();//全部将小写转换成大写;
Console.WhiteLine(f);
string g=a.ToLower();//全部将大写转换成小写;
Console.WhiteLine(g);
//索引号是从0开始的;
string h=a.Substring(4);//里面一个值,表示从这个索引开始一直截取到最后
Console.WhiteLine(h);//若不重新赋值,a是没有变化的
string i=a.Sunstring(4,3);//两个值,表示从哪个索引号开始,截取多少长度;
Console.WhiteLine(i);

//a=a.Replace("de","DE");//旧的替换成新的
//Console.WhiteLine(a);
string j="2012 12 23";
string [] aa=j.Split();//分割字符串
foreach(string m in aa)
{
Console.WhiteLine(m);
}

string a = "    abCdefgd8    ";
            int c = a.IndexOf("d");//从前面开始找,找到第一个,数它的索引号
            int d = a.LastIndexOf("d");
            bool b = a.Contains("dd");//是否包含此字符串
            Console.WriteLine(d);
Console.ReadLine();

(二)Math
//double a = 1.5;
            //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的情况下,取下线

 

3月11日 异常语句 类

标签:

原文地址:http://www.cnblogs.com/dongqiaozhi/p/5267531.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!