This little thing that drives me nuts..

Hi everyone,

First post, bear with me. I'm 2 months in a C# course, things are going fast, and I'm sure I missed something somewhere, anyways, here my problem:

Part of the exercise needs to find an existing person based on a reference (the kl string) inside a text file. I created this method:

static void SearchClient(string kl) {

 using (StreamReader sr = new StreamReader(@"C:\temp\myfile.txt")) { while (sr.Peek() != -1) { if (kl == (sr.ReadLine())) { Console.WriteLine("found person"); Console.WriteLine(sr.ReadLine()); } } } } 

Basically, if it finds the person, it writes the next line, which is the person's name.

Now my questions:

  • How can I use the person's name outside of this method?

  • I found this the easiest way to get the person's name from the next line, should I rather use something else?

thanks a lot

by SharpenMyC via /r/csharp

Leave a Reply