title: Call a subroutine in C#
body: <p>could anyone please help me - I'm new to C# console apps, and trying to define a subroutine to replace a string of text in a file.</p>
  
  <p>I keep getting the error though:</p>
  
  <p><code>Error  CS0119  'Program.Main(string[])' is a method, which is not valid in the given context   SSReplace   d:\users\mtait\documents\visual studio 2015\Projects\SSReplace\SSReplace\Program.cs</code></p>
  
  <p>Thanks for any help,</p>
  
  <p>Mark</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.IO;
  using System.Text.RegularExpressions;
  
  namespace SSReplace
  {
  class Program
  {
      static void Main(string[] args)
      {
          SSReplace.Program.Main.ReplaceInFiles("D:\\users\\mtait\\documents\\visual studio 2015\\Projects\\SSReplace\\test_fic_ISUK.txt", "Begin", "Begin2");
      }
  
      /// &lt;summary&gt;
      /// Replaces text in a file.
      /// &lt;/summary&gt;
      /// &lt;param name="filePath"&gt;Path of the text file.&lt;/param&gt;
      /// &lt;param name="searchText"&gt;Text to search for.&lt;/param&gt;
      /// &lt;param name="replaceText"&gt;Text to replace the search text.&lt;/param&gt;
      public void ReplaceInFiles(string filePath, string searchText, string replaceText)
      {
          StreamReader reader = new StreamReader(filePath);
          string content = reader.ReadToEnd();
          reader.Close();
  
          content = Regex.Replace(content, searchText, replaceText);
  
          StreamWriter writer = new StreamWriter(filePath);
          writer.Write(content);
          writer.Close();
      }
  
  }
  }
  </code></pre>