.NET 도움말 C# iList (How It Works For Developers) 커티스 차우 업데이트됨:7월 28, 2025 다운로드 IronPDF NuGet 다운로드 DLL 다운로드 윈도우 설치 프로그램 무료 체험 시작하기 LLM용 사본 LLM용 사본 LLM용 마크다운 형식으로 페이지를 복사하세요 ChatGPT에서 열기 ChatGPT에 이 페이지에 대해 문의하세요 제미니에서 열기 제미니에게 이 페이지에 대해 문의하세요 Grok에서 열기 Grok에게 이 페이지에 대해 문의하세요 혼란 속에서 열기 Perplexity에게 이 페이지에 대해 문의하세요 공유하다 페이스북에 공유하기 트위터에 공유하기 LinkedIn에 공유하기 URL 복사 이메일로 기사 보내기 Introduction to the IList IList is a part of the .NET Framework's Collections namespace. It is a non-generic collection interface that provides the blueprint for a collection of objects that can be individually accessed by their index. Unlike arrays, IList allows for a dynamic number of object value elements, meaning you can add or remove elements from the collection as needed. It serves as the base interface for all non-generic lists in the .NET Framework, offering a way to manage a collection of objects in a more flexible manner than arrays. We'll learn about the IList interface and the IronPDF C# PDF Library in this tutorial. Understanding the IList Interface The public interface IList declaration is a fundamental part of creating custom collections in C# that adhere to the IList contract specified by the .NET Framework's Collections namespace. IList includes properties and methods that enable accessing elements in the collection, counting them, and modifying the collection by adding, inserting, or removing elements. Here are some of the key properties and methods defined in the IList interface: Properties like IsFixedSize and IsReadOnly inform whether the collection is of fixed size or read-only, respectively. Methods such as Add, Insert, Remove, and RemoveAt are used for modifying elements within the collection. You can add, insert, and remove elements. The IndexOf method is for locating elements, and the Item property (or indexer in C#) allows for the getting and setting of elements based on their index. Practical Usage of the IList Interface To showcase how IList works, let's create a simple example. This example will demonstrate how to declare an IList, add items to it, and iterate over its contents. Creating and Modifying an IList First, let's see how to declare an IList and add items to it: using System; using System.Collections; class Program { static void Main(string[] args) { // Creating an IList instance IList myIList = new ArrayList(); // Adding elements to the IList myIList.Add("Hello"); myIList.Add(10); myIList.Add(new object()); // Displaying the number of values in the IList using the Count property Console.WriteLine($"Number of elements: {myIList.Count}"); // Accessing elements using a loop foreach (var element in myIList) { Console.WriteLine(element); } } } using System; using System.Collections; class Program { static void Main(string[] args) { // Creating an IList instance IList myIList = new ArrayList(); // Adding elements to the IList myIList.Add("Hello"); myIList.Add(10); myIList.Add(new object()); // Displaying the number of values in the IList using the Count property Console.WriteLine($"Number of elements: {myIList.Count}"); // Accessing elements using a loop foreach (var element in myIList) { Console.WriteLine(element); } } } $vbLabelText $csharpLabel In the above example, we've created an IList instance using ArrayList, a class that implements IList. We've added a mix of different types of objects to demonstrate that an IList can hold any object. Finally, we've iterated over the collection, printing out each element. Index-Based Access and Modification Accessing and modifying elements by their index is a key feature of IList. The following example shows how you can do it: using System; using System.Collections; class Program { static void Main(string[] args) { IList myIList = new ArrayList { "Hello", 10, new object() }; // Accessing an element by index object value = myIList[1]; Console.WriteLine($"Element at index 1: {value}"); // Modifying an element by index myIList[1] = 20; Console.WriteLine($"Modified element at index 1: {myIList[1]}"); } } using System; using System.Collections; class Program { static void Main(string[] args) { IList myIList = new ArrayList { "Hello", 10, new object() }; // Accessing an element by index object value = myIList[1]; Console.WriteLine($"Element at index 1: {value}"); // Modifying an element by index myIList[1] = 20; Console.WriteLine($"Modified element at index 1: {myIList[1]}"); } } $vbLabelText $csharpLabel Implementing a Custom IList Sometimes, you might need a tailored collection that inherits IList. This allows for more control over how elements are stored, accessed, and modified. Below is an example of a simple custom collection implementing IList: using System; using System.Collections; public class CustomCollection : IList { private ArrayList _innerList = new ArrayList(); public object this[int index] { get => _innerList[index]; set => _innerList[index] = value; } public bool IsFixedSize => _innerList.IsFixedSize; public bool IsReadOnly => _innerList.IsReadOnly; public int Count => _innerList.Count; public bool IsSynchronized => _innerList.IsSynchronized; public object SyncRoot => _innerList.SyncRoot; public int Add(object value) { return _innerList.Add(value); } public void Clear() { _innerList.Clear(); } public bool Contains(object value) { return _innerList.Contains(value); } public int IndexOf(object value) { return _innerList.IndexOf(value); } public void Insert(int index, object value) { _innerList.Insert(index, value); } public void Remove(object value) { _innerList.Remove(value); } public void RemoveAt(int index) { _innerList.RemoveAt(index); } public void CopyTo(Array array, int index) { _innerList.CopyTo(array, index); } public IEnumerator GetEnumerator() { return _innerList.GetEnumerator(); } } using System; using System.Collections; public class CustomCollection : IList { private ArrayList _innerList = new ArrayList(); public object this[int index] { get => _innerList[index]; set => _innerList[index] = value; } public bool IsFixedSize => _innerList.IsFixedSize; public bool IsReadOnly => _innerList.IsReadOnly; public int Count => _innerList.Count; public bool IsSynchronized => _innerList.IsSynchronized; public object SyncRoot => _innerList.SyncRoot; public int Add(object value) { return _innerList.Add(value); } public void Clear() { _innerList.Clear(); } public bool Contains(object value) { return _innerList.Contains(value); } public int IndexOf(object value) { return _innerList.IndexOf(value); } public void Insert(int index, object value) { _innerList.Insert(index, value); } public void Remove(object value) { _innerList.Remove(value); } public void RemoveAt(int index) { _innerList.RemoveAt(index); } public void CopyTo(Array array, int index) { _innerList.CopyTo(array, index); } public IEnumerator GetEnumerator() { return _innerList.GetEnumerator(); } } $vbLabelText $csharpLabel This CustomCollection class encapsulates an ArrayList, a class that itself implements IList. Our CustomCollection forwards calls to the underlying ArrayList, allowing it to behave like any other collection that implements IList. This example demonstrates creating a collection that can be accessed by index, modified (items added, inserted, or removed), and iterated over, just like any built-in .NET collection that implements IList. Advanced Operations with IList Beyond basic add, remove, and access operations, IList allows for more complex manipulations and queries. For instance, checking if the collection contains a specific object or finding the index of an object within the collection are operations that can be essential for certain applications: using System; using System.Collections; class Program { static void Main(string[] args) { IList myIList = new ArrayList { "Hello", 10, new object() }; // Check if the IList contains a specific object bool contains = myIList.Contains(10); // Assuming 10 was added previously Console.WriteLine($"Contains 10: {contains}"); // Find the index of a specific object int index = myIList.IndexOf(10); Console.WriteLine($"Index of 10: {index}"); } } using System; using System.Collections; class Program { static void Main(string[] args) { IList myIList = new ArrayList { "Hello", 10, new object() }; // Check if the IList contains a specific object bool contains = myIList.Contains(10); // Assuming 10 was added previously Console.WriteLine($"Contains 10: {contains}"); // Find the index of a specific object int index = myIList.IndexOf(10); Console.WriteLine($"Index of 10: {index}"); } } $vbLabelText $csharpLabel These operations can be particularly useful when dealing with collections of objects where you need to determine the presence or position of specific items without iterating over the entire collection. IronPDF: C# PDF Library IronPDF is a PDF library for .NET developers that allows for the creation and manipulation of PDF documents directly within .NET applications. It supports converting HTML to PDF documents, images, and web pages to PDF. Developers can easily add PDF functionalities to their applications with this library. IronPDF also includes features for editing, merging, and splitting PDF files, which provide comprehensive control over PDF manipulation. IronPDF excels in HTML to PDF conversion, ensuring precise preservation of original layouts and styles. It's perfect for creating PDFs from web-based content such as reports, invoices, and documentation. With support for HTML files, URLs, and raw HTML strings, IronPDF easily produces high-quality PDF documents. using IronPdf; class Program { static void Main(string[] args) { var renderer = new ChromePdfRenderer(); // 1. Convert HTML String to PDF var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>"; var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent); pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf"); // 2. Convert HTML File to PDF var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath); pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf"); // 3. Convert URL to PDF var url = "http://ironpdf.com"; // Specify the URL var pdfFromUrl = renderer.RenderUrlAsPdf(url); pdfFromUrl.SaveAs("URLToPDF.pdf"); } } using IronPdf; class Program { static void Main(string[] args) { var renderer = new ChromePdfRenderer(); // 1. Convert HTML String to PDF var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>"; var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent); pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf"); // 2. Convert HTML File to PDF var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath); pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf"); // 3. Convert URL to PDF var url = "http://ironpdf.com"; // Specify the URL var pdfFromUrl = renderer.RenderUrlAsPdf(url); pdfFromUrl.SaveAs("URLToPDF.pdf"); } } $vbLabelText $csharpLabel Code Example Here is a straightforward example that demonstrates generating a simple PDF document from a list of strings using IronPDF and the IList interface: using IronPdf; using System.Collections.Generic; public class PDFGenerator { public static void GeneratePDFFromList(IList<string> dataList) { // Initialize the HtmlToPdf renderer var renderer = new ChromePdfRenderer(); // Start building HTML content from the dataList var htmlContent = "<h1>My Data List</h1><ul>"; foreach (var item in dataList) { htmlContent += $"<li>{item}</li>"; } htmlContent += "</ul>"; // Convert HTML string to PDF var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent); // Save the PDF to a file pdfDocument.SaveAs("DataList.pdf"); } } // Example usage class Program { static void Main(string[] args) { License.LicenseKey = "License-Key"; IList<string> myDataList = new List<string> { "Apple", "Banana", "Cherry" }; PDFGenerator.GeneratePDFFromList(myDataList); } } using IronPdf; using System.Collections.Generic; public class PDFGenerator { public static void GeneratePDFFromList(IList<string> dataList) { // Initialize the HtmlToPdf renderer var renderer = new ChromePdfRenderer(); // Start building HTML content from the dataList var htmlContent = "<h1>My Data List</h1><ul>"; foreach (var item in dataList) { htmlContent += $"<li>{item}</li>"; } htmlContent += "</ul>"; // Convert HTML string to PDF var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent); // Save the PDF to a file pdfDocument.SaveAs("DataList.pdf"); } } // Example usage class Program { static void Main(string[] args) { License.LicenseKey = "License-Key"; IList<string> myDataList = new List<string> { "Apple", "Banana", "Cherry" }; PDFGenerator.GeneratePDFFromList(myDataList); } } $vbLabelText $csharpLabel In this example, an IList<string> is used to store a collection of fruit names. The GeneratePDFFromList method then iterates over this list, building an HTML string that includes each item in an unordered list. IronPDF's ChromePdfRenderer converts this HTML content into a PDF document, which is subsequently saved to a file. Conclusion This beginner-friendly guide aimed to cover the basics and practical uses of IList in C#. With examples ranging from simple usage to custom implementation, it's clear that IList is a powerful tool in the C# developer's toolkit. Whether you're manipulating collections of data or building your collection types, IList offers the functionality and flexibility needed for effective software development. IronPDF offers a free trial of its PDF library for interested users, with licenses available starting from $799. 자주 묻는 질문 C#의 IList 인터페이스는 무엇인가요? 'IList' 인터페이스는 인덱스로 액세스할 수 있는 동적 컬렉션을 만드는 데 사용되는 .NET Framework의 컬렉션 네임스페이스의 일부입니다. 이 인터페이스는 요소를 추가, 삽입, 제거 및 액세스하는 메서드를 제공하여 정적 배열보다 더 많은 유연성을 제공합니다. C#에서 HTML을 PDF로 변환하려면 어떻게 해야 하나요? IronPDF의 `RenderHtmlAsPdf` 메서드를 사용하여 C#에서 HTML을 PDF로 변환할 수 있습니다. 이를 통해 HTML 문자열, 파일 또는 URL을 고품질 PDF 문서로 변환할 수 있습니다. IList 인터페이스의 주요 방법은 무엇인가요? IList` 인터페이스의 주요 메서드에는 `Add`, `Insert`, `Remove`, `RemoveAt` 및 `IndexOf`가 있습니다. 이러한 메서드는 컬렉션 내의 요소를 동적으로 관리하고 수정하는 데 필수적입니다. C#에서 사용자 지정 IList는 어떻게 만들 수 있나요? C#에서 사용자 지정 `IList`를 만들려면 클래스에서 `IList` 인터페이스를 구현하여 `Add`, `Remove`, `IndexOf`와 같은 필요한 메서드와 속성을 재정의하여 컬렉션의 요소 처리 방식을 사용자 지정할 수 있습니다. IronPDF는 HTML에서 PDF를 어떻게 생성하나요? IronPDF는 `ChromePdfRenderer` 클래스를 사용하여 HTML 콘텐츠를 PDF로 변환합니다. HTML 문자열, 파일 또는 URL에서 변환을 지원하여 웹 콘텐츠에서 정확한 PDF 생성을 보장합니다. 데이터 목록에서 PDF를 생성할 수 있나요? 예, 목록을 반복하여 HTML 문자열을 구성한 다음 IronPDF의 `ChromePdfRenderer`를 사용하여 HTML을 PDF 문서로 변환하여 `SaveAs` 메서드를 사용하여 저장할 수 있는 IList에서 PDF를 생성할 수 있습니다. IList는 어떤 고급 작업을 지원하나요? IList`의 고급 작업에는 `Contains`를 사용하여 컬렉션에 특정 개체가 포함되어 있는지 확인하고 `IndexOf`를 사용하여 개체의 인덱스를 찾는 작업이 포함됩니다. 이러한 기능을 사용하면 요소를 수동으로 검색할 필요 없이 컬렉션을 효율적으로 관리할 수 있습니다. C#에서 PDF 생성 문제를 어떻게 해결할 수 있나요? C#에서 PDF 생성 시 문제가 발생하면 HTML 콘텐츠의 형식이 올바르게 지정되어 있는지, 최신 버전의 IronPDF를 사용하고 있는지 확인하세요. 변환 과정에서 발생한 예외가 있는지 확인하여 추가 정보를 얻으세요. 커티스 차우 지금 바로 엔지니어링 팀과 채팅하세요 기술 문서 작성자 커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, 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 더 읽어보기 C# Linked List (How It Works For Developers)Polly Retry (How It Works For Devel...
업데이트됨 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 더 읽어보기