在C#中ArrayList与传统数组间的转换

来源:百度知道 编辑:UC知道 时间:2024/06/03 00:12:18
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace ArrayListSample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string[] departs = new string[4];
departs[0] = "depart 1";
departs[1] = "depart 2";
departs[2] = "depart 3";
departs[3] = "depart 4";
ArrayList departsList = ArrayListSample.Adapter(departs);
listBox1.DataSource = departsList;
}

private void button1_Click(object sender, EventA

看了一下代码,ArrayListSample.Adapter(departs);应该Adapter类的构造函数,在ArrayListSample命名空间中还少了Adapter类的定义,你写的是书上的例子吧,仔细看看你的项目是不是少了Adapter定义,如果不是在当前项目定义,那就是少引用,可能引用其他程序集的Adapter的定义。

Adapter应该是自己写的方法吧,添加using ArrayListSample;