13
In a question I asked about C#, @Maniero answered me and put an example 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 realized that at the beginning of the code there is a using static.
From what I had learned so far from C#, I knew that to facilitate the use of a class that is within a namespace specific, I should use using.
But I realized that in the example above, @Maniero used using static System.Console to call the function WriteLine without having to put Console.WriteLine on the entire call.
What is the difference between using and the using static?
The using does not work for classes? Only for namespace?
What is the purpose of using static in the specific case?
Other negative? Is there something wrong with my question?
– Wallace Maxters
They seem to forget to answer the question, it costs nothing.
– rubStackOverflow