.NET 도움말 C# ArrayList (How It Works For Developers) 커티스 차우 업데이트됨:7월 28, 2025 다운로드 IronPDF NuGet 다운로드 DLL 다운로드 윈도우 설치 프로그램 무료 체험 시작하기 LLM용 사본 LLM용 사본 LLM용 마크다운 형식으로 페이지를 복사하세요 ChatGPT에서 열기 ChatGPT에 이 페이지에 대해 문의하세요 제미니에서 열기 제미니에게 이 페이지에 대해 문의하세요 Grok에서 열기 Grok에게 이 페이지에 대해 문의하세요 혼란 속에서 열기 Perplexity에게 이 페이지에 대해 문의하세요 공유하다 페이스북에 공유하기 트위터에 공유하기 LinkedIn에 공유하기 URL 복사 이메일로 기사 보내기 The ArrayList class is part of the .NET Framework's collections namespace, designed to store a collection of objects. It is a non-generic collection, meaning it can hold items of any data type. This feature makes it highly flexible but less type-safe compared to generic collections. The ArrayList can contain duplicate elements and allows for dynamic resizing as a valid value is added or removed. In this article, we'll discuss the basics of ArrayList and the IronPDF Library Features. The Basics of ArrayList The ArrayList is essentially a non-generic collection capable of storing a number of elements of any data type, making it a versatile choice for various programming scenarios. The ability to add elements or remove items at will without the constraints of a fixed size is one of its key features. The ArrayList adjusts its size automatically to accommodate new elements, a feature made possible through its implementation of the IList interface. This dynamic resizing is crucial for applications that require collections with a varying number of elements over their lifetime. When you instantiate an ArrayList, you're creating a collection that can hold any object value, from integers and strings to complex custom objects. Adding elements to an ArrayList is straightforward, thanks to methods like Add, which appends an object value to the end of the collection, and Insert, which places a new item at a specified index, shifting existing elements as necessary to make room. This flexibility allows developers to manage collections more effectively, adapting to the needs of the application as it evolves. Working with Elements Adding elements to an ArrayList is simple and intuitive. For instance, consider a scenario where you're building a collection of various types of data. With the Add method, you can append any object to your ArrayList, from strings to integers, or even other collections. The capacity of the ArrayList is automatically increased as needed, ensuring that there's always room for new object obj elements. This automatic resizing is a significant advantage over traditional arrays, which require manual resizing or the creation of a new array to accommodate more elements. The ArrayList also provides methods for inserting and removing elements at specific positions or int index. The Insert method allows you to add an element at a specified position, effectively enabling you to place new items precisely within the collection at any specified index. Similarly, the Remove and RemoveAt methods facilitate the deletion of items, either by specifying the object to be removed or its index within the collection. This granular control over the elements within the ArrayList makes it a powerful tool for managing dynamic data. Creating and Adding Elements To start using an ArrayList, you first need to create an instance of it. Then, you can add elements to the ArrayList using the Add method, which inserts an object to the end of the ArrayList. using System; using System.Collections; class Program { // The main entry point of the program public static void Main() { // Create a new ArrayList ArrayList myArrayList = new ArrayList(); // Add elements of different types myArrayList.Add("Hello"); myArrayList.Add(100); var item = "World"; myArrayList.Add(item); // Iterate through the ArrayList and print each element foreach (var obj in myArrayList) { Console.WriteLine(obj); } } } using System; using System.Collections; class Program { // The main entry point of the program public static void Main() { // Create a new ArrayList ArrayList myArrayList = new ArrayList(); // Add elements of different types myArrayList.Add("Hello"); myArrayList.Add(100); var item = "World"; myArrayList.Add(item); // Iterate through the ArrayList and print each element foreach (var obj in myArrayList) { Console.WriteLine(obj); } } } $vbLabelText $csharpLabel This example demonstrates how to create a new ArrayList and add different types of elements to it. The foreach loop then iterates through the ArrayList, printing each element. Inserting Elements To insert an element at a specified index, use the Insert method, noting that this is a zero-based index system. // Insert element at index 1 myArrayList.Insert(1, "Inserted Item"); // Insert element at index 1 myArrayList.Insert(1, "Inserted Item"); $vbLabelText $csharpLabel Removing Elements To remove elements, the Remove and RemoveAt methods come in handy. Remove deletes the first occurrence of a specific object, while RemoveAt removes the element at the specified integer index. myArrayList.Remove("Hello"); // Removes the first occurrence of "Hello" myArrayList.RemoveAt(0); // Removes the element at index 0 myArrayList.Remove("Hello"); // Removes the first occurrence of "Hello" myArrayList.RemoveAt(0); // Removes the element at index 0 $vbLabelText $csharpLabel Example: Managing an ArrayList Creating an advanced example of using ArrayList in C# involves showcasing not just the basic operations like adding or removing elements, but also more complex manipulations such as sorting, searching, and converting the ArrayList to other data structures. Put the following example in the Program.cs file to run it: using System; using System.Collections; using System.Linq; class AdvancedArrayListExample { static void Main(string[] args) { // Initialize an ArrayList with some elements ArrayList numbers = new ArrayList() { 5, 8, 1, 3, 2 }; // Adding elements numbers.Add(6); // Add an element to the end numbers.AddRange(new int[] { 7, 9, 0 }); // Add multiple elements from a specified collection. Console.WriteLine("Initial ArrayList:"); foreach (int number in numbers) { Console.Write(number + " "); } Console.WriteLine("\n"); // Removing elements numbers.Remove(1); // Remove the element 1 numbers.RemoveAt(0); // Remove the first element Console.WriteLine("After Removal:"); foreach (int number in numbers) { Console.Write(number + " "); } Console.WriteLine("\n"); // Sorting numbers.Sort(); // Sort the ArrayList Console.WriteLine("Sorted ArrayList:"); foreach (int number in numbers) { Console.Write(number + " "); } Console.WriteLine("\n"); // Searching int searchFor = 5; int index = numbers.IndexOf(searchFor); // Find the index of the element if (index != -1) { Console.WriteLine($"Element {searchFor} found at index {index}"); } else { Console.WriteLine($"Element {searchFor} not found."); } Console.WriteLine("\n"); // Converting ArrayList to Array int[] numbersArray = (int[])numbers.ToArray(typeof(int)); Console.WriteLine("Converted Array:"); foreach (int number in numbersArray) { Console.Write(number + " "); } Console.WriteLine("\n"); // Demonstrate LINQ with ArrayList (Requires System.Linq) var evenNumbers = numbers.Cast<int>().Where(n => n % 2 == 0).ToList(); // Assign values to evenNumbers from the filtered results. Console.WriteLine("Even Numbers:"); evenNumbers.ForEach(n => Console.Write(n + " ")); Console.WriteLine(); } } using System; using System.Collections; using System.Linq; class AdvancedArrayListExample { static void Main(string[] args) { // Initialize an ArrayList with some elements ArrayList numbers = new ArrayList() { 5, 8, 1, 3, 2 }; // Adding elements numbers.Add(6); // Add an element to the end numbers.AddRange(new int[] { 7, 9, 0 }); // Add multiple elements from a specified collection. Console.WriteLine("Initial ArrayList:"); foreach (int number in numbers) { Console.Write(number + " "); } Console.WriteLine("\n"); // Removing elements numbers.Remove(1); // Remove the element 1 numbers.RemoveAt(0); // Remove the first element Console.WriteLine("After Removal:"); foreach (int number in numbers) { Console.Write(number + " "); } Console.WriteLine("\n"); // Sorting numbers.Sort(); // Sort the ArrayList Console.WriteLine("Sorted ArrayList:"); foreach (int number in numbers) { Console.Write(number + " "); } Console.WriteLine("\n"); // Searching int searchFor = 5; int index = numbers.IndexOf(searchFor); // Find the index of the element if (index != -1) { Console.WriteLine($"Element {searchFor} found at index {index}"); } else { Console.WriteLine($"Element {searchFor} not found."); } Console.WriteLine("\n"); // Converting ArrayList to Array int[] numbersArray = (int[])numbers.ToArray(typeof(int)); Console.WriteLine("Converted Array:"); foreach (int number in numbersArray) { Console.Write(number + " "); } Console.WriteLine("\n"); // Demonstrate LINQ with ArrayList (Requires System.Linq) var evenNumbers = numbers.Cast<int>().Where(n => n % 2 == 0).ToList(); // Assign values to evenNumbers from the filtered results. Console.WriteLine("Even Numbers:"); evenNumbers.ForEach(n => Console.Write(n + " ")); Console.WriteLine(); } } $vbLabelText $csharpLabel This code snippet demonstrates how to: Initialize an ArrayList with a set of elements. Add single and multiple elements to the ArrayList. Remove elements by value and by index. Sort the ArrayList to order the elements. Search for an element and find its index. Convert the ArrayList to a standard array. Use LINQ with ArrayList to filter out even numbers, showcasing how to bridge non-generic collections with LINQ's powerful query capabilities. Introduction of IronPDF: C# PDF Library IronPDF is a powerful library for C# that simplifies the complex process of PDF generation, offering a wide range of features for PDF manipulation, including the ability to generate PDFs from HTML, add text and images, secure documents, and much more. Integrating IronPDF with ArrayList Let's write a simple C# program that creates an ArrayList of items, and then uses IronPDF to generate a PDF document listing those items. using IronPdf; using System; using System.Collections; class PdfCode { static void Main(string[] args) { // Set your IronPDF license key here IronPdf.License.LicenseKey = "Your_License_Key"; // Create a new ArrayList and add some items ArrayList itemList = new ArrayList(); itemList.Add("Apple"); itemList.Add("Banana"); itemList.Add("Cherry"); itemList.Add("Date"); // Initialize a new PDF document var Renderer = new ChromePdfRenderer(); // Create an HTML string to hold our content string htmlContent = "<h1>Items List</h1><ul>"; // Iterate over each item in the ArrayList and add it to the HTML string foreach (var item in itemList) { htmlContent += $"<li>{item}</li>"; } htmlContent += "</ul>"; // Convert the HTML string to a PDF document var PDF = Renderer.RenderHtmlAsPdf(htmlContent); // Save the PDF to a file PDF.SaveAs("ItemList.pdf"); Console.WriteLine("PDF file 'ItemList.pdf' has been generated."); } } using IronPdf; using System; using System.Collections; class PdfCode { static void Main(string[] args) { // Set your IronPDF license key here IronPdf.License.LicenseKey = "Your_License_Key"; // Create a new ArrayList and add some items ArrayList itemList = new ArrayList(); itemList.Add("Apple"); itemList.Add("Banana"); itemList.Add("Cherry"); itemList.Add("Date"); // Initialize a new PDF document var Renderer = new ChromePdfRenderer(); // Create an HTML string to hold our content string htmlContent = "<h1>Items List</h1><ul>"; // Iterate over each item in the ArrayList and add it to the HTML string foreach (var item in itemList) { htmlContent += $"<li>{item}</li>"; } htmlContent += "</ul>"; // Convert the HTML string to a PDF document var PDF = Renderer.RenderHtmlAsPdf(htmlContent); // Save the PDF to a file PDF.SaveAs("ItemList.pdf"); Console.WriteLine("PDF file 'ItemList.pdf' has been generated."); } } $vbLabelText $csharpLabel In this example, we start by creating an ArrayList named itemList and populating it with several string items. Next, we initialize a new instance of IronPDF's ChromePdfRenderer class, which we'll use to convert HTML content into a PDF document. Output Here is the output PDF generated by IronPDF: Conclusion The ArrayList is a powerful collection offered by C# for storing a list of objects. Its ability to adjust size dynamically and store elements of any type makes it versatile for a wide range of applications. However, for type safety and better performance, generic collections are recommended. Experimenting with the ArrayList and its methods will help you understand its uses and how it can fit into your applications. Additionally, for those interested in expanding their C# capabilities into PDF manipulation, IronPDF offers a free trial for PDF Functions in .NET to explore its features. Licenses start from $799, providing a comprehensive solution for integrating PDF functionality into .NET applications. 자주 묻는 질문 C#에서 ArrayList를 PDF로 변환하려면 어떻게 해야 하나요? IronPDF를 사용하여 C#의 ArrayList에서 PDF를 생성할 수 있습니다. ArrayList를 반복하여 내용을 PDF 생성에 적합한 형식으로 컴파일한 다음 IronPDF의 메서드를 사용하여 PDF를 생성하고 저장합니다. ArrayLists와 함께 IronPDF를 사용하면 어떤 이점이 있나요? IronPDF를 사용하면 개발자가 ArrayLists에 저장된 데이터를 PDF 문서로 쉽게 변환할 수 있습니다. 이는 최소한의 코드와 최대의 효율로 보고서를 만들거나 항목 목록을 내보내는 데 유용합니다. ArrayList에서 생성된 PDF에 텍스트와 이미지를 추가할 수 있나요? 예, IronPDF를 사용하면 배열 목록의 항목을 반복하면서 텍스트, 이미지 및 기타 콘텐츠를 추가하여 PDF를 사용자 지정할 수 있습니다. C#의 ArrayList에서 생성된 PDF를 보호할 수 있나요? IronPDF는 PDF 문서를 안전하게 보호하는 기능을 제공합니다. 비밀번호와 권한을 설정하여 배열 목록의 데이터에서 생성된 PDF에 대한 액세스 및 편집을 제한할 수 있습니다. PDF 라이브러리와 통합할 때 동적 크기 조정이 ArrayList에 어떤 이점이 있나요? 배열 목록의 동적 크기 조정 기능을 사용하면 용량에 대한 걱정 없이 필요에 따라 요소를 추가하거나 제거할 수 있습니다. 이러한 유연성은 IronPDF와 같은 라이브러리를 사용하여 PDF 생성을 위한 데이터를 준비할 때 유용합니다. C# 개발자를 위해 IronPDF를 사용하면 어떤 이점이 있나요? IronPDF는 C# 개발자에게 PDF 문서 생성 및 조작을 위한 강력한 도구 세트를 제공합니다. HTML에서 PDF로 변환, 주석 추가, 여러 PDF 병합과 같은 다양한 기능을 지원하므로 .NET 애플리케이션에 필수적인 라이브러리입니다. PDF를 만들 때 ArrayList에서 다양한 데이터 유형을 처리하려면 어떻게 해야 하나요? ArrayList는 모든 데이터 유형을 저장할 수 있으므로 IronPDF를 사용하여 ArrayList를 반복하고 필요한 변환을 적용하여 이러한 다양한 데이터 유형을 일관된 PDF 문서로 포맷하고 변환할 수 있습니다. ArrayLists와 함께 IronPDF를 사용하기 위한 문제 해결 팁은 무엇인가요? PDF로 변환하기 전에 배열 목록의 데이터 형식이 올바른지 확인하세요. Null 값과 호환되지 않는 데이터 유형이 있는지 확인하고 IronPDF 디버깅 도구를 사용하여 PDF 생성 과정에서 발생하는 모든 문제를 식별하고 해결하세요. 커티스 차우 지금 바로 엔지니어링 팀과 채팅하세요 기술 문서 작성자 커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다. 커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다. 관련 기사 업데이트됨 12월 11, 2025 Bridging CLI Simplicity & .NET : Using Curl DotNet with IronPDF Jacob Mellor has bridged this gap with CurlDotNet, a library created to bring the familiarity of cURL to the .NET ecosystem. 더 읽어보기 업데이트됨 12월 20, 2025 RandomNumberGenerator C# Using the RandomNumberGenerator C# class can help take your PDF generation and editing projects to the next level 더 읽어보기 업데이트됨 12월 20, 2025 C# String Equals (How it Works for Developers) When combined with a powerful PDF library like IronPDF, switch pattern matching allows you to build smarter, cleaner logic for document processing 더 읽어보기 Math.Round C# (How It Works For Developers)C# Linter (How It Works For Developers)
업데이트됨 12월 11, 2025 Bridging CLI Simplicity & .NET : Using Curl DotNet with IronPDF Jacob Mellor has bridged this gap with CurlDotNet, a library created to bring the familiarity of cURL to the .NET ecosystem. 더 읽어보기
업데이트됨 12월 20, 2025 RandomNumberGenerator C# Using the RandomNumberGenerator C# class can help take your PDF generation and editing projects to the next level 더 읽어보기
업데이트됨 12월 20, 2025 C# String Equals (How it Works for Developers) When combined with a powerful PDF library like IronPDF, switch pattern matching allows you to build smarter, cleaner logic for document processing 더 읽어보기