C#类型转换

隐士转换:不需要做任何工作。

显示转换:使用Convert命令进行显示转换。

复杂的变量类型:1.枚举  2.结构  3.数组

enum orientation : byte
{
noth = 1,

south = 2,

east = 3,

west
}

枚举与基本类型转换:(基本数据类型)orientation.noth  (orientation)基本类型变量

枚举与字符串转换:枚举类型成员.ToString(); 或Convert.ToString(枚举类型成员)  

字符串转枚举用命令  Enum.Parse();  

结构:

struct route

{

  public orientation direction;

  public double distance;

}

数组:

<baseType>[] <name>;    <baseType>包括任何变量类型,包括枚举和结构类型

int [] myIntArray = {5,9,10,2,99};   int [] myIntArray = new int [5]; 数值类型默认为0

static int arraySize; int [] myIntArray = new int [arraySize]; 变量对数组初始化,变量必须是静态变量

const int arraySize=5;
int[] myIntArray = new int[arraySize]{5,9,10,2,99};

foreach (<baseType> name in <array> )

{}

    

    

原文地址:https://www.cnblogs.com/niuyjdz/p/7468433.html