[英]How to create dynamic multilingual web application using Asp.net 3.5 and c# 3.0
[英]How to create Web Application using C# and ASP.NET Core using macOS X
我是 C# 和 ASP.NET Core 的初學者,我的任務是創建 Web 應用程序。 這個應用程序的主要任務是基本的:我需要創建一個表單(用戶可以寫東西的行)並顯示書面內容。 當用戶不輸入數字時,它也必須處理異常(FormatException)
我開發的控制台應用程序的代碼片段,現在我需要借助 C# 和 ASP.NET 核心框架將其轉換為 Web 應用程序。
這里是 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);
}
}
}
現在我需要將其轉換為帶有輸入行的 Web 應用程序,如果它不是 10、49 等數值,則在特殊的 window 中顯示異常。我在 macOS X 上寫這個,所以不要給Windows的建議:)
希望有人能幫助我完成這項任務。 謝謝:):):)
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.