您的位置:首页 > 编程语言 > C#

C#学习笔记

2011-08-02 22:41 531 查看
1、 枚举类型:

enum typeName
{
value 1,
value 2,
value 3,
.
.
.
value N
}
typeName varName;//声明
varName=typeName.value//赋值



value的值从0开始,可以重写赋值过程指定每个枚举的实际值。
枚举的基本类型有:byte sbyte short ushort int uint long ulong
2、结构体
struct route
{
public orientation direction;
public double distance;
}
route myRoute;
myRoute.direction = orientation.north;
myRoute.distance = 2.5;



3、数组

<baseType>[] <name>

数组必须在访问前初始化。

数组的初始化方法:

int[] myArrary={5,5,5,5,5};//方法一
int[] myArray = new int[5];//方法二,对于数值类型其被初始化为0
int[] myArray = new int[5]{1,2,2,2,2};//方法三
const int arraySize = 5;
int myArray = new int[arraySize]{1,1,1,1,1};



多维数组(矩形数组,每行个数相同)

<baseType>[,,]<name>;
//赋值
double[,]hillHeight = new double[3,4];//方法一
double[,] hillHeight = {{1,2,3,4},{2,2,2,2},{3,2,3,2}};//方法二



数组的数组:
//声明
int[][] intArray;
//初始化方法一
intArray = new int[2][];
intArray[0] = new int [3];
intArray[1] = new int[4];
//初始化方法二
intArry = new int[3][]{new int[]{1,2,3},new int[]{1},new int[]{1,2}};
//初始化方法三
int[][] intArray = {new int[]{1,2,3},new int[]{1},new int[]{1,2}};









                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# distance struct byte