选择项目->右键->属性->调试->命令行参数(命令行参数调试配置.png)
namespace CsharpStudy
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("循环调用命令行参数");
foreach (string arg in args)
{
Console.WriteLine("Arg:{0}", arg);
}
ShowEnvironmentDetails();
Console.ReadLine();
}
private static void ShowEnvironmentDetails()
{
string[] theArgs = Environment.GetCommandLineArgs();
Console.WriteLine();
Console.WriteLine("使用System.Environment.GetCommandLineArgs()读取的命令行参数");
//字体颜色变化
ConsoleColor prevColor = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("注意:第一行返回的是应用程序本身的名称!");
//恢复颜色
Console.ForegroundColor = prevColor;
foreach (string arg in theArgs)
{
Console.WriteLine("Arg:{0}", arg);
}
Console.WriteLine();
Console.WriteLine("使用System.Environment.GetLogicalDrives()读取本机的驱动器");
foreach (string drive in Environment.GetLogicalDrives())
{
Console.WriteLine("Drive:{0}", drive);
}
Console.WriteLine();
Console.WriteLine("System.Environment的其他成员");
Console.WriteLine("OS:{0}", Environment.OSVersion);
Console.WriteLine("Number of processors:{0}", Environment.ProcessorCount);
Console.WriteLine(".NET Version:{0}", Environment.Version);
Console.WriteLine("IS 64bit Operation System:{0}", Environment.Is64BitOperatingSystem);
Console.WriteLine("MachineName:{0}", Environment.MachineName);
Console.WriteLine("UserName:{0}", Environment.UserName);
Console.WriteLine("SystemDirectory:{0}", Environment.SystemDirectory);
Console.WriteLine("CurrentDirectory:{0}", Environment.CurrentDirectory);
}
}
}
输出返回(输出返回.png)