C# ArrayList 완전 정복: 실전 예제로 배우는 동적 배열
C#에서 ArrayList란?
ArrayList 컬렉션은 System.Collections 네임스페이스의 일부로, 전통적인 배열처럼 동작하지만 동적 크기 조절을 제공합니다. 정적 배열과 달리 고정 크기를 미리 선언할 필요가 없으며, 언제든 요소를 추가하거나 제거할 수 있습니다.
ArrayList 선언
new 키워드로 ArrayList를 인스턴스화하고 변수에 할당합니다. 이 변수가 컬렉션에 접근하고 조작하는 핸들이 됩니다.
ArrayList a1 = new ArrayList();
요소 추가
Add 메서드는 int, string, bool, 커스텀 타입 등 어떤 객체든 리스트에 추가합니다.
ArrayList.Add(element)
예시:
a1.Add(1); – 정수 추가
a1.Add("Example"); – 문자열 추가
a1.Add(true); – 불리언 추가
아래는 생성, 추가, 요소 검색을 시연하는 완전한 콘솔 프로그램입니다:

using System;
using System.Collections;
namespace DemoApplication {
class Program {
static void Main(string[] args) {
ArrayList a1 = new ArrayList();
a1.Add(1);
a1.Add("Example");
a1.Add(true);
Console.WriteLine(a1[0]); // 1
Console.WriteLine(a1[1]); // Example
Console.WriteLine(a1[2]); // True
Console.ReadKey();
}
}
}
설명:
- ArrayList 인스턴스화
Add로 다양한 타입의 요소 삽입
- 인덱스 0부터 시작하여 항목 접근
이 코드 실행 결과:

주요 ArrayList 메서드
Count
현재 저장된 요소 수를 반환합니다.
int total = a1.Count;
Contains
지정된 요소가 리스트에 있는지 확인합니다.
bool exists = a1.Contains(2);
RemoveAt
주어진 0 기반 인덱스의 요소를 삭제합니다.
a1.RemoveAt(1);
다음 프로그램은 이 메서드들을 실제 동작으로 보여줍니다:

using System;
using System.Collections;
namespace DemoApplication {
class Program {
static void Main(string[] args) {
ArrayList a1 = new ArrayList();
a1.Add(1);
a1.Add("Example");
a1.Add(true);
Console.WriteLine(a1.Count); // 3
Console.WriteLine(a1.Contains(2)); // False
Console.WriteLine(a1[1]); // Example
a1.RemoveAt(1); // "Example" 제거
Console.WriteLine(a1[1]); // True
Console.ReadKey();
}
}
}
설명:
- 전체 항목 수 표시
- 값
2 존재 여부 확인
- 제거 전 인덱스
1의 요소 표시
- 인덱스
1의 요소 제거
- 인덱스
1의 새 요소 표시(이제 True)
출력은 컬렉션의 동적 특성을 보여줍니다:

요약
ArrayList는 이종 데이터에 대한 유연하고 비제네릭 컨테이너를 제공합니다. 현대 C#은 타입 안전성을 위해 List<T>를 권장하지만, 레거시 코드베이스와 빠른 프로토타이핑을 위해 ArrayList 이해는 여전히 가치 있습니다.