Is there an "Imports System.Console" (VB.NET) in C #?

2

I would like to know if there is something like a using System.Console in C # .

I wanted to do something in the console to remember. When I learned to use the console, I did it with the VB.NET language. There you could import the namespace called System.Console so as not to repeat the word Console for all the code.

... and I want to do the same, but I can not find a using like that in C # .

Example namespace in Visual Basic

'SIN EL ESPACIO DE NOMBRES ("Console." en cada línea del código)
Module Module1
    Sub Main() 
        Console.WriteLine("HOLA")
        Console.ReadLine()
    End Sub
End Module

'CON EL ESPACIO DE NOMBRES (desaparece el "Console.", lo que quiero en C#)
Imports System.Console
Module Module1
    Sub Main()
        WriteLine("HOLA")
        ReadLine()
    End Sub
End Module>

Anyway, what I would like to know is if I have to write the Console. always in C # , or if there is a way of not doing it.

    
asked by WilsonGtZ 12.11.2016 в 16:05
source

2 answers

2

What you ask for is possible, but only from C # 6 onwards (Visual Studio 2015+). It is achieved with using static . You can find documentation on its use here: using (Directive, C # Reference) .

Example:

using static System.Console;

// ....

static void Main()
{
    WriteLine("hola mundo");
}
    
answered by 13.11.2016 / 03:09
source
2

C #, if you use the namespace System :

using System;
...
...
...
    Console.WriteLine()

If not, you have simply referred to the class Console and its namespace

System.Console.WriteLine()

Responding to your question, you can write only:

using static System.Console;
...
...
    WriteLine("HOLA")
    ReadLine()

If you are using Visual Studio C # 2015 or later.

    
answered by 12.11.2016 в 16:21