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?
>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");
}
}
}