title: Creating a function that takes in a text file as an argument
body: <p>I will admit, I am learning C#. I know what I want to do, it's just a matter of the syntax and calling the right "stuff" as it were.</p>
  
  <p>Essentially, I want to create a function that takes in two arguments:</p>
  
  <ol>
  <li>A Text File</li>
  <li>A String</li>
  </ol>
  
  <p>From what I have been reading and trying to figure out, there are a lot of different methods to Read in text files and do stuff, but I haven't come across a way that actually takes one in as an argument. I know how to create functions in C# that take in data types of particular types, like bool, string, int, decimal, etc.</p>
  
  <p>So, basically it's like this (My Dream, so to say)</p>
  
  <pre><code>protected bool FindWordInFile((textfile), string word_to_find) //Generic Function that takes in a word list file as an argument and a search word and returns if there is a match or not
  {
        //Do stuff
        bool FoundIt = false;
        return FoundIt;
   }
  </code></pre>
  
  <p>Now, the reason I want to do it like this is I have different text files I will want to use to find things, instead of creating separate functions for each of the types of search I want to do.</p>
  
  <p>So, conceivably, I could do:</p>
  
  <pre><code>bool IsThereGoodStuff = FindWordInFile("goodstuff.txt", "awesome");
  bool IsThereBadStuff = FindWordInFile("badstuff.txt", "terrible");
  </code></pre>
  
  <p>Alternatively, I could just create an array from a file and pass the array as an argument, but I would rather not do that. The array wouldn't be that big, given the size of the text files, or I could convert the contents of the text file into a string and pass that. Either way, I want to avoid it.</p>
  
  <p>I've tried mucking around with this a way to create a StreamReader Object, but I haven't found a way to pass that an argument to a function. If there's a way to do that, great! </p>
  
  <pre><code>StreamReader goodwordsfile = new StreamReader("c:\\wordfilelib\\goodwords.txt");
  </code></pre>
  
  <p>But, ideally, I just want to pass the damn file to the function. </p>
  
  <p>Thank you in advance for any help. Much appreciated.</p>