In a question I asked about C #, @bigown answered me and put a sample code in DotNetFiddle.
The code is this:
using static System.Console;
public class Program {
public static void Main() {
var objects = new [] {
new {Id = 2, Nome = "Wallace"},
new {Id = 4, Nome = "Cigano"}
};
WriteLine(objects.GetType());
foreach (var user in objects) {
WriteLine($"Meu id é {user.Id}");
WriteLine($"Meu nome é {user.Nome}");
}
}
}
I noticed that at the beginning of the code there is using static
.
From what I had learned so far from C #, I knew that to make it easier to use a class that is within a specific namespace
, I should use using
.
But I noticed that in the example above, @bigown used using static System.Console
to call the WriteLine
function without having to put Console.WriteLine
on the whole call.
What is the difference between using
and using static
?
Does using
not work for classes? Only for namespace
?
What is the purpose of using static
in the specific case?