类的运用

try (捕捉错误) {    要执行的代码 } catch (Exception) {    错误(异常)处理代码 } finally {    最终要执行的代码 }

String类

string str = "asd";

str.Length:字符串的长度   ***** str[索引号]

str.Trim():去除左右两边的空格 ***** str.TrimStart():去掉左边的空格 str.TrimEnd():去掉右边的空格

str.ToLower():大写转小写 str.ToUpper():小写转大写

str.StartsWith():匹配开头 str.EndsWith():匹配结尾 str.Contains():匹配整个字符串 ******

str.IndexOf():某字符串在str里面哪个位置出现(第一次出现的位置) str.LastIndexOf():某字符串在str里面最后一次出现的位置

str.Substring():截取字符串 ******

str.Replace(替换掉括号里面的字符串)

Math类:

Math.Round(n,0); 四舍五入(小数与小数的第几位保留) Math.Ceiling(n);取大于该小数的最小整数 Math.Floor(n);取小于该小数的最大整数 Math.Sqrt(a);开平方,平方根 Math.Pow(2,4); 求2的4次方

DateTime类

int a = d.Year;年 int b = d.Month;月 int c = d.Day;天 int e = d.Hour;小时 int f = d.Minute;分钟 int g = d.Second;秒 int h = d.Millisecond; int k = d.DayOfYear;今年的第几天

DayOfWeek l = d.DayOfWeek;周几

System.TimeSpan da = new TimeSpan(1,0,0,0); d = d.Add(da);加了一天

AddYears()-----AddSeconds();添加时间

ToString("yyyy年MM月dd日 hh时mm分ss秒")

原文地址:https://www.cnblogs.com/hansonglin/p/4626487.html