Some technical accumulation of. Net (for yourself)

Source: Internet
Author: User
// Calculate the length of the text to distinguish between multi-byte characters
Return System. Text. encoding. Default. getbytes ("ABC China"). length;

Extern// The extern modifier is used to declare the member functions implemented outside the assembly.
// It is often used to call system API functions (through dllimport ). Note: The static modifier must be added for use with dllimport.
[Dllimport ("user32.dll")]
Public static extern int MessageBox (INT handle, string message, string caption, int type );

Abstract// Abstract modifier can be used for classes, methods, attributes, events, and index indicators (Indexer) to represent abstract members.
// Abstract cannot be used with static or virtual objects
// Declared abstract members can not include the implementation code, but only the class has unimplemented abstract members. This class cannot be instantiated. It is usually used to force the inheritance class to implement a certain member.
Public abstract class baseclass {}

Internal
The internal modifier can be used for types or members. types or members declared using this modifier can only be accessed within the same assembly (namespace ).

Sealed
Sealed modifier indicates sealed
When used for a class, it indicates that the class cannot be inherited and cannot be used with abstract at the same time, because these two modifiers are mutually exclusive in meaning.
When used for methods and attributes, it indicates that the method or attribute cannot be inherited and must be used together with the override keyword, because the method or attribute using the sealed modifier must be a virtual Member of the base class.
It is usually used to implement third-party class libraries that do not want to be inherited by the client, or for classes that do not need to be inherited to prevent hierarchy confusion caused by misuse of inheritance.
The proper use of the sealed modifier can also improve the running efficiency, because the inherited class will overwrite the member.

Index indicator
The class that implements index indicator (Indexer) can use the object after its instance like an array, but unlike the array, the parameter type of index indicator is not limited to int
Simply put, it is essentially a parameter attribute
For example:

Public String This [String Day]

Alias indicator
Using alias indicators, we can create an alias for a type.
It is mainly used to resolve conflicts between two namespaces with the same name type or avoid redundant namespaces.
Alias indicators work only in one unit file

// Use the alias indicator to resolve conflicts with the same name Type
Using lib01class1 = com. nblogs. reonlyrun. csharp26qexample. example19.lib01. class1;
Using lib02class2 = com. nblogs. reonlyrun. csharp26qexample. example19.lib02. class1;

Params

The Params keyword is used in the parameter list of the method member to provide the ability to change the number of parameters for this method.
It can appear only once and cannot be followed by parameter definitions.

Using system;
Using system. Collections. Generic;
Using system. text;
 
Namespace consoleapplication1
{
Class app
{
// The first parameter must be an integer, but the number of subsequent parameters is variable.
// Because the object array is specified, all data types can be passed as parameters.
Public static void useparams (int id, Params object [] list)
{
Console. writeline (ID );
For (INT I = 0; I <list. length; I ++)
{
Console. writeline (list [I]);
}
}
 
Static void main ()
{
// Variable parameters are input with three parameters, both of which are strings.
Useparams (1, "A", "B", "C ");
// Four parameters are input in the Variable Parameter section, which are string, integer, floating point, and double-precision floating point array.
Useparams (2, "D", 100, 33.33, new double [] {1.1, 2.2 });
 
Console. Readline ();
}
}
}

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.