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

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
主站蜘蛛池模板: 安徽省| 鄯善县| 客服| 英山县| 海伦市| 沧州市| 叙永县| 呼玛县| 南城县| 尉犁县| 武城县| 鸡西市| 呈贡县| 宝山区| 蒲城县| 蒙山县| 运城市| 芦山县| 柳河县| 邛崃市| 曲沃县| 剑河县| 武清区| 临沧市| 宁安市| 信阳市| 沈阳市| 柳林县| 汽车| 景宁| 石河子市| 夹江县| 东阿县| 手游| 蒲江县| 大宁县| 深水埗区| 永川市| 淮阳县| 会宁县| 图们市|