《c#10 in a nutshell》--- 读书随记(5)
Chaptor 6. .NET Fundamentals
内容来自书籍《C# 10 in a Nutshell》
Author:Joseph Albahari
需要该电子书的小伙伴,可以留下邮箱,有空看到就会发送的
String and Text Handling
Char
命名空间是System.Char,有一些静态方法用来处理字符,比如ToLower、ToUpper和IsWhiteSpace方法
ToLower和ToUpper取决于用户的本地化,所以char.ToUpper ('i') == 'I',不一定是true
可以用使用char.ToUpperInvariant ('i'),确保转换的是英文
Utility Classes
Environment
System.Environment提供了几种有用的属性:
- Files and folders
- CurrentDirectory, SystemDirectory, CommandLine
- Computer and operating system
- MachineName, ProcessorCount, OSVersion, NewLine
- User logon
- UserName, UserInteractive, UserDomainName
- Diagnostics
- TickCount, StackTrace, WorkingSet, Version
访问OS的环境变量:GetEnvironmentVariable,GetEnvironmentVariables、SetEnvironmentVariable
Process
在System.Diagnostics,允许我们开启一个新的进程
Process.Start ("notepad.exe");
Process.Start ("notepad.exe", "e:\\file.txt");
ProcessStartInfo psi = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = "/c ipconfig /all",
RedirectStandardOutput = true,
UseShellExecute = false
};
Process p = Process.Start (psi);
string result = p.StandardOutput.ReadToEnd();
Console.WriteLine (result);
AppContext
在System.AppContext命名空间
BaseDirectory,返回程序启动的所在文件夹,可以用来定位配置文件TargetFrameworkName,返回runtime的名字和版本

浙公网安备 33010602011771号