+ 1
What do the codes at the beginning of C# mean?
What do these codes that are at the top of C# codes mean? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { } } } My guess/understanding of this, based on the little knowledge I have, is that the “using...” is like “import..” in python, and contains the functions and stuff that can later be used in the code(Console.ReadLine(),Console.WriteLine,etc). The namespace and class bundles everything below it, and main is the function that executed what is written below it.
6 Réponses
+ 10
•—• • •-• ••• —- -• Good question.
The import statement in Python does a bit more than the using directive in C#.
In Python, the import statement does the following:
1.Attempts to locate the module and initializes that module if it's the first time it's being loaded.
2. Loads one or more or all objects from that module into the local scope.
3. Those objects from the module could also be aliased to use different names.
In C#, the using directive does not actually attempt to load or initialize anything as described in items 1 and 2 listed above.
However, the C# using directive is most similar to the third item listed above in that it allows types to be accessed without having to fully qualify the namespace.
For example, let's consider the fully qualified name for the static method used for writing to the system console:
System.Console.WriteLine()
This could be shortened with the following using directive:
using System;
...
Console.WriteLine("...");
Static methods can be further shortened with the using static directive as seen below:
using static System.Console;
...
WriteLine("...");
Hopefully this makes sense.
+ 1
It's been a mystery to me why all SoloLearn examples include Linq when it is never mentioned or used in any lessons, quizzes, or challenges.
0
David Carroll That's unusual. The using command in C# actually works like import in other languages.
Usually use/using is used to import a namespace not a module. Therefore, if foo has a method bar. It should work like this.
using spam.foo;
foo.bar();
Not like this
bar();
I think this behaviour is peculiar to C#?
0
Linq is added by default. C# never intended to be the leanest programming language. But if you want to you can remove it at anytime. If you did not use it it won't cause a compiler error.
0
Rora That is my point. Contrary to what David Carroll suggests, the `using` keyword is actually used — like `import` in other languages — to import external modules into the current namespace.
Normally, `use` in other languages have a different job. They are used to shorten a namespace' name as used in code.