另一種方式 https://www.cnblogs.com/stulzq/p/9039836.html
代碼截圖:
貼一下代碼,方便復制:
//默認端口號5000 string port = "5000"; if (args.Length == 2) { if (args[0] == "-p") { string portStr = args[1]; //判斷端口號是否正確 純數字驗證 if (Regex.IsMatch(portStr, @"^\d*$")) { port = portStr; } } }
使用方法:dotnet xxx.dll -p 端口號,例:dotnet helloworld.dll -p 8080,那么就會監聽8080端口