11-11(11-11)

C#数据类型,封装(访问修饰符),C# 数组(Array)C#数据类型

值类型(Value types)值类型变量可以直接分配给一个值。

bool 布尔值 True 或 False Falsebyte 8 位无符号整数 0 到 255 0char 16 位 Unicode 字符 U +0000 到 U +ffff ‘\0’decimal 128 位精确的十进制值,28-29 有效位数 (-7.9 x 1028 到 7.9 x 1028) / 100 到 28 0.0Mdouble 64 位双精度浮点型 (+/-)5.0 x 10-324 到 (+/-)1.7 x 10308 0.0Dfloat 32 位单精度浮点型 -3.4 x 1038 到 + 3.4 x 1038 0.0Fint 32 位有符号整数类型 -2,147,483,648 到 2,147,483,647 0long 64 位有符号整数类型 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807 0Lsbyte 8 位有符号整数类型 -128 到 127 0short 16 位有符号整数类型 -32,768 到 32,767 0uint 32 位无符号整数类型 0 到 4,294,967,295 0ulong 64 位无符号整数类型 0 到 18,446,744,073,709,551,615 0ushort 16 位无符号整数类型 0 到 65,535 0引用类型(Reference types)引用类型不包含存储在变量中的实际数据,但它们包含对变量的引用。

换句话说,它们指的是一个内存位置。使用多个变量时,引用类型可以指向一个内存位置。

1、对象(Object)类型 是 C# 通用类型系统(Common Type System – CTS)中所有数据类型的终极基类。

2、动态(Dynamic)类型您可以存储任何类型的值在动态数据类型变量中。这些变量的类型检查是在运行时发生的。

3、字符串(String)类型 允许您给变量分配任何字符串值。

C# 封装封装 被定义为”把一个或多个项目封闭在一个物理的或者逻辑的包中”。在面向对象程序设计方法论中,封装是为了防止对实现细节的访问。

C# 封装根据具体的需要,设置使用者的访问权限,并通过 访问修饰符 来实现。

一个 访问修饰符 定义了一个类成员的范围和可见性。C# 支持的访问修饰符如下所示:

public:所有对象都可以访问;

private:对象本身在对象内部可以访问;

protected:只有该类对象及其子类对象可以访问

internal:同一个程序集的对象可以访问;

protected internal:访问限于当前程序集或派生自包含类的类型。

C# 数组(Array)声明数组:元素类型[] 自命名

double[] balance;赋值给数组:1、元素类型[ ] 自命名=new 元素类型[几个值]

自命名[0]=XXX

自命名[1]=XXX

double[] balance = new double[10];

balance[0] = 4500.0;

2、元素类型[] 自命名=new 元素类型[]{XX,XX,XX}

double[] balance = new double[5]{112.2,25.2,3.6,4.6,6.8}

也可以:double[] balance = new double[]{112.2,25.2,3.6,4.6,6.8}

————————

C # data type, encapsulation (access modifier), C # array, C # data type

Value types value type variables can be assigned directly to a value.

bool Boolean value True or false Falsebyte 8-bit unsigned integer 0 to 255 0char 16 bit Unicode character U + 0000 to U + ffff ‘\ 0’decimal 128 bit precise decimal value, 28-29 significant digits (- 7.9 x 1028 to 7.9 x 1028) / 100 to 28 0.0Mdouble 64 bit double precision floating point (+ / -) 5.0 x 10-324 to (+ / -) 1.7 x 10308 0.0Dfloat 32-bit single precision floating point – 3.4 x 1038 to + 3.4 x 1038 0.0Fint 32-bit signed integer type – 2147483648 to 2147483647 0long 64 bit signed integer type – 9223372036854775808 to 9223372036854775807 0Lsbyte 8-bit signed integer type – 128 to 127 0short 16 bit signed integer type – 32768 to 32767 0uint 32-bit unsigned integer type 0 to 4294967295 0ulong 64 bit unsigned integer type 0 to 18446744073709551615 0ushort 16 bit unsigned integer type 0 to 65535 0 reference types reference types do not contain actual data stored in variables, but they contain references to variables.

In other words, they refer to a memory location. When using multiple variables, the reference type can point to a memory location.

1. The object type is the ultimate base class for all data types in the c# common type system (CTS).

2. Dynamic type you can store any type of value in a dynamic data type variable. Type checking of these variables occurs at run time.

3. The string type allows you to assign any string value to a variable.

C # encapsulation is defined as “enclosing one or more items in a physical or logical package”. In object-oriented programming methodology, encapsulation is to prevent access to implementation details.

C # encapsulation sets the user’s access rights according to specific needs and is implemented through access modifiers.

An access modifier defines the scope and visibility of a class member. C # supports the following access modifiers:

Public: all objects can be accessed;

Private: the object itself can be accessed inside the object;

Protected: only this class object and its subclass objects can be accessed

Internal: objects of the same assembly can be accessed;

Protected internal: access is limited to the current assembly or types derived from the containing class.

C# array declaration array: element type [] self naming

double[] balance; Assignment to array: 1. Element type [] self naming = new element type [several values]

Self naming [0] = XXX

Self naming [1] = XXX

double[] balance = new double[10];

balance[0] = 4500.0;

2. Element type [] self naming = new element type [] {XX, XX, XX}

double[] balance = new double[5]{112.2,25.2,3.6,4.6,6.8}

You can also: double [] balance = new double [] {112.2,25.2,3.6,4.6,6.8}