当前位置:网站首页>C data type_ From rookie tutorial
C data type_ From rookie tutorial
2022-07-26 22:07:00 【Unity tool man】
data type
Value type (Value types)
Value type variables can be assigned directly to a value . They are from class System.ValueType Derived from .
Value types contain data directly . such as int、char、float, They store numbers separately 、 character 、 Floating point numbers . When you declare a int Type , The system allocates memory to store values .
The following table lists them C# 2010 Value types available in :
| type | describe | Range | Default |
|---|---|---|---|
| bool | Boolean value | True or False | False |
| byte | 8 Bit unsigned integer | 0 To 255 | 0 |
| char | 16 position Unicode character | U +0000 To U +ffff | ‘\0’ |
| decimal | 128 The exact decimal value of ,28-29 Effective digits | (-7.9 x 1028 To 7.9 x 1028) / 100 To 28 | 0.0M |
| double | 64 Bit double precision floating point | (+/-)5.0 x 10-324 To (+/-)1.7 x 10308 | 0.0D |
| float | 32 Bit single precision floating point type | -3.4 x 1038 To + 3.4 x 1038 | 0.0F |
| int | 32 Bit signed integer type | -2,147,483,648 To 2,147,483,647 | 0 |
| long | 64 Bit signed integer type | -9,223,372,036,854,775,808 To 9,223,372,036,854,775,807 | 0L |
| sbyte | 8 Bit signed integer type | -128 To 127 | 0 |
| short | 16 Bit signed integer type | -32,768 To 32,767 | 0 |
| uint | 32 Bit unsigned integer type | 0 To 4,294,967,295 | 0 |
| ulong | 64 Bit unsigned integer type | 0 To 18,446,744,073,709,551,615 | 0 |
| ushort | 16 Bit unsigned integer type | 0 To 65,535 | 0 |
To get the exact size of a type or variable on a specific platform , have access to sizeof Method . expression sizeof(type) Generates a storage size that stores objects or types in bytes . Here's an example to get... On any machine int Storage size of type :
example
using System;
namespace DataTypeApplication
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Size of int: {0}", sizeof(int));
Console.ReadLine();
}
}
}
When the above code is compiled and executed , It will produce the following results :
Size of int: 4
Reference type (Reference types)
object (Object) type
object (Object) type yes C# General type system (Common Type System - CTS) The ultimate base class for all data types in .Object yes System.Object Alias of class . So the object (Object) Type can be assigned to any other type ( Value type 、 Reference type 、 Predefined or user-defined types ) Value . however , Before assigning values , Type conversion is required first .
When a value type is converted to an object type , It's called Packing ; On the other hand , When an object type is converted to a value type , It's called Unpacking .
object obj;
obj = 100; // This is packing
dynamic (Dynamic) type
You can store any type of value in a dynamic data type variable . Type checking of these variables occurs at run time .
Syntax for declaring dynamic types :
dynamic <variable_name> = value;
for example :
dynamic d = 20;
Dynamic types are similar to object types , But type checking of object type variables occurs at compile time , Type checking of dynamically typed variables occurs at run time .
character string (String) type
character string (String) type Allows you to assign any string value to a variable . character string (String) The type is System.String Alias of class . It is from the object (Object) Type derived . character string (String) The value of type can be assigned in two forms : Quotation marks and @ quotes .
for example :
String str = "runoob.com";
One @ Quote string :
@"runoob.com";
C# string The string can be preceded by @( Referred to as " Word for word strings ") The escape character (\) Treat as ordinary characters , such as :
string str = @"C:\Windows";
Equivalent to :
string str = "C:\\Windows";
@ You can wrap any line in the string , Line breaks and indented spaces are calculated within the length of the string .
string str = @"<script type=""text/javascript""> <!-- --> </script>";
User defined reference types include :class、interface or delegate.
Pointer types (Pointer types)
Pointer type variables store another type of memory address .C# Pointer in and C or C++ Pointers in have the same function .
Syntax for declaring pointer types :
type* identifier;
for example :
char* cptr;
int* iptr;
边栏推荐
- Kalibr calibration realsensed435i -- multi camera calibration
- Flink 在讯飞 AI 营销业务的实时数据分析实践
- What you need to know about mobile video compatibility
- Task04 | classification analysis
- Altium designer 22 modify the layer properties of the selected component
- If you do not add waitkey() function after imshow() function, it will not be displayed
- Ansible installation and use
- mysql推荐书
- FreeRTOS personal notes - Events
- 进程的概念和分类
猜你喜欢

Just one dependency to give swagger a new skin, which is simple and cool~

JDBC总结

I successfully landed the automatic testing post, with a maximum monthly salary of 15.4k. I'm great~

My SQL is OK. Why is it still so slow? MySQL locking rules

JDBC summary

Task04 | classification analysis

Matlab draws short-term average amplitude spectrum

JDBC operation and entry case of MySQL

LDAP——实现用户统一登录管理

月薪5万的朋友告诉我,你只是在打杂
随机推荐
Ansible installation and use
Just one dependency to give swagger a new skin, which is simple and cool~
Is it safe to open an account on flush? How to choose a securities firm for opening an account
Flink 在讯飞 AI 营销业务的实时数据分析实践
Overview of MPLS Basics
In depth analysis of the source code, why is the string class immutable? (hit me before you understand)
Task04 | classification analysis
我的sql没问题为什么还是这么慢|MySQL加锁规则
Join method in JS
Database notes (from Lao She)
Li Kou daily question - day 43 -168. Name of Excel table column
基于CAShapeLayer和贝塞尔曲线的圆形进度条动画
matlab 画短时平均幅度谱
Let Xiaobai thoroughly understand performance tuning
C# 数据类型_摘自菜鸟教程
ZABBIX calls API retrieval method
彻底搞通服务发现的原理和实现
Technology sharing | do you know the functions of the server interface automated testing and requests library?
梦里的一碗面
Afnetworking understand