Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

561
Visualizações
The name 'File' does not exist in the current context

I am a beginner in c# programming. I am gettting error The name 'File' does not exist in the current context.

Problem must be in the line var v = File.ReadLines("dictionary.txt");

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

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                var v = File.ReadLines("dictionary.txt");
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Just add this using statement to the top of you file

using System.IO;

The compiler only recognises classes from namespaces that you have in the current context. You add namespace to the context using using statements. You can also use a fully qualified type name such as System.IO.File to refer to the class.

If you are using Visual Studio you can also place the cursor on the problematic symbol (File) and press Shift + Alt + F10

over 4 years ago · Santiago Trujillo Relatório

0

For anyone using Visual Studio 2015 this error will still occur even if System.IO is referenced. The problem is that by default a Visual Studio 2015 project will target both the dnx451 and dnxcore50 frameworks, and the System.IO assembly doesn't seem to be available for dnxcore50.

If you look in the project.json file you'll see a "frameworks" section. The quick fix is to comment out the "dnxcore50" entry so that you're only targeting dnx451:

"dnxcore50": {
    "dependencies": {
        "System.Console": "4.0.0-beta-22816",
        "System.Collections": "4.0.10-beta-22816",
        "System.Linq": "4.0.0-beta-22816",
        "System.Threading": "4.0.10-beta-22816",
        "Microsoft.CSharp": "4.0.0-beta-22816"
    }
}
over 4 years ago · Santiago Trujillo Relatório

0

Add using System.IO; to your usings section.

File class is located in System.IO namespace.

Alternatively (if it is the only place in your code where you're using some type from System.IO) you can use fully qualified name of File like:

var v = System.IO.File.ReadLines("dictionary.txt");

But in the case when you need to access objects from some namespace multiple times in your code, it is better to inculde that namespace in usings.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda