I have the method below but I am going to have more methods similar to this one. They differ in is the last parameters being passed to the method. The first three parameters will always be there and then in the while loop with && conditions, I am going to use the same params that I am passing in.I am going to need five or six of these methods. Do you think I can write this method in a more reusable way, or do I have to just copy/paste most of it and change the params and condition for each method?private string FindFullRowForProvider(string id, string lastName, string firstName, string devSystem){    string fullRow = string.Empty;    StreamReader streamreader = new StreamReader(importSource);    char[] delimiter = new char[] { '|' };    int columnLocation = 0;    string[] columnheaders = streamreader.ReadLine().Split(delimiter);    foreach (string columnheader in columnheaders)    {        columnHeadertoLocation[columnheader.ToUpper()] = columnLocation;        columnLocation++;    }    while (streamreader.Peek() > 0)    {        fullRow = streamreader.ReadLine();        string[] currentRowValues = fullRow.Split(delimiter);        string _NPI = currentRowValues[columnHeadertoLocation[ID]];        string _LName = currentRowValues[columnHeadertoLocation[LNAME]];        string _FName = currentRowValues[columnHeadertoLocation[FNAME]];        string _devPKCR = currentRowValues[columnHeadertoLocation[DEV_SYSTEM]];        if (npi.Trim().ToUpper() == _NPI.Trim().ToUpper()            && _LName.Trim().ToUpper() == lastName.Trim().ToUpper()            && _FName.Trim().ToUpper() == firstName.Trim().ToUpper()            && _dev.Trim().ToUpper() == devSystem.Trim().ToUpper())        {            // woot! we found the row of this guy.            return fullRow;        }    }    return fullRow;}
Writing a reusable method in which only some of its parameters are different
c#
I'm not a fan of npi.Trim().ToUpper() == _NPI.Trim().ToUpper(), because there is a better way. Use that solution in a method like this and your code will look a lot nicer:private bool AreIdentical(string a, string b){    return string.Equals(a.Trim(), b.Trim(), StringComparison.CurrentCultureIgnoreCase);}(Note that this doesn't catch NULL strings, but neither does your original code.)I also note that your code as presented here doesn't actually work. The parameter string id is used nowhere and seems to have become npi. Ditto for _devPKCR._LName and _FName are IMHO bad names, and _NPI and _devPKCR are even worse. Moreover, they don't follow Microsoft guidelines.If you're going to return fullRow; anyway, I wouldn't also do it inside the if-block. Just break; out of that one.EDIT I just notice your code also fails here: fullRow will contain the value of the last line read from the file if there is no valid result.You don't seem to close the StreamReader. It would be better if you used it in a using block:using (StreamReader streamreader = new StreamReader(importSource)){    // do stuff}This review is in addition to previous ones, so other remarks also apply. RubberDuck's suggestion of a Person class to limit the amount of search parameters is a very good one for instance.EDIT 2: To avoid the code returning the last row read from the file when there's no valid line, you'll need to restructure the logic like this:private string FindFullRowForProvider([params]){    // remove this line: string fullRow = string.Empty;    while (streamreader.Peek() > 0)    {        var fullRow = streamreader.ReadLine();        if ([code to check if all requirements are met])        {            // woot! we found the row of this guy.            return fullRow;        }    }    return string.Empty;}