אוקיי תודה רבה, כרגע הבעיה שלי היא שבכל איטרציה של המתודה היא תמיד תגיע בסוף ותחזיר -9999 וככה היא תצא ובעצם לא תסיים לקרוא את כל הקובץ ואני לא מצליח לתקן את זה
[/code]
קוד: בחירת הכל
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;
namespace T380
{
public class BabyStreamReader : StreamReader
{
public BabyStreamReader(string path)
: base(path)
{
}
public int ReadNextInt()
{
int INum = 0;
string StNum = "";
ArrayList Numbers = new ArrayList();
BabyStreamReader InputFile = new BabyStreamReader("TextFile.txt");
char character = (char)InputFile.Read();
if (character >= '0' && character <= '9')
{
StNum += character;
}
else
{
INum = int.Parse(StNum);
StNum = "";
Numbers.Add(INum);
foreach (int i in Numbers)
{
return i;
}
}
return -9999;
}
}
class Program
{
static void Main(string[] args)
{
BabyStreamReader InputFile = new BabyStreamReader("TextFile.txt");
while (!InputFile.EndOfStream)
{
int result = InputFile.ReadNextInt();
Console.WriteLine(result);
}
Console.ReadLine();
}
}
}
אגב, במתודה יכול להיות שהשורה BabyStreamReader InputFile = new BabyStreamReader("TextFile.txt");
מיותרת ובמקום char Character = (char)InputFile.Read(); הייתי צריך לרשום This.Read ?