ArrayList与结构体应用

本文介绍如何使用C#中的ArrayList类来存储和遍历数据。通过创建自定义结构体SData,演示了如何添加数据到ArrayList中,并通过foreach循环进行遍历。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Collections;
  6. namespace TestArrayList
  7. {
  8.     class Program
  9.     {
  10.         public struct SData
  11.         {
  12.             public int Index;
  13.             public string Content;
  14.         }
  15.         static void Main(string[] args)
  16.         {
  17.             ArrayList aList = new ArrayList();
  18.             SData d0 = new SData();
  19.             d0.Index = 0;
  20.             d0.Content = "d0";
  21.             aList.Add(d0);
  22.             SData d1 = new SData();
  23.             d1.Index = 1;
  24.             d1.Content = "d1";
  25.             aList.Add(d1);
  26.             SData d2 = new SData();
  27.             d2.Index = 2;
  28.             d2.Content = "d2";
  29.             aList.Add(d2);
  30.             foreach (SData d in aList)
  31.             {
  32.                 Console.WriteLine("Index={0} Content={1}", d.Index, d.Content);
  33.             }
  34.             Console.WriteLine();
  35.             Console.ReadLine();
  36.         }
  37.     }
  38. }



引用命令空间:

using System.Collections;

 

效果图:

image

 

参考文献:

http://blog.sina.com.cn/s/blog_6fd3ad020100ndyt.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值