[英]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.