.NET 도움말 C# LINQ Distinct (How It Works For Developers) 커티스 차우 업데이트됨:6월 22, 2025 다운로드 IronPDF NuGet 다운로드 DLL 다운로드 윈도우 설치 프로그램 무료 체험 시작하기 LLM용 사본 LLM용 사본 LLM용 마크다운 형식으로 페이지를 복사하세요 ChatGPT에서 열기 ChatGPT에 이 페이지에 대해 문의하세요 제미니에서 열기 제미니에게 이 페이지에 대해 문의하세요 Grok에서 열기 Grok에게 이 페이지에 대해 문의하세요 혼란 속에서 열기 Perplexity에게 이 페이지에 대해 문의하세요 공유하다 페이스북에 공유하기 트위터에 공유하기 LinkedIn에 공유하기 URL 복사 이메일로 기사 보내기 Language-integrated query (LINQ), a potent language feature in C#, enables programmers to create clear, expressive queries for a variety of data sources. This post will discuss the use of IronPDF, a versatile C# library for working with PDF documents, using LINQ's Distinct function. We will show how this combination may make the process of creating unique documents from a collection easier. In this article, we are going to learn about the C# LINQ distinct function with IronPDF. How to Use C# LINQ Distinct Method Create a new console project. Import System.Linq namespace. Create a list with multiple items. Call the method Distinct() from the List. Get the unique values and display the result on the console. Dispose of all the created objects. What is LINQ Developers may build clear and expressive queries for data manipulation directly in their code with C#'s LINQ (Language Integrated Query) feature. First included in the .NET Framework 3.5, LINQ offers a standard syntax for querying a range of data sources, including databases and collections. LINQ makes simple tasks like filtering and projection easier using operators like Where and Select, which improves code readability. Because it allows for delayed execution for optimal speed, this feature is crucial for C# developers to ensure that data manipulation operations are completed quickly and naturally in a manner analogous to SQL. Understanding LINQ Distinct Duplicate elements may be removed from a collection or sequence using LINQ's Distinct function. In the absence of a custom equality comparer, it compares items using their default comparer. This makes it a great option in situations when you need to work with a unique collection and remove duplicate components. The Distinct technique uses the default equality comparers to evaluate values. It will exclude duplicates to return only unique elements. Basic Usage To obtain distinct items, the simplest way to use it is to use the Distinct method directly on a collection. using System.Linq; using System.Collections.Generic; public class DistinctExample { public static void Example() { // Example list with duplicate integers List<int> numbers = new List<int> { 1, 2, 2, 3, 4, 4, 5 }; // Using Distinct to remove duplicates var distinctNumbers = numbers.Distinct(); // Display the distinct numbers foreach (var number in distinctNumbers) { Console.WriteLine(number); } } } using System.Linq; using System.Collections.Generic; public class DistinctExample { public static void Example() { // Example list with duplicate integers List<int> numbers = new List<int> { 1, 2, 2, 3, 4, 4, 5 }; // Using Distinct to remove duplicates var distinctNumbers = numbers.Distinct(); // Display the distinct numbers foreach (var number in distinctNumbers) { Console.WriteLine(number); } } } $vbLabelText $csharpLabel Custom Equality Comparer You can define a custom equality comparison by using an overload of the Distinct function. This is helpful if you wish to compare items according to particular standards. Please refer to the following example: using System; using System.Collections.Generic; using System.Linq; public class Person { public string FirstName { get; set; } public string LastName { get; set; } } public class PersonEqualityComparer : IEqualityComparer<Person> { public bool Equals(Person x, Person y) { return x.FirstName == y.FirstName && x.LastName == y.LastName; } public int GetHashCode(Person obj) { return obj.FirstName.GetHashCode() ^ obj.LastName.GetHashCode(); } } public class DistinctCustomComparerExample { public static void Example() { // Example list of people List<Person> people = new List<Person> { new Person { FirstName = "John", LastName = "Doe" }, new Person { FirstName = "Jane", LastName = "Doe" }, new Person { FirstName = "John", LastName = "Doe" } }; // Using Distinct with a custom equality comparer var distinctPeople = people.Distinct(new PersonEqualityComparer()); // Display distinct people foreach (var person in distinctPeople) { Console.WriteLine($"{person.FirstName} {person.LastName}"); } } } using System; using System.Collections.Generic; using System.Linq; public class Person { public string FirstName { get; set; } public string LastName { get; set; } } public class PersonEqualityComparer : IEqualityComparer<Person> { public bool Equals(Person x, Person y) { return x.FirstName == y.FirstName && x.LastName == y.LastName; } public int GetHashCode(Person obj) { return obj.FirstName.GetHashCode() ^ obj.LastName.GetHashCode(); } } public class DistinctCustomComparerExample { public static void Example() { // Example list of people List<Person> people = new List<Person> { new Person { FirstName = "John", LastName = "Doe" }, new Person { FirstName = "Jane", LastName = "Doe" }, new Person { FirstName = "John", LastName = "Doe" } }; // Using Distinct with a custom equality comparer var distinctPeople = people.Distinct(new PersonEqualityComparer()); // Display distinct people foreach (var person in distinctPeople) { Console.WriteLine($"{person.FirstName} {person.LastName}"); } } } $vbLabelText $csharpLabel Using Distinct with Value Types You don't need to supply a custom equality comparison when using the Distinct method with value types. using System; using System.Collections.Generic; using System.Linq; public class DistinctValueTypeExample { public static void Example() { List<int> integers = new List<int> { 1, 2, 2, 3, 4, 4, 5 }; // Using Distinct to remove duplicates var distinctIntegers = integers.Distinct(); // Display distinct integers foreach (var integer in distinctIntegers) { Console.WriteLine(integer); } } } using System; using System.Collections.Generic; using System.Linq; public class DistinctValueTypeExample { public static void Example() { List<int> integers = new List<int> { 1, 2, 2, 3, 4, 4, 5 }; // Using Distinct to remove duplicates var distinctIntegers = integers.Distinct(); // Display distinct integers foreach (var integer in distinctIntegers) { Console.WriteLine(integer); } } } $vbLabelText $csharpLabel Using Distinct with Anonymous Types Distinct may be used with anonymous types to remove duplicates based on particular attributes. Please refer to the following example: using System; using System.Collections.Generic; using System.Linq; public class Person { public string FirstName { get; set; } public string LastName { get; set; } } public class DistinctAnonymousTypesExample { public static void Example() { List<Person> people = new List<Person> { new Person { FirstName = "John", LastName = "Doe" }, new Person { FirstName = "Jane", LastName = "Doe" }, new Person { FirstName = "John", LastName = "Doe" } }; // Using Distinct with anonymous types var distinctPeople = people .Select(p => new { p.FirstName, p.LastName }) .Distinct(); // Display distinct anonymous types foreach (var person in distinctPeople) { Console.WriteLine($"{person.FirstName} {person.LastName}"); } } } using System; using System.Collections.Generic; using System.Linq; public class Person { public string FirstName { get; set; } public string LastName { get; set; } } public class DistinctAnonymousTypesExample { public static void Example() { List<Person> people = new List<Person> { new Person { FirstName = "John", LastName = "Doe" }, new Person { FirstName = "Jane", LastName = "Doe" }, new Person { FirstName = "John", LastName = "Doe" } }; // Using Distinct with anonymous types var distinctPeople = people .Select(p => new { p.FirstName, p.LastName }) .Distinct(); // Display distinct anonymous types foreach (var person in distinctPeople) { Console.WriteLine($"{person.FirstName} {person.LastName}"); } } } $vbLabelText $csharpLabel Distinct by a Specific Property When working with objects, you may either create your logic for distinguishing by a certain attribute, or you can utilize the DistinctBy extension method from third-party libraries (like MoreLINQ). // Ensure to include the MoreLINQ Library using MoreLinq; using System; using System.Collections.Generic; using System.Linq; public class Person { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } public class DistinctByExample { public static void Example() { List<Person> people = new List<Person> { new Person { Id = 1, FirstName = "John", LastName = "Doe" }, new Person { Id = 2, FirstName = "Jane", LastName = "Doe" }, new Person { Id = 1, FirstName = "John", LastName = "Doe" } }; // Using DistinctBy to filter distinct people by Id var distinctPeople = people.DistinctBy(p => p.Id); // Display distinct people foreach (var person in distinctPeople) { Console.WriteLine($"{person.Id}: {person.FirstName} {person.LastName}"); } } } // Ensure to include the MoreLINQ Library using MoreLinq; using System; using System.Collections.Generic; using System.Linq; public class Person { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } } public class DistinctByExample { public static void Example() { List<Person> people = new List<Person> { new Person { Id = 1, FirstName = "John", LastName = "Doe" }, new Person { Id = 2, FirstName = "Jane", LastName = "Doe" }, new Person { Id = 1, FirstName = "John", LastName = "Doe" } }; // Using DistinctBy to filter distinct people by Id var distinctPeople = people.DistinctBy(p => p.Id); // Display distinct people foreach (var person in distinctPeople) { Console.WriteLine($"{person.Id}: {person.FirstName} {person.LastName}"); } } } $vbLabelText $csharpLabel IronPDF Programmers may create, edit, and alter PDF documents using the C# language with the aid of the .NET library IronPDF Website. The program provides a range of tools and functionalities to enable various tasks involving PDF files, such as generating PDFs from HTML, converting HTML to PDF, merging or splitting PDF documents, and adding text, images, and annotations to already existing PDFs. To know more about IronPDF, please refer to their IronPDF Documentation. The main feature of IronPDF is HTML to PDF Conversion, which keeps your layouts and styles intact. You can generate PDFs from web content, perfect for reports, invoices, and documentation. It supports converting HTML files, URLs, and HTML strings to PDF files. 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 Features of IronPDF Convert HTML to PDF: You may use IronPDF to convert any kind of HTML data—including files, URLs, and strings of HTML code—into PDF documents. PDF Generation: Text, images, and other elements may be programmatically added to PDF documents using the C# programming language. PDF Manipulation: IronPDF can split a PDF file into many files, merge several PDF documents into one file, and edit PDFs that already exist. PDF Forms: The library enables users to build and fill PDF forms, making it useful in scenarios where form data needs to be gathered and processed. Security Features: IronPDF may be used to encrypt PDF documents and provide password and permission protection. Text Extraction: Text from PDF files may be extracted using IronPDF. Install IronPDF Get the IronPDF library; it's needed for setting up your project. Enter the following code into the NuGet Package Manager Console to accomplish this: Install-Package IronPdf Using the NuGet Package Manager to search for the package "IronPDF" is an additional choice. We may choose and download the necessary package from this list out of all the NuGet packages associated with IronPDF. LINQ With IronPDF Consider a situation in which you have a set of data and you wish to create various PDF documents according to different values in that set. This is where the usefulness of LINQ's Distinct shines, particularly when used with IronPDF to create documents quickly. Generating Distinct PDFs with LINQ and IronPDF using IronPdf; using System; using System.Collections.Generic; using System.Linq; public class DocumentGenerator { public static void Main() { // Sample data representing categories List<string> categories = new List<string> { "Technology", "Business", "Health", "Technology", "Science", "Business", "Health" }; // Use LINQ Distinct to filter out duplicate values var distinctCategories = categories.Distinct(); // Generate a distinct elements PDF document for each category foreach (var category in distinctCategories) { GeneratePdfDocument(category); } } private static void GeneratePdfDocument(string category) { // Create a new PDF document using IronPDF IronPdf.HtmlToPdf renderer = new IronPdf.HtmlToPdf(); PdfDocument pdf = renderer.RenderHtmlAsPdf($"<h1>{category} Report</h1>"); // Save the PDF to a file string pdfFilePath = $"{category}_Report.pdf"; pdf.SaveAs(pdfFilePath); // Display a message with the file path Console.WriteLine($"PDF generated successfully. File saved at: {pdfFilePath}"); } } using IronPdf; using System; using System.Collections.Generic; using System.Linq; public class DocumentGenerator { public static void Main() { // Sample data representing categories List<string> categories = new List<string> { "Technology", "Business", "Health", "Technology", "Science", "Business", "Health" }; // Use LINQ Distinct to filter out duplicate values var distinctCategories = categories.Distinct(); // Generate a distinct elements PDF document for each category foreach (var category in distinctCategories) { GeneratePdfDocument(category); } } private static void GeneratePdfDocument(string category) { // Create a new PDF document using IronPDF IronPdf.HtmlToPdf renderer = new IronPdf.HtmlToPdf(); PdfDocument pdf = renderer.RenderHtmlAsPdf($"<h1>{category} Report</h1>"); // Save the PDF to a file string pdfFilePath = $"{category}_Report.pdf"; pdf.SaveAs(pdfFilePath); // Display a message with the file path Console.WriteLine($"PDF generated successfully. File saved at: {pdfFilePath}"); } } $vbLabelText $csharpLabel In this example, a series of distinct categories are obtained by using the Distinct method for the categories collection. It helps to remove duplicate elements from a sequence. Next, IronPDF is used to create a PDF document with these unique elements. This method guarantees that separate PDF documents are produced solely for unique categories. Console OUTPUT Generated PDF Output To know more about the IronPDF code example for generating PDFs using HTML refer to the IronPDF HTML to PDF Example Code. Conclusion LINQ's Distinct extension method in conjunction with IronPDF offers a robust and efficient mechanism for creating unique PDF documents based on values. This method streamlines the code and guarantees effective document production whether you are working with categories, tags, or any other data where separate documents are needed. You may develop a reliable and expressive solution for managing different aspects of your C# applications by utilizing LINQ for data processing and IronPDF for document production. When using these strategies for your projects, keep in mind the particular needs of your application and adjust the implementation to achieve maximum dependability and performance. 자주 묻는 질문 C#의 컬렉션에서 중복 항목을 제거하려면 어떻게 해야 하나요? C#의 컬렉션에서 중복 항목을 제거하려면 LINQ의 Distinct 메서드를 사용할 수 있습니다. 이 메서드는 고유한 데이터 범주에서 고유한 PDF 문서를 생성하기 위해 IronPDF와 결합할 때 특히 유용합니다. C#에서 HTML을 PDF로 변환하려면 어떻게 해야 하나요? C#에서 HTML을 PDF로 변환하려면 IronPDF의 RenderHtmlAsPdf 메서드를 사용할 수 있습니다. 이를 통해 HTML 문자열이나 파일을 PDF 문서로 효율적으로 변환할 수 있습니다. 사용자 지정 객체와 함께 LINQ의 Distinct 메서드를 사용할 수 있나요? 예, 사용자 지정 동일성 비교기를 제공하여 사용자 지정 객체와 함께 LINQ의 Distinct 메서드를 사용할 수 있습니다. 이는 IronPDF를 사용한 PDF 생성 프로세스에서 고유성을 결정하기 위한 특정 기준을 정의해야 할 때 유용합니다. IronPDF와 함께 LINQ를 사용하면 어떤 이점이 있나요? 개발자는 IronPDF와 함께 LINQ를 사용하면 데이터 처리를 기반으로 고유하고 효율적인 PDF 문서를 만들 수 있습니다. 특히 대규모 문서 생성 작업을 관리할 때 코드 가독성과 성능이 향상됩니다. LINQ의 Distinct 방식은 PDF 문서 생성을 어떻게 향상시킬 수 있나요? LINQ의 고유 메서드는 최종 출력에 고유한 항목만 포함되도록 하여 PDF 문서 생성을 향상시킬 수 있습니다. 이 메서드는 IronPDF와 함께 사용하여 다양한 데이터 범주에 대해 고유한 PDF 문서를 생성할 수 있습니다. IronPDF를 사용할 때 PDF 출력을 사용자 지정할 수 있나요? 예, IronPDF는 페이지 크기, 여백 설정, 머리글 또는 바닥글 추가 등 PDF 출력을 사용자 지정할 수 있는 다양한 옵션을 제공합니다. 이러한 사용자 지정 기능을 LINQ와 결합하여 맞춤형 고유 문서 출력을 만들 수 있습니다. PDF에 LINQ의 Distinct 방식을 사용하면 어떤 시나리오에서 이점을 얻을 수 있나요? 보고서, 송장 또는 데이터 세트에서 고유성이 필요한 문서를 생성하는 등의 시나리오에서는 PDF와 함께 LINQ의 Distinct 방법을 사용하면 이점을 얻을 수 있습니다. IronPDF를 활용하면 깔끔하고 고유한 PDF 출력을 효율적으로 생성할 수 있습니다. LINQ는 데이터 기반 PDF 애플리케이션의 효율성을 어떻게 개선하나요? LINQ는 개발자가 PDF를 생성하기 전에 데이터 세트를 필터링하고 조작할 수 있도록 하여 데이터 기반 PDF 애플리케이션의 효율성을 향상시킵니다. 이를 통해 꼭 필요한 고유 데이터만 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 더 읽어보기 C# Internal (How It Works For Developers)C# Priority Queue (How It Works For...
업데이트됨 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 더 읽어보기