Click here to Skip to main content
15,899,313 members
Home / Discussions / C#
   

C#

 
QuestionQuick C# Help Retrieve data using while (!sr.EndOfStream) Pin
d87c22-Sep-10 17:35
d87c22-Sep-10 17:35 
I ran into problem for my school assignment and it is to display whatever in a meal.csv file, here is a code we are starting with. The array string of itemDetails is where the data is store then passed into array ReadLines, then in Main, it is passed to mealContent, but when I tried Console.WriteLine(mealContent); it only prompted System.String[]. So how do I at least display it out in the command prompt. Thanks for the help guys~ Source code is also attached

Code/meal.csv
lunch,bento box b - sashimi,box combo,$9.59
dinner,vegetable sushi,6 rolls,$3.50
dinner,tuna roll,3 rolls,$4.50
dinner,roe, 2 rolls,$3.95
lunch,bento box a - chicken teriyaki,box combo,$8.59

lunch,bento box b - sashimi,box combo,$9.59 dinner,vegetable sushi,6 rolls,$3.50 dinner,tuna roll,3 rolls,$4.50 dinner,roe, 2 rolls,$3.95 lunch,bento box a - chicken teriyaki,box combo,$8.59
FileIOManager/FileLocation.cs

using System;

namespace FileIOManager
{
static class FileLocation
{
public const string INPUT_FILE = "../../Data/meals.csv";
}
}

using System; namespace FileIOManager { static class FileLocation { public const string INPUT_FILE = "../../Data/meals.csv"; } }
FileIOManager/FileReader.cs

using System;
using System.IO;

namespace FileIOManager
{
static public class FileReader
{
private static int GetLineCount()
{
StreamReader sr = new StreamReader(FileLocation.INPUT_FILE);
int counter = 0;
while (!sr.EndOfStream)
{
counter++;
sr.ReadLine();
}
sr.Close();
return counter;
}


public static string[] ReadLines()

{

int totalItems = GetLineCount();

string[] itemDetails = new string[totalItems];

StreamReader sr = new StreamReader(FileLocation.INPUT_FILE);



string itemDetail;

int counter = 0;



while (!sr.EndOfStream){

itemDetail = sr.ReadLine();

if (itemDetail.Trim() != "")

itemDetails[counter++] = itemDetail;

}

sr.Close();

return itemDetails;

}

}
} Cry | :((
AnswerRe: Quick C# Help Retrieve data using while (!sr.EndOfStream) Pin
AspDotNetDev22-Sep-10 18:58
protectorAspDotNetDev22-Sep-10 18:58 
GeneralRe: Quick C# Help Retrieve data using while (!sr.EndOfStream) Pin
d87c22-Sep-10 19:05
d87c22-Sep-10 19:05 
GeneralRe: Quick C# Help Retrieve data using while (!sr.EndOfStream) Pin
AspDotNetDev22-Sep-10 19:17
protectorAspDotNetDev22-Sep-10 19:17 
QuestionRetrieve array items to use in NUnit Test Pin
mtn*rain22-Sep-10 15:01
mtn*rain22-Sep-10 15:01 
AnswerRe: Retrieve array items to use in NUnit Test Pin
Luc Pattyn22-Sep-10 15:37
sitebuilderLuc Pattyn22-Sep-10 15:37 
GeneralRe: Retrieve array items to use in NUnit Test Pin
mtn*rain22-Sep-10 15:39
mtn*rain22-Sep-10 15:39 
AnswerRe: Retrieve array items to use in NUnit Test Pin
Luc Pattyn22-Sep-10 15:44
sitebuilderLuc Pattyn22-Sep-10 15:44 
GeneralRe: Retrieve array items to use in NUnit Test Pin
mtn*rain22-Sep-10 15:48
mtn*rain22-Sep-10 15:48 
GeneralRe: Retrieve array items to use in NUnit Test Pin
Luc Pattyn22-Sep-10 15:59
sitebuilderLuc Pattyn22-Sep-10 15:59 
GeneralRe: Retrieve array items to use in NUnit Test Pin
mtn*rain22-Sep-10 16:02
mtn*rain22-Sep-10 16:02 
AnswerRe: Retrieve array items to use in NUnit Test Pin
AspDotNetDev22-Sep-10 16:07
protectorAspDotNetDev22-Sep-10 16:07 
GeneralRe: Retrieve array items to use in NUnit Test Pin
mtn*rain22-Sep-10 16:12
mtn*rain22-Sep-10 16:12 
GeneralRe: Retrieve array items to use in NUnit Test Pin
Paul Michalik22-Sep-10 20:47
Paul Michalik22-Sep-10 20:47 
Question3 way byte merge Pin
jkohler22-Sep-10 4:01
jkohler22-Sep-10 4:01 
AnswerRe: 3 way byte merge Pin
OriginalGriff22-Sep-10 4:19
mveOriginalGriff22-Sep-10 4:19 
GeneralRe: 3 way byte merge Pin
jkohler22-Sep-10 4:28
jkohler22-Sep-10 4:28 
AnswerRe: 3 way byte merge Pin
Ennis Ray Lynch, Jr.22-Sep-10 5:07
Ennis Ray Lynch, Jr.22-Sep-10 5:07 
GeneralRe: 3 way byte merge Pin
jkohler22-Sep-10 5:15
jkohler22-Sep-10 5:15 
GeneralRe: 3 way byte merge Pin
harold aptroot22-Sep-10 5:40
harold aptroot22-Sep-10 5:40 
GeneralRe: 3 way byte merge Pin
jkohler22-Sep-10 6:00
jkohler22-Sep-10 6:00 
GeneralRe: 3 way byte merge Pin
harold aptroot22-Sep-10 6:11
harold aptroot22-Sep-10 6:11 
AnswerRe: 3 way byte merge Pin
Chris Trelawny-Ross22-Sep-10 9:19
Chris Trelawny-Ross22-Sep-10 9:19 
GeneralRe: 3 way byte merge Pin
jkohler22-Sep-10 9:35
jkohler22-Sep-10 9:35 
GeneralRe: 3 way byte merge Pin
Michael B. Hansen23-Sep-10 2:27
Michael B. Hansen23-Sep-10 2:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.