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

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
主站蜘蛛池模板: 崇左市| 武汉市| 宕昌县| 莱西市| 犍为县| 龙口市| 青龙| 英吉沙县| 东乌| 淳安县| 台南市| 蓝田县| 蓝山县| 无棣县| 潞西市| 南康市| 宽甸| 嘉荫县| 丹凤县| 永新县| 察隅县| 通许县| 宁南县| 呼玛县| 河源市| 临西县| 耒阳市| 图木舒克市| 南岸区| 沙雅县| 怀来县| 沅陵县| 德庆县| 获嘉县| 广东省| 化州市| 黄陵县| 宁明县| 彭山县| 陆河县| 怀仁县|