파일에서 숫자를 함수에서 전달 된 숫자와 비교하는 방법을 알지 못합니다. 나는 파일이 얼마나 아무 생각이추측 게임 및 번호 비교
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Guess_Game
{
class Program
{
static void Main(string[] args)
{
int quantity;
int min, max;
Console.WriteLine("Enter the Quantity of Numbers : ");
quantity = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Maximum and Minimum Number that you wish to be in your file : \n");
Console.WriteLine("MIN : ");
min = int.Parse(Console.ReadLine());
Console.WriteLine("MAX : ");
max = int.Parse(Console.ReadLine());
Console.WriteLine("Now, Guess the Number : ");
int number = int.Parse(Console.ReadLine());
Console.WriteLine("Now Guess a Number That already contains in a File : ");
number = int.Parse(Console.ReadLine());
GuessGame(min, max, quantity, number);
//if(number!= // number not equal to that number that contains in a file.. how to write it in that
//if condition..
}
static void GuessGame(int min,int max,int quantity,int number)
{
Random r = new Random();
StreamWriter sw = new StreamWriter(@"D:\nasir\Guess Game\Guess Game\bin\Debug\ Guess Game.txt");
for (int i = 0; i < quantity; i++)
{
int temp = r.Next(min, max);
sw.WriteLine(temp);
}
// while(number != sw.WriteLine())
{
Console.WriteLine("Your Guess is Wrong!");
}
sw.Close();
}
}
}
분 = INT를 즐길 향상 선물로 compareson
을 : 당신이 당신의 추측이 파일 리더를 추가 입력 한 후 그렇게 fristly 연결을 닫습니다 .Parse (Console.ReadLine()); 내가 "A"를 입력하면 폭발합니다 :) - 항상 tryparse를 사용하고, 사용자를 믿지 마십시오! – balexandre
differnce B/W 구문 분석을 이해하고 구문 분석을 시도하지 않습니다. 파스는 모든 숫자를 변환 할 수있는 숫자를 변환합니다 ..하지만 구문 분석을 시도합니까 .. u는 plx를 설명 할 수 있습니까? – Abid
TryParse 메서드를 사용하여 문자열을 int로 안전하게 구문 분석 할 수 있습니다.나는 그것이 예외를 던지지는 않는다는 것을 의미하지만 성공하고 값이 out 매개 변수로 반환되면 부울을 반환합니다. 문자열 값이 정수가 아니어도 프로그램이 계속 작동 할 수 있지만 허용되지 않는 경우 Parse를 사용하는 것이 좋습니다. – Beatles1692