Maybe you don't know C # basic data types and their default values

Source: Internet
Author: User

// Value Type

C # type. NET Framework type

Bool System. Boolean

4. Logical value of the Byte 32bit Boolean variable; optional values: true or false; default value: false

Byte System. Byte

1 Byte 8bit unsigned integer unsigned Byte, the stored value range is 0 ~ 255. The default value is 0.

Sbyte System. SByte 1 Byte

8-bit signed integer byte, the stored value range is-128 ~ 127. The default value is 0.

Char System. Char

2 Byte 16-bit unsigned Unicode character, default value: '/0'

Decimal System. Decimal

16 byte 128bit decimal number does not comply with rounding rules in decimal number, 28 valid digits, usually used for financial calculation, the default value is 0.0 m

Double system. Double

8 byte 64bit double-precision floating point type, default value: 0.0d

Float System. Single

4 byte 32-bit floating point type with single precision; default value: 0.0f

INT system. int32

4 byte 32bit signed integer, default value: 0

Uint system. uint32

4 byte 32bit unsigned integer; default value: 0

Long system. int64

8 byte 64bit signed integer, default value: 0

Ulong system. uint64

8 byte 64bit unsigned integer; default value: 0

Object System. Object

Reference to a class instance. The default value is null.

Short system. int16

2 byte 16-bit signed integer; default value: 0

Ushort system. uint16

2 byte 16-bit unsigned integer; default value: 0

String System. String

References to a string object. The default value is null.

// Reference type

Variables of the reference type, also known as objects, can store references to actual data. This section describes the following keywords used to declare the reference type:

· Class

Unlike C ++, C # only allows a single inheritance. That is to say, a class can only be inherited from a base class. However, a class can implement more than one interface.

A class can contain the declaration of the following members:

Constructor destructor constant field method attribute indexer operator event Delegate class INTERFACE STRUCTURE

Only the nested classes allow access levels of protected and private.

· Interface

An interface only contains the signature of a method, delegate, or event. It is a fully abstract set of Members. It is not a class and is essentially different from a base class. Method implementation is completed in the class that implements the interface

An interface can be a namespace or a member of a class and contain the signature of the following members: Method property indexer event

An interface can be inherited from one or more basic interfaces.

When the base type list contains the base class and interface, the base class must be the first in the list.

The class that implements the interface can explicitly implement the members of this interface. Explicitly implemented members cannot be accessed through class instances, but can only be accessed through interface instances.

· Delegate

The format of the delegate type declaration is as follows:

Public Delegate void testdelegate (string message );

The delegate keyword is used to declare a reference type, which can be used to encapsulate naming or anonymous methods. The delegate is similar to the function pointer in C ++. However, the delegate type is safe and reliable.

Delegation is the basis of events.

You can instantiate a delegate by associating the delegate with the naming or anonymous method.

Built-in reference types are as follows:

· Object

The object type is the alias of the object in. NET Framework. In the unified type system of C #, all types (pre-defined type, user-defined type, reference type and value type) are inherited directly or indirectly from the object. Any type of value can be assigned to an object-type variable. The process of converting a value type variable to an object is called "boxed ). The process of converting an object type variable to a value type is called "unboxing ".

· String

String represents a sequence composed of zero or more Unicode characters. String is the alias of string in. NET Framework.

Although string is a reference type, it defines equal operators (= and! =) Is to compare the value of a string object (rather than a reference. This makes the test of string equality more intuitive.

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/simonezhlx/archive/2009/04/22/4099904.aspx

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.