查看: 964|回复: 0

[ASP.NET教程] ArrayList 注意点

发表于 2017-10-16 08:00:05
太阳http代理AD

1.

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. var al = new ArrayList { 2, 3, true, "aa", true };
  9. //al.Clear();
  10. var count = al.Count;
  11. for (int i = 0; i < count; i++)
  12. {
  13. al.RemoveAt(0);
  14. }
  15. Console.WriteLine(al.Count);
  16. }
  17. }
复制代码

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. var al = new ArrayList {"aa", "ab"};
  9. al.Remove(new string(new char[] {'a', 'b'}));
  10. foreach (var o in al)
  11. {
  12. Console.WriteLine(o);
  13. }
  14. }
  15. }
复制代码

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace ConsoleApp3
  9. {
  10. class Jjj : IEnumerable
  11. {
  12. private int _pos = -1;
  13. private int[] _ss = new int[] { 2, 3, 4, 5 };
  14. public int this[int index]
  15. {
  16. get => _ss[index];
  17. set => _ss[index] = value;
  18. }
  19. public int Count => _ss.Length;
  20. public IEnumerator GetEnumerator()
  21. {
  22. foreach (var i in _ss)
  23. {
  24. yield return i;
  25. }
  26. }
  27. }
  28. class Program
  29. {
  30. static void Main(string[] args)
  31. {
  32. var oj = new Jjj();
  33. var e = oj.GetEnumerator();
  34. while (e.MoveNext())
  35. {
  36. var cur = e.Current;
  37. Console.WriteLine(cur);
  38. }
  39. e.Reset();
  40. while (e.MoveNext())
  41. {
  42. var cur = e.Current;
  43. Console.WriteLine(cur);
  44. }
  45. foreach (var x in oj)
  46. {
  47. Console.WriteLine(x);
  48. }
  49. }
  50. }
  51. }
复制代码



太阳http代理AD
回复

使用道具 举报