Я новичок в C# и не могу понять, как проверить в коде, который я уже написал. У меня код работает отлично, но хочу продолжать добавлять функции. Я ищу советы или все, что вы хотели бы упомянуть. Спасибо заранее. Вот код, который у меня есть до сих пор, и вам нужно пройти проверку на 3 getInputs рядом с зелеными комментариями.Проверка чисел и букв с помощью C# для новичков
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BasicUserInterface
{
class Program
{
static void DisplayApplicationInformation()
{
Console.WriteLine("Welcome to the Basic User Interface Program");
Console.WriteLine("CIS247, Week 2 Lab");
Console.WriteLine("Name: Fred Ziyad");
Console.WriteLine();
Console.WriteLine("This program accepts user input as a string, then makes the");
Console.WriteLine("approppriate data conversion and display the results.");
Console.WriteLine();
}
static void DisplayDivider(String outputTitle)
{
Console.WriteLine("************* " + outputTitle + " **************");
}
static string GetInput(string inputType)
{
string strInput;
Console.Write("Enter " + inputType + ": ");
strInput = Console.ReadLine();
return strInput;
}
static void TerminateApplication()
{
Console.WriteLine();
Console.WriteLine("Thank you for using the Basic User Interface program");
Console.Read();
}
static void Main(string[] args)
{
int age;
double mileage;
string strInput, name;
DisplayApplicationInformation();
DisplayDivider("Start Program");
Console.WriteLine();
DisplayDivider("Get Name");
name = GetInput("your name");
Console.WriteLine("Your name is " + name);
Console.WriteLine();
//Validate name to be a string of letters.
DisplayDivider("Get Age");
strInput = GetInput("your age");
age = int.Parse(strInput);
Console.WriteLine("Your age is: " + age);
Console.WriteLine();
//Validate age to be a number.
DisplayDivider("Get Mileage");
strInput = GetInput("gas mileage");
mileage = double.Parse(strInput);
Console.WriteLine("Your car MPT is: " + mileage);
//Validate mileage to be a number.
TerminateApplication();
}
}
}
Не значит TryParse? (Возможно, вы смотрите игру Бронкос). –
@SteveWellens - Я полностью наблюдаю за игрой в АФК, и думаю после 2-летнего, так что да, опечатки следует ожидать. TOUCHDOWN –
Спасибо вам большое! –