Good day. I create a console application that, when a variable changes, should save data to a new file. Constructor class:

StreamReader sr = new StreamReader(@"D:\New\1.txt"); 

Question : How to implement variable transfer to incoming parameters? As I see a solution that does not fit:

  StreamReader sr = new StreamReader(@"D:\New\{0}.txt", count); // Error 

Thanks for the answer.

  • Where did the question mark c # -faq come from? If such questions really were asked often - you would have found the answer without asking a question ... - Pavel Mayorov
  • @PavelMayorov discussion of the built-in library isn't it a faq? - Rifter
  • Not. FAQs are frequently asked questions. Your question is not frequent. - Pavel Mayorov

1 answer 1

For example:

 StreamReader sr = new StreamReader(string.Format(@"D\New\{0}.txt", count)); 

Or so:

 StreamReader sr = new StreamReader($@"D\New\{count}.txt"); 

And you seem to have lost a colon along the way.

  • Thank you, it came - Rifter
  • @Rifter: Please! - VladD