Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

The name "WriteLine" does not exist in Visual Studio

I am developing a console project in C#. The code is separated into some files. The compiler shows this error:

IDE1007 The name 'WriteLine' does not exist in the current context

I used Console.Writeline() method in other files (Program.cs and LaptopBLL.cs to be precise) and the compiler didn’t report any error.
I checked SalesManagerMenu.cs for the using System; line. Naturally, it was there, thouugh the error remains. Here is the full file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LaptopStore
{
    internal class SalesManagerMenu
    {
        Console.WriteLine("\nSample text here");
    }
}

How do I make it work with Console.WriteLine() properly?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The problem isn’t with WriteLine, it’s the fact you can’t have statements directly under a class – they need to be in a method or a constructor. E.g.:

namespace LaptopStore
{
    internal class SalesManagerMenu
    {
        static public void Main(String[] args) // Here!
        {
            Console.WriteLine("\nSample text here");
        }
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading