简体   繁体   English

如何使用 C# 创建 Web 应用程序,使用 macOS X 创建 ASP.NET 核心

[英]How to create Web Application using C# and ASP.NET Core using macOS X

I'm the beginner in C# and in ASP.NET Core and I have a task to create Web Application.我是 C# 和 ASP.NET Core 的初学者,我的任务是创建 Web 应用程序。 The main task of this app is basic: I need to create a form(line where user can write something) and display written content.这个应用程序的主要任务是基本的:我需要创建一个表单(用户可以写东西的行)并显示书面内容。 Also it mush handle exceptions(FormatException) when user doesn't input a number当用户不输入数字时,它也必须处理异常(FormatException)

Code snippet for Console Application I have developed and now I need to transform it into Web Application with the help of C# and ASP.NET Core framework.我开发的控制台应用程序的代码片段,现在我需要借助 C# 和 ASP.NET 核心框架将其转换为 Web 应用程序。

Here the code template of C# Console Application:这里是 C# 控制台应用程序的代码模板:

using System;
namespace Input_Output
{
   class MainClass
   {
     public static void Main(string[] args)
     {
        int number;
        try 
        {
           Console.WriteLine("Enter a number: ");
           number = Convert.ToInt32(Console.ReadLine());
           Console.WriteLine($"You've entered {number}");
        }
        catch(FormatException)
        {
          Console.WriteLine("It is not a number!!!");
        }
        Console.ReadKey(true);
     }
   }
}

And now I need to transform it into the Web Application with the line for input and if it is not a numeric value like 10, 49, etc than display exception in the special window. I am writing this on macOS X, so don't give pieces of advice for Windows:)现在我需要将其转换为带有输入行的 Web 应用程序,如果它不是 10、49 等数值,则在特殊的 window 中显示异常。我在 macOS X 上写这个,所以不要给Windows的建议:)

Hope someone could help me with this task.希望有人能帮助我完成这项任务。 Thank you:):):)谢谢:):):)

    int number;
    try 
    {
       Console.WriteLine("Enter a number: ");
       var enteredNumber = Console.ReadLine();
       var isNumeric = int.TryParse(enteredNumber, out int n);
       if(isNumeric)
       {
         number = Convert.ToInt32(enteredNumber);
         Console.WriteLine($"You've entered {number} succesfully");
       }
       else
       {
         Console.WriteLine("It is not a number!!!");
       }
    }
    catch(Exception ex)
    {
      Console.WriteLine("An issue occured with your number entry: " + ex.message);
    }
    Console.ReadKey(true);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Asp.net 3.5和C#3.0创建动态多语言Web应用程序 - How to create dynamic multilingual web application using Asp.net 3.5 and c# 3.0 如何在Asp.NET Core WEB API中使用.Net(C#)在有效载荷中使用自定义JSON声明创建JWT令牌 - How to create a JWT token with custom JSON claims in Payload using .Net (C#) in Asp.NET Core WEB API 将XPath与ASP.NET C#Web应用程序一起使用 - Using XPath with ASP.NET C# Web Application 使用C#和asp.net的Web应用程序中的进度栏 - Progress bar in web application using C# and asp.net 使用c#在asp.net中动态创建网页 - Dynamically create web page in asp.net using c# 如何使用C#.net为Windows应用程序和使用C#ASP.NET的Web应用程序生成Excel文件 - how to generate excel file for a windows application using C# .net and a web application using C# ASP.NET 使用 C# function 不断更新 x 轴和 y 轴以更新 ASP.NET 核心 Web 应用程序 Razor 页中的 Chart.js 图表 - Constant updating of x- and y-axis using a C# function to update a Chart.js chart in ASP.NET core Web Application Razor Pages 使用 C# HttpClient,如何将字符串 HttpContent POST 到 ASP.net Core Web API? - Using C# HttpClient, how to POST a string HttpContent to ASP.net Core web API? 如何使用 MongoDB 将动态 JSON 属性发布到 C# ASP.Net Core Web API? - How to post a dynamic JSON property to a C# ASP.Net Core Web API using MongoDB? 如何使用 ZD7EFA19FBE7D3972FD5ADB6024Z2 在 ASP.NET Core 6 Web API 中运行存储过程? - How run stored procedure in ASP.NET Core 6 Web API using C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM