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

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
主站蜘蛛池模板: 调兵山市| 东乌珠穆沁旗| 保康县| 方城县| 灵武市| 陈巴尔虎旗| 乐安县| 普格县| 民丰县| 吉水县| 高唐县| 曲阜市| 炉霍县| 垫江县| 习水县| 许昌县| 沙田区| 遵义市| 沙坪坝区| 南宁市| 沾益县| 张家港市| 濮阳市| 金乡县| 临汾市| 翼城县| 六盘水市| 邛崃市| 赞皇县| 随州市| 湟源县| 大埔县| 广平县| 云梦县| 博客| 北流市| 新平| 德清县| 阳西县| 湄潭县| 子洲县|