c#中的struct的使用问题

来源:百度知道 编辑:UC知道 时间:2024/06/14 00:39:14
using System;
using System.Collections;
using System.Text;
using System.Collections.Generic;
using System.IO;

public struct Arc
{
int a;
int[] ArcInfo = new int[7];
ArrayList ArcPoint = new ArrayList();
}
编译结果说int数组和Arraylist有问题。难道是struct数组当中不能定义这两个东西?是怎么回事?

你把ArcInfo和ArcPoint实例化了,在结构体中不能实例化成员。

public struct Arc
{
int a;
int[] ArcInfo;
ArrayList ArcPoint;
}

struct是结构体的关键字,定义的是一个结构体,不是数组,请参照结构体说明。

结构是值类型,数组是引用类型,值类型里不能用引用类型