12. C# - Namespaces
Namespaces are like folders on a computer.
They help organize or put similar code in one area.
Not necessary to have a namespace, but can help with organization.
Things inside a namespace, like a variable, statement, or method, must be grouped inside a class first.
Creating a namespace:
namespace MyNameSpace{
whatever in here, cant be Fields, methods, or statements. Meaning if want to put a variable, it must be placed inside a class first.
}
Nesting namespace:
// can nest namespaces inside a namespace inside more namespaces.
namespace NameSpaceA{
namespace NameSpaceB{
whatever here
}
}
Accessing things within a namespace:
Create a sample namespace,
namespace SampleNameSpace{
String dog = "Benny";
}
Printing the dog,
Console.WriteLine(SampleNameSpace.dog);
Comments
Post a Comment