Packages in C#

PHPz
Release: 2023-09-10 21:17:02
forward
1105 people have browsed it

C# 中的包

As an alternative to packages in Java, the C# language has namespaces.

Packages in Java

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 in C

#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# -

Example

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();
   }
}
Copy after login

The above is the detailed content of Packages in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template