How to add items to ArrayList in C#?

WBOY
Release: 2023-09-05 09:53:02
forward
958 people have browsed it

如何在 C# 中向 ArrayList 添加项目?

ArrayList is a non-generic collection in C# that can be dynamically resized.

Let us see how to initialize ArrayList in C# -

ArrayList arr= new ArrayList();
Copy after login

Add items to array list -

ArrayList arr1 = new ArrayList();
arr1.Add(30);
arr1.Add(70);
Copy after login

Let us see the complete example of implementing ArrayList in C#. Here we have two array lists. The second array list is appended to the first list.

Example

using System;
using System.Collections;

public class MyClass {
   public static void Main() {
      ArrayList arr1 = new ArrayList();
      arr1.Add(30);
      arr1.Add(70);

      ArrayList arr2 = new ArrayList();
      arr2.Add(200);
      arr2.Add(240);

      arr1.AddRange(arr2);
      for (int i = 0; i < arr1.Count; i++)
      Console.WriteLine(arr1[i]);
   }
}
Copy after login

The above is the detailed content of How to add items to ArrayList in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!