0

I am making a pay roll app for a class project, I have most of it under control but I am stuck on trying to search my text file, (using stream writer/reader) I need to Develop Method to search the personal list details for Employment ID (eg 101) and individual pay rate (e.g. $20 per hour) however I am stuck on just looking up employment ID. I will post my code not sure If I should post it all, or just where the error is, I will start with where the error is. the error I am having seems to be with the private List<string>string SearchbyName; ( with the error:

'PayRoll.SearchbyName(string, List)': not all code paths return a value

Sorry if this is not correct way to do this but any help would be great as this project is due end of the week and I cant progress anymore till I fix this thank you. (this is a windows form app)

 private List<string> SearchbyName(string term, List<string> PeopleList)
    {
        List<string> results = new List<string>();

        for (int i = 0; i < PeopleList.Count; i++)
        {
            if (PeopleList[i].Contains(term))
            {
                results.Add(PeopleList[i]);
            }
        }
        if (results.Count == 0)
        {
            results.Add(term + "not Found");
        }
    }
kealist
  • 1,669
  • 12
  • 26
Tandinos
  • 9
  • 1
  • A few notes about questions on Stack Overflow (at least to get better help and more upvotes), Next time when you write the question, you can try to focus more on the error message. While your program is using winforms, actually your question isn't related to winforms, so you should try removing the tag and the code for the extra click function. As you use SO more you'll learn to edit how & how to ask more specific questions. Enough lecture, Welcome! – kealist Oct 17 '17 at 02:20
  • Noted thank you do I close this thread or keep it open – Tandinos Oct 17 '17 at 02:22
  • You can accept an answer if you wish. I generally don't recommend deleting a question. Otherwise, just leave it. – kealist Oct 17 '17 at 02:26

1 Answers1

0

If you read the error more carefully, it is stating that you are not returning a value. The function is supposed you return List<string> so you should return that. It seems that results fits that type and your function is missing the return keyword with the correct return type: return results;

kealist
  • 1,669
  • 12
  • 26
  • I see thanks for that I can now get the details to show teach me for not reading things carefully, Now I should try and work it out myself, but going to ask, how can I return just a part of the string ? well line in the text doc, which would look something like 101, Jim, 17.00, jim@hotmail.com but I only want the 17.00 to show ( pay rate) – Tandinos Oct 17 '17 at 02:00
  • I recommend taking a look at [this question](https://stackoverflow.com/questions/8714197/c-sharp-streamreader-save-to-array-with-separator). If you don't want an array, you can use the `ToList()` extension method – kealist Oct 17 '17 at 02:03
  • Thank you so much for your help mate, I really appreciate it , been trying to work out why that didnt work for so long, got a long way to go, thanks – Tandinos Oct 17 '17 at 02:08