Home > Article > Backend Development > Packages in C#
As an alternative to packages in Java, the C# language has namespaces.
Packages are used in Java to prevent naming conflicts, control access, and make it easier to search/locate and use classes, interfaces, enumerations, annotations, etc.
#Namespaces are designed to provide a way to keep one set of names separate from another. A class name declared in one namespace does not conflict with the same class name declared in another namespace.
The namespace definition begins with the keyword namespace, followed by the namespace name. Below shows how to use namespaces in C# -
using System; namespace first_space { class namespace_cl { public void func() { Console.WriteLine("Inside first_space"); } } } namespace second_space { class namespace_cl { public void func() { Console.WriteLine("Inside second_space"); } } } class TestClass { static void Main(string[] args) { first_space.namespace_cl fc = new first_space.namespace_cl(); second_space.namespace_cl sc = new second_space.namespace_cl(); fc.func(); sc.func(); Console.ReadKey(); } }
The above is the detailed content of Packages in C#. For more information, please follow other related articles on the PHP Chinese website!