如何在c#中实现数据结构中的线性存储。

Ezra 2009-03-16 06:10:45
如何在c#实现数据的插入和删除。比如建立一个数组,要讲一任意的数插入在任意的位置,然后输出这个数组,还有就是删除一个任意位置的数,然后也同样输出这个数组。该怎么做啊?希望各位高手帮帮我啊~~~
...全文
85 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
我不懂电脑 2009-03-16
  • 打赏
  • 举报
回复
用ArrayList
面的代码示例演示如何创建并初始化 ArrayList 以及如何打印出其值
using System;
using System.Collections;
public class SamplesArrayList {

public static void Main() {

// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add("Hello");
myAL.Add("World");
myAL.Add("!");

// Displays the properties and values of the ArrayList.
Console.WriteLine( "myAL" );
Console.WriteLine( " Count: {0}", myAL.Count );
Console.WriteLine( " Capacity: {0}", myAL.Capacity );
Console.Write( " Values:" );
PrintValues( myAL );
}

public static void PrintValues( IEnumerable myList ) {
foreach ( Object obj in myList )
Console.Write( " {0}", obj );
Console.WriteLine();
}

}


/*
This code produces output similar to the following:

myAL
Count: 3
Capacity: f
Values: Hello World !

*/
oktell 2009-03-16
  • 打赏
  • 举报
回复
用类实现啊:

public class Link
{
int number;
Link next;

public Link(int val)
{
this.number = val;
next = null;
}

//增加链
public void Add(int val);

//删除链
public void Remove(int val);
}

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧