Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to summarize .NET data types

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

NET data types, I believe that many inexperienced people are helpless about this, this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Any development language needs data types as its foundation, just like words in natural languages, so if you want to master a development language, you must first understand the data types, and then I will talk about my understanding of the data types of. NET (the development language is mainly C#).

data type

In C#, data types can be divided into value types, reference types and pointer types. The following is a classification table of data types:

ValueType

Bottom Storage: byte, short, int(default), long

Structure: BigInteger

Keyword: char

Value range: A Unicode character that stores integers between 0 and 65535

Keyword: bool

Value Range: True or False

sbyte:-128~127

byte:0~255

short:-32768~32767

ushort:0~65535

int:-2147483648~2147483647

uint:0~4294967295

long:-9223372036854775808~9223372036854775807

ulong:0~18446744073709551615

float:1.5*10^-45~3.4*10^38

double:5*10^-324~1.7*10^308

decimal:1*10^-28~7.9*10^2

numerical data

Boolean

Char

DateTime and TimeSpan

Numerics

enumeration

structure

reference type

Class class

Interface

Dynamic

Object super parent

String String

Delegate

Array array

pointer type

Data Type Default

Numerical data: 0

Boolean:false

Char: single empty character

DateTime and TimeSpan: 1/1/0001 12:00:00 AM

Numerics:0

Reference type: null

nullable type

Used to represent numeric data with no value, null is added to the value of the actual type. This syntax is only valid for value types. The syntax is as long as the value type keyword is added. Suffix. For example: int? nullableInt = 0;

memory allocation

Value-type variables are allocated on the stack and removed from memory when they leave the domain.

Reference type variables are allocated and managed on the heap, controlled by garbage collection.

replication

shallow copy

When ValueType contains a reference type, two separate ValueType values are generated, but one of the reference types generates a copy of the reference, i.e., a reference to the same object in memory, and changing the value of one of them changes the value of the other.

deep copy

To copy the state of an internal reference completely into a new object, you need to implement the ICloneable interface.

assignment operations

Value type assignment is a copy, two variables are independently operated on.

Reference type assignments are two variables that point to the same object in the managed heap, and changing the value of one variable changes the other.

When the value type contains a reference type, the assignment defaults to shallow copy.

transfer

value type

passed by value

Pass a copy of the variable's data.

reference type

Pass-by-value copies a reference to the caller object. You can change the state data of the object, but you cannot reference a new object.

Passing by reference can change the state data of the object, and can also change the pointer of the reference in memory, and assign the reference to a new object.

type conversion

implicit conversion

broadening

Implicit upconversion, from a type with a small range of values to a type with a large range of values, without loss of data.

display conversion

Forced type conversion

narrowing

Show downconversion from a type with a large value range to a type with a small value range

Overflow detection (default not detected)

VS-> Project Properties-> Generate-> Advanced-> Detect Operation Overflow

unchecked

checked

code level detection

project-level detection

Convert command

Widening, narrowing, string parsing, numerical value, etc.

Custom type conversion

Custom type conversion using keywords explicit and implicit. Implicit implicit conversion operators are easier to use, but explicit operators are useful if you want the operator's users to be aware that a conversion is taking place.

After reading this, do you have a good overview of. NET data types? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report