0

I have this code that I wrote but I am getting an error saying that a namespace cannot include methods. Would appreciate any advice on what I am doing wrong and / or a suggestion on how I could code this in a better way to avoid this error.

namespace WriteToExcel
{
    class Program
    {

        static void Main(string[] args)
        {
            List<PhraseSource> data = ReadFromFile();
        }

        static List<PhraseSource ReadFromFile()
        {
            var filepath = @"/Users/psnet.data";
            return ReadFromJsonFile<List<PhraseSource>>(filepath);
        }

        static T ReadFromJsonFile<T>(string filePath) where T : new()
        {
            TextReader reader = null;
            try
            {
                reader = new StreamReader(filePath);
                var fileContents = reader.ReadToEnd();
                return JsonConvert.DeserializeObject<T>(fileContents);
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }
        }
    }
}

1 Answer 1

4

You missed a >

The funny thing is, if you miss a really basic syntax component sometimes, you can get blasted with a bunch of errors that don't make sense. However, if you work through the errors you will usually find the right one

enter image description here

This

static List<PhraseSource ReadFromFile()

Should be

static List<PhraseSource> ReadFromFile()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.