Sam
Sam

Reputation: 7678

Accessing a Static Method in C#

I have this class:

public static class CsvWriter
    {
       private static StreamWriter _writer = new StreamWriter(@"c:\temp\ssis_list.csv");

       public static  StreamWriter Writer 
       {
          get { return _writer; }
       }
    }

This is being called from another class

 class Program
  {
     ...
     static void GetConnections(string path,string pkgname,string server)
        {

          _writer.WriteLine(myLine);
        }
   }

Which has this error

The name '_writer' does not exist in the current context    

How can I fix this?

Upvotes: 1

Views: 190

Answers (1)

John Saunders
John Saunders

Reputation: 161831

You want CsvWriter.Writer.WriteLine.

Upvotes: 11

Related Questions