官术网_书友最值得收藏!

The Program class

Those of you who have created console applications should be familiar with the Program class and the Main method within. We will follow this structure for other console-based applications throughout the remainder of the book. The following code block contains the program class from which the application will begin execution:

using System;

using chapter02.ML;

namespace chapter02
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine($"Invalid arguments passed in, exiting.{Environment.NewLine}" + $"{Environment.NewLine}Usage: {Environment.NewLine}" +
$"predict <sentence of text to predict against>{Environment.NewLine}" +
$"or {Environment.NewLine}" +
$"train <path to training data file>{Environment.NewLine}");

return;
}

switch (args[0])
{
case "predict":
new Predictor().Predict(args[1]);
break;
case "train":
new Trainer().Train(args[1]);
break;
default:
Console.WriteLine($"{args[0]} is an invalid option");
break;
}
}
}
}

This constitutes a fairly straightforward method implementation for those familiar with parsing command-line arguments. A simple two-argument approach is used as the help text indicates.

When executing a more complex command-line application that takes in several arguments (optional and required), Microsoft has provided a simple-to-use NuGet package, which is available here:  https://github.com/dotnet/command-line-api
主站蜘蛛池模板: 共和县| 东丽区| 扶绥县| 正镶白旗| 遵化市| 保靖县| 扎囊县| 洮南市| 定安县| 鄯善县| 方山县| 卢湾区| 天全县| 丘北县| 宝鸡市| 米林县| 扎赉特旗| 河西区| 马公市| 兴仁县| 隆子县| 兴义市| 恩施市| 吉安市| 图木舒克市| 石嘴山市| 怀集县| 滨州市| 抚顺县| 绥阳县| 德安县| 辽阳县| 宣城市| 罗江县| 金坛市| 武冈市| 获嘉县| 高平市| 石首市| 敦煌市| 调兵山市|