Understanding C # naming conventions

Source: Internet
Author: User
I. C # name blank space
C # specify the parameter value for the parameter value. Each parameter value can be found in Program Type Used in: type, structure, component, delegate, and interface. Use Using to reference the namespace, such as the commonly used using system;
When using nested naming for null time, you need to use full-path routing

2. Use the naming Space
The agent can be divided into multiple files.
The namespace is scalable.
A hierarchical structure can be created.

Iii. generation can be divided into multiple files
The same naming space can be distributed in different files. For example, the CG naming space in the following generation is in namespace. in CS and namespace01.cs, these two files are combined to form a named blank CG
Note: nesting types can only be in the same file and cannot be performed across different files.

Namespace. CS file replacement: Using System;
Namespace CG
{
Class Test
{
Static   Void Main ()
{
Printname PN = New Printname ();
Pn. Intro ();
}
}
}

Namespace01.cs file generation: Using System;
Namespace CG
{
Public   Class Printname
{
Public   Void Intro ()
{
Console. writeline ( " My name is " );
}
}
}

4. The namespace is scalable.
in the preceding example, the two namespaces are distributed in different files, we change one file instead of copying another file. This namespace is more scalable. For example, if the Sub-Name Space in the above example is used to generate the DLL file, the main command uses the space to reference this DLL. When the sub-name blank list changes, the primary name blank space does not need to be renewed again.
Note:
4.1 using the following methods:

code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/

--> CSC primary CS file secondary CS file
command:
CSC namespace . CS namespace01.cs

4.2 method for generating sequence types:

code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/

--> CSC / Target: Library CS file (DLL file created by ghost)
command:
CSC / Target: Library namespace . CS

4.3 primary file and Classification CSC/Reference: The Referenced File Name of a similar object.
The following command
CSC/Reference: namespace01.dllNamespace. CS

5. A hierarchical structure can be built up.
For example, the names of A. A1 and A. A2 in the following generation are empty, which makes it easier to group and manage them. Using System;
Namespace CG
{
Class Test
{
Static   Void Main ()
{
A. a1.printname = New A. a1.printname ();
A. Intro ();
A. a2.printname B = New A. a2.printname ();
B. Intro ();
Console. Readline ();
}
}
}
Namespace A
{
Namespace A1
{
Public   Class Printname
{
Public   Void Intro ()
{
Console. writeline ( " My name is " );
}
}
}
Namespace A2
{
Public   Class Printname
{
Public   Void Intro ()
{
Console. writeline ( " My name is B " );
}
}
}
}

6. Name of alies)
Use other names to make the program more agile
Usage:
Using other name = namespace Blank

Comparison between the following non-point source generations and more generations:

Source: Using System;
Namespace CG
{
Class Test
{
Static   Void Main ()
{
Parentnamespace. childnamespace. printname = New Parentnamespace. childnamespace. printname ();
A. Intro ();
Console. Readline ();
}
}

}
Namespace Parentnamespace
{
Namespace Childnamespace
{
Public   Class Printname
{
Public   Void Intro ()
{
Console. writeline ( " My name is " );
}
}
}
}

This generation is changed to the form of another name:

Using System;
Using MySpace = Parentnamespace. childnamespace;
Namespace CG
{
Class Test
{
Static   Void Main ()
{
MySpace. printname = New MySpace. printname ();
A. Intro ();
Console. Readline ();
}
}

}
Namespace Parentnamespace
{
Namespace Childnamespace
{
Public   Class Printname
{
Public   Void Intro ()
{
Console. writeline ( " My name is " );
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.