I need help
I need to store data's inside variable for later use.
i have a file which look like this
first,second,third,fourth
first,second,third,fourth
first,second,third,fourth
first,second,third,fourth
first,second,third,fourth
now i need to store these lines with all string ,did i need to use list or array.
thanks in advance

VulpesRank #55 · 29.2K reputationPosted Sep 30, 2013, 2:59 AM EDT
VulpesRank #55 · 29.2K reputationPosted Sep 30, 2013, 12:25 AM EDT
using System.IO;
// ...
string[] lines = File.ReadAllLines("kk.txt");
krishnakumar kuna55 reputationPosted Sep 30, 2013, 12:28 AM EDT
but i need to loop and store all data that is five string values in it and looping through all lines all string should be stored.
how?
thanks in advance
VulpesRank #55 · 29.2K reputationPosted Sep 30, 2013, 12:38 AM EDT
If so, try this (off 'top of head', untested):
var lines = new List
using (var sr = new StreamReader("kk.txt"))
{
string line = null;
while((line = sr.ReadLine()) != null)
{
string[] items = line.Split(',');
if (items.Length == 5) lines.Add(line);
}
}
krishnakumar kuna55 reputationPosted Sep 30, 2013, 2:38 AM EDT
this will help
A file like this
john,1432,somedata,somedata
kumar,564,somedata,somedata
jai,34241,somedata,somedata
now from the file i need these data for each person or each line to be read and stored in a variable .so, that later from the these variable i will write the data to a database.
now i a m using array where for every loop i need to run insert statement ,but if i use in a collection i could access any line at any time.
eg:
string data
string[] line;
while(data=sr.readline(file)!=null)
{ line=data.split(,)
label1.text=line[0];
}
i access those data inside while loop itself as when the loop loops second time the data in array list get overlaped with new data,as you know better than me.but what i want is i want to access all 5 lines even after the loop is finished.
like after loop is finished
label1.text=line[1][0];(i know this is wrong because this is not a multidimensional array)
for 3rd line
label3.text=linep[3][0]
thanks again.sorry for the trouble.
krishnakumar kuna55 reputationPosted Sep 30, 2013, 3:52 AM EDT
Did i need to create class with how many variable i need to store.
could you please if it is correct
public void lineclass()
{
string name;
int number;
}
and use var lines =new list
please help i dont know about this thank you
VulpesRank #55 · 29.2K reputationPosted Sep 30, 2013, 4:23 AM EDT
To access the number property of the i'th line, you'd then use lines[i].number.
krishnakumar kuna55 reputationPosted Sep 30, 2013, 5:00 AM EDT