C# 数据结构(DataStructure)

C# 数据结构(DataStructure)

ConcurrentQueue: 线程安全版本的Queue;
ConcurrentStack: 线程安全版本的Stack;
ConcurrentBag: 线程安全的对象集合,一个无序的数据结构集,当不需要考虑顺序时非常有用;
ConcurrentDictionary: 线程安全的Dictionary;
BlockingCollection: 与经典的阻塞队列数据结构类似;

一:数组

Array:在内存上连续分配的,而且元素类型是一样的,可以坐标访问;
读取快但是增删慢,总长度不变。

	public void ArrayFun()
	{
   
	    Console.WriteLine("***************Array******************");
	    int[] intArray = new int[3];
	    intArray[0] = 123;
	    intArray[1] = 456;
	    intArray[2] = 123;
	
	    // 根据索引获取数据
	    int a = intArray[0];
	
	
	    // 这种长度必须按照制定的长度[3, 4]来
	    int[,] aa = new int[3, 4] {
   
	        {
   0, 1, 2, 3} ,   /*  初始化索引号为 0 的行 */
	        {
   4, 5, 6, 7} ,   /*  初始化索引号为 1 的行 */
	        {
   8, 9, 10, 11}   /*  初始化索引号为 2 的行 */
	    };
	
	    // 这种长度可以随意
	    int[][] abc = new int[2][];
	    abc[0] = new int[] {
    1, 2 };
	    abc[1] = new int[] {
    3, 4, 5, 6 };
	
	    string[] stringArray = new string[] {
    "123", "234" };
	}

ArrayList:不定长的,连续分配的;
元素没有类型限制,任何元素都是当成object处理,如果是值类型,会有装箱操作;
读取快–增删慢;

	/// <summary>
	/// ArrayList  不定长的,连续分配的;
	/// <para>元素没有类型限制,任何元素都是当成object处理,如果是值类型,会有装箱操作</para>
	/// <para>读取快--增删慢</para>
	/// </summary>
	public void ArrayListFun()
	{
   
	    Console.WriteLine("***************ArrayList******************");
	    ArrayList arrayList = new ArrayList();
	    arrayList.Add("aaa");
	    arrayList.Add("Is");
	    arrayList.Add(32);//add增加长度
	
	    // 只能add
	    //arrayList[4] = 26;
	
	    //删除数据
	    //arrayList.RemoveAt(4);
	    var value = arrayList[2];
	    arrayList.RemoveAt(0);
	    arrayList.Remove("aaa");
	}

List:也是Array,内存上都是连续摆放;
不定长;泛型,保证类型安全,避免装箱拆箱;
读取快–增删慢;

	/// <summary>
	/// List:也是Array,内存上都是连续摆放;不定长;泛型,保证类型安全,避免装箱拆箱
	/// <para>读取快--增删慢</para>
	/// </summary>
	public void ListFun()
	{
   
	    Console.WriteLine("***************List<T>******************");
	    List<int> intList = new List<int>() {
    1, 2, 3, 4 };
	    intList.Add(123);
	    intList.Add(123);
	    //intList.Add("123");
	    //intList[0] = 123;
	    List<string> stringList = new List<string
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值