《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,有一些静态方法用来处理字符,比如ToLowerToUpperIsWhiteSpace方法

ToLowerToUpper取决于用户的本地化,所以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的环境变量:GetEnvironmentVariableGetEnvironmentVariablesSetEnvironmentVariable

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的名字和版本
posted @ 2022-07-02 21:55  huang1993  阅读(40)  评论(0)    收藏  举报