私は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();
}
}
}
? (たぶんあなたはブロンコスの遊びを見ているでしょう)。 –
@SteveWellens - 私は完全にAFCの試合を見ているし、2歳の後に気を配っているので、誤字が予想される。-TOUCHDOWN –
ありがとう。 –