日期:2014-05-19  浏览次数:20479 次

求高手解答:C#基础问题
编程背景资料:
public   class   Corporation
{
public   string   Num;
public   string   Name;
public   string   Post;
public   string   Notes;
}
      编程要求:编写一个针对以上数据定义类的集合类;实现集合成员的新增、插入、修改、查询、定位、移除、清除,按Numb索引,Numb和Name索引等功能。


------解决方案--------------------
有点时间帮你写了一下,使用List基本能够完成你要的功能,我只是封装了一下,还需要什么功能自己加吧。

//written by wqxhome
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
using System;
using System.Collections.Generic;
using System.Text;

public class CorporationNode
{
string num;
string name;
string post;
string notes;

public string Num
{
get
{
return num;
}
set
{
num = value;
}
}

public string Name
{
get
{
return name;
}
set
{
name = value;
}
}

public string Post
{
get
{
return post;
}
set
{
post = value;
}
}

public string Notes
{
get
{
return notes;
}
set
{
notes = value;
}
}

public override string ToString()
{
return num + ", " + name + ", " + post + ", " + notes;
}
}

public class CorporationList
{
List <CorporationNode> corporations;
public CorporationList()
{
corporations = new List <CorporationNode> ();
}

public CorporationNode this[int index]
{
get
{
if (index > corporations.Count)
{
throw new Exception( "越界 ");
}
return corporations[index];
}
}

public void Add(CorporationNode corporationNode)
{
corporations.Add(corporationNode);
}

public void Insert(int index, CorporationNode corporationNode)
{
corporations.Insert(index, corporationNode);
}

public void ModifyAt(int index, CorporationNode newCorporationNode)
{
CorporationNode c = corporations[index];
c.Num = newCorporationNode.Num;
c.Name = newCorporationNode.Name;
c.Post = newCorporationNode.Post;
c.Notes = newCorporationNode.Notes;
}

public void Remove(CorporationNode corporationNode)
{
corporations.Remove(corporationNode);
}

public void RemoveAt(int index)
{
corporations.RemoveAt(index);