Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use using in C #

Shulou Source: shulou.com Published: 2022-06-01 01:52:34 10月03日 Update

This article mainly explains "how to use using in C#". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use using in C#".

The usage of using:

1. Using directive: introduce namespaces

This is the most common usage, such as:

Using System;using Namespace1.SubNameSpace

2. Using static directive: specifies the type whose static members can be accessed without specifying a type name

Using static System.Math;var = PI; / / use System.Math.PI directly

3. Give an alias

Using Project = PC.MyCompany.Project

4. Using statement: bind the instance to the code

Using (Font font3 = new Font ("Arial", 10.0f), font4 = new Font ("Arial", 10.0f)) {/ / Use font3 and font4. }

At the end of the code snippet, the Dispose methods of font3 and font4 are automatically called to release the instance.

Thank you for your reading, the above is the content of "how to use using in C#". After the study of this article, I believe you have a deeper understanding of how to use using in C#, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Examples instructions types aliases names that is common ideas situations members articles methods more knowledge knowledge points space Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia Apple Microsoft Shulou Tech Info