1.判断今天星期几
1.最简单也是最直接的是如下
string[] Day = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
string week1 = Day[Convert.ToInt32(DateTime.Now.DayOfWeek.ToString("d"))].ToString();
Console.WriteLine(week1); //输出今天周几
2.swtich
int d = (int)DateTime.Now.DayOfWeek; //(Sunday=0, Monday=1, Tuesday=2 ..) 若是星期六 才是6
string day="";
switch (d)
{
case 0:
day = "星期天";
break;
case 1:
day = "星期一";
break;
case 2:
day = "星期二";
break;
case 3:
day = "星期三";
break;
case 4:
day = "星期四";
break;
case 5:
day = "星期五";
break;
case 6:
day = "星期六";
break;
}
Console.WriteLine(day); //输出今天周几
2.MD5加密
MD5 md5 = new MD5CryptoServiceProvider();//创建MD5加密对象 byte[] bytes = Encoding.Default.GetBytes("123");//把要进行MD5加密的对象转换成字节数组 以123举例 byte[] bytess = md5.ComputeHash(bytes); string a; string b; a = BitConverter.ToString(bytess).Replace("-", ""); //将指定的字节数组的每个元素的数值转换为其等效的十六进制字符串表示形式。 b = BitConverter.ToString(bytess); Console.WriteLine(a); Console.WriteLine(b);
这个是直接一点的 MD5 md51 = new MD5CryptoServiceProvider(); byte[] result = md51.ComputeHash(System.Text.Encoding.Default.GetBytes("123")); string c= BitConverter.ToString(result); Console.WriteLine(c);
3.LastIndexOf最常用的用法,获取文件后缀名
string path= @"D:下载的软件QQBinQQScLauncher.exe"; int index = path.LastIndexOf("\"); string name = path.Substring(index+1);
Console.WriteLine(index); //获取最后一次出现位置 Console.WriteLine(name); //获取文件后缀名 Console.ReadKey();
4.去除重复值并输出
string test = "123,123,32,126,655,9565,432,6543,343,32,126,655"; string[] array = test.Split(','); List<string> list = new List<string>(); foreach (string item in array) { if (!list.Contains(item)) { list.Add(item); } } for (int i = 0; i < list.Count; i++) { Console.Write(list[i].ToString()); } Console.ReadKey();
//直接点如下
string test = "123,123,32,125,68,9565,432,6543,343,32,125,68";
string test1 = String.Join("-", test.Split(',').Distinct());
Console.WriteLine(test1);
5.打开一个进程
#region MyRegion Process p = new Process(); ProcessStartInfo info = new ProcessStartInfo(@"D:下载的软件QQBinQQScLauncher.exe"); //在ProcessStartInfo类中实例化对象,并传参为打开进程的路径 p.StartInfo = info; p.Start(); // 打开一个进程 Console.ReadKey(); #endregion
如上5个简单例子,若有不对之处或有待优化,请园友指出,谢谢。