Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

redirect textreader 1

Status
Not open for further replies.

ajikoe

Programmer
Apr 16, 2004
71
ID
I use textreader to open a file and I want to use the same textreader read another file, How can I solve this problem?

StringBuilder sb = new StringBuilder();
TextReader tr = new StreamReader(FileNameA);
string sLN="";

sLN = tr.ReadLine();
while(sLN != null){
//Do something
sLN = tr.ReadLine();
}

tr.Close();

// here I want to redirect tr
TextReader tr = new StreamReader(FileNameB); // ERROR

Sincerely Yours,
Pujo

 
You already defined the tr object, there for you only need to reasign the variable not to redeclare
Code:
void MyFunction()
{
//first initialization
TextReader tr = new StreamReader(FileNameA); 

//second initialization
tr.Close();
tr = new StreamReader(FileNameB); 
//...

//nth initialization
tr.Close();
tr = new StreamReader(FileNameN); 

}

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Thank you Shaddow, it is working....

Pujo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top