For the namespace can you put anything there | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

For the namespace can you put anything there

26th Sep 2020, 11:39 AM
KingZord
KingZord - avatar
3 Answers
+ 1
onusomto If you found my response helpful, can you mark it as an answer? Thanks!
29th Sep 2020, 12:47 AM
Kaveman
Kaveman - avatar
+ 2
Yes, a namespace defines "where" the script is stored in a library. If I define my namespace like this... using System; namespace Foo { public static class Bar { public static string myVar = "Hello World"; } } In other scripts in order to use it you have to define the namespace (using the "using" header) or use the namespace embedded in the code (not recommended) Ex using System; using Foo; // That namespace public static Program { public static void Program(string[] args) { Console.WriteLine(Bar.myVar); // This will work because we defined the namespace Console.WriteLind(Foo.Bar.myVar); // This will also work but it is lengthy and it is better to define the namespace if you are going to use it more than once } }
26th Sep 2020, 3:53 PM
Kaveman
Kaveman - avatar
0
Ok thank you
28th Sep 2020, 3:27 PM
KingZord
KingZord - avatar