常用的C#类

(一)数学类:Math
1.Math.Ceiling(小数/整数):返回大于当前小数的最小整数
2.Math.Floor(小数/整数):返回小于当前小数的最大整数
Console.WriteLine(Math.Ceiling(3.14));  //4
Console.WriteLine(Math.Floor(3.14));   //3
Console.WriteLine(Math.Ceiling(3.0));   //3
 
3.Math.Pow(2,3)求指数。相当于2的3次方
4.Math.Sqrt(16)开平方。
5.四舍五入。
    Math.Round(3.63); //4 
    Math.Round(3.14);   //3
 
(二)日期时间:DateTime
构造:DateTime dt = new DateTime();
当前时间:
DateTime dt = DateTime.Now;
 
日期时间对象的数据:
Year,Month,Day,Hour,Minite,Second,MilliSecond
DayOfWeek——星期几。DayOfYear——一年中的第几天。
Date——取期日期部份。TimeOfDay——取期时间部份。
日期时间对象的函数:
AddYears(int num)
AddMonths(int num)
AddDays(int num)
AddHours(int num)
AddMinutes(int num)
AddSeconds(int num)
日期时间型数据可以直接相减,返回两个日期之间差的天数和时间。
(三)字符串
*Length:字符串的长度。
 
ToLower():全都转成小写
ToUpper():全都转成大写
 
TrimStart():
TrimEnd():
Trim():压两头的空格。
 
*IndexOf("子串"):(int)返回子串在字符串中第一次出现的位置。
*LastIndexOf("子串"):(int)返回子串在字符串中最后一次出现的位置。
以上两函数,如果在字符串中找不到相应的子串,返回-1
 
*Substring(int start[,int length]):(string)截取子串。
Replace(string old,string new):(string)把字符串的old串换成new串
二百个不间断的重复,只是让我看到了人的命运无法改变这一事实而已。
原文地址:https://www.cnblogs.com/dlexia/p/4439162.html