C#开发可以用Blazor在今后写前端渲染的网页了!C#是微软公司发布的一种面向对象的、运行于.NET Framework和.NET Core(完全开源,跨平台)之上的高级程序设计语言。我觉得起因是因为浏览器支持WebAssembly,WebAssembly是一种新的编码方式,可以在现代的网络浏览器中运行二进制格式文件,以接近原生的性能运行。Blazor 尝试使用WebAssembly和DotNetAnywhere将.NET带回到浏览器。除了用C#来开发之外,还可以让C#运行在浏览器(使用WebAssembly)上,这样dotnet的众多api我们都可以在浏览器使用了。https://docs.microsoft.com/zh-cn/aspnet/core/blazor/get-started?view=aspnetcore-3.1&tabs=visual-studiohttps://docs.microsoft.com/zh-cn/aspnet/core/blazor/get-started?view=aspnetcore-3.1&tabs=visual-studio 按照官网指示,先安装 .NET Core 3.1 SDK。我使用的是mac环境,直接下载dotnet的pkg安装包安装。安装之后在终端输入,安装Blazor的模板:dotnet new -i Microsoft.AspNetCore.Components.WebAssembly.Templates::3.2.0-preview2.20160.5 我使用的是 Visual Studio Code,安装C#插件dotnet new blazorwasm -o WebApplicationMix 用Visual Studio Code打开。终端输入:浏览器打开https://localhost:5001/,初次体验Blazor我比较看重还是Blazor可以调用dotnet提供的一个机器学习库。BlazorML5,为Blazor提供了ML.NET的功能。- ML.NET情绪分析、产品推荐、价格预测、物体检测、图像分类等等。微软的api梳理得更为接近应用场景。代码风格也比较简洁://Step 1. Create a ML Context var ctx = new MLContext();
//Step 2. Read in the input data for model training IDataView dataReader = ctx.Data .LoadFromTextFile<MyInput>(dataPath, hasHeader: true);
//Step 3. Build your estimator IEstimator<ITransformer> est = ctx.Transforms.Text .FeaturizeText("Features", nameof(SentimentIssue.Text)) .Append(ctx.BinaryClassification.Trainers .LbfgsLogisticRegression("Label", "Features"));
//Step 4. Train your Model ITransformer trainedModel = est.Fit(dataReader);
//Step 5. Make predictions using your model var predictionEngine = ctx.Model .CreatePredictionEngine<MyInput, MyOutput>(trainedModel);
var sampleStatement = new MyInput { Text = "This is a horrible movie" };
var prediction = predictionEngine.Predict(sampleStatement);
|