Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C# filling up record list from text file

cferenc

New Coder
I try to fill up a record list that works in a previous code but it don't in the current one. what is strange the loop while doesn't look running at all, so filing up record list from text file posted also doesn't happen. also it is a problem the beginning of the text file. it starts with a code. I try to get it also but running the code noting happens, noting is running. no error msg Please have a look and help me as it is possible.
the code:

[CODE lang="csharp" title="hotelorder1"] string olvas = @"c:\Users\Public\textfiles\pitypang.txt";
List<pitypang00> adatok = new List<pitypang00>();
int i = 0;
int i2 = 0;
int kod0 = 0;
int utolso = 0;
try
{

// Open the text file using a stream reader.
using (var sr = new StreamReader(olvas, Encoding.Default))
{
// Read the stream as a string, and write the string to the console.
//Console.WriteLine(sr.ReadToEnd());
while (!sr.EndOfStream)
{

string sor = sr.ReadLine();
string[] record = sor.Split(' ');

adatok.Add(new pitypang00());
if (i == 0) { kod0 = Convert.ToInt32(record[0]); }
else
{
adatok.foglaloszam = Convert.ToInt32(record[1]);
adatok.szobaszam = Convert.ToInt32(record[2]);
adatok.erkezesinapsorszama = Convert.ToInt32(record[3]);
adatok.tavozasinapsorszam = Convert.ToInt32(record[4]);
adatok.vendegszam = Convert.ToInt32(record[5]);
adatok.kernekreggelit = Convert.ToInt32(record[6]);
adatok.vendegazonosito = record[7];
utolso++;
Console.WriteLine(i+" "+ record[7]);
i++;
}
}
sr.Close();

for (i2 = 1; i2 <= utolso; i2++){
Console.WriteLine(
" Foglaloszam "+ adatok.foglaloszam+
" Szobaszam "+ adatok.szobaszam+
" Erkezesinap\n sorszama "+ adatok.erkezesinapsorszama);
}[/CODE]
 

Attachments

  • pitypang.txt
    31.8 KB · Views: 0
I try to fill up a record list that works in a previous code but it don't in the current one. what is strange the loop while doesn't look running at all, so filing up record list from text file posted also doesn't happen. also it is a problem the beginning of the text file. it starts with a code. I try to get it also but running the code noting happens, noting is running. no error msg Please have a look and help me as it is possible.
the code:

[CODE lang="csharp" title="hotelorder1"] string olvas = @"c:\Users\Public\textfiles\pitypang.txt";
List<pitypang00> adatok = new List<pitypang00>();
int i = 0;
int i2 = 0;
int kod0 = 0;
int utolso = 0;
try
{

// Open the text file using a stream reader.
using (var sr = new StreamReader(olvas, Encoding.Default))
{
// Read the stream as a string, and write the string to the console.
//Console.WriteLine(sr.ReadToEnd());
while (!sr.EndOfStream)
{

string sor = sr.ReadLine();
string[] record = sor.Split(' ');

adatok.Add(new pitypang00());
if (i == 0) { kod0 = Convert.ToInt32(record[0]); }
else
{
adatok.foglaloszam = Convert.ToInt32(record[1]);
adatok.szobaszam = Convert.ToInt32(record[2]);
adatok.erkezesinapsorszama = Convert.ToInt32(record[3]);
adatok.tavozasinapsorszam = Convert.ToInt32(record[4]);
adatok.vendegszam = Convert.ToInt32(record[5]);
adatok.kernekreggelit = Convert.ToInt32(record[6]);
adatok.vendegazonosito = record[7];
utolso++;
Console.WriteLine(i+" "+ record[7]);
i++;
}
}
sr.Close();

for (i2 = 1; i2 <= utolso; i2++){
Console.WriteLine(
" Foglaloszam "+ adatok.foglaloszam+
" Szobaszam "+ adatok.szobaszam+
" Erkezesinap\n sorszama "+ adatok.erkezesinapsorszama);
}[/CODE]

What you can do is read all the text into an array, and then passing the array as a parameter in the the list creation.

string[] data = File.ReadAllLines(path);
List<string>dataList = new List<string>(data);
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom