Altbilgi içeriğine atla
.NET YARDıM

C# LINQ Distinct (Geliştiriciler için Nasıl Çalışır)

Dil ile entegre sorgulama (LINQ), C#'ta güçlü bir dil özelliği olup, programcıların çeşitli veri kaynakları için net, ifade edici sorgular oluşturmalarına olanak tanır. Bu makale, PDF belgeleri ile çalışmak için çok yönlü bir C# kütüphanesi olan IronPDF'nin kullanımı hakkında konuşacak, LINQ'un Distinct işlevini kullanarak. Bu kombinasyonun, bir koleksiyondan benzersiz belgeler oluşturma sürecini nasıl kolaylaştırabileceğini göstereceğiz. Bu makalede, IronPDF ile C# LINQ distinct fonksiyonunu öğreneceğiz.

C# LINQ Distinct Yöntemi Nasıl Kullanılır

  1. Yeni bir konsol projesi oluşturun.
  2. System.Linq ad alanını içe aktarın.
  3. Birden fazla elemanı olan bir liste oluşturun.
  4. Listedeki yöntemi Distinct() çağırın.
  5. Benzersiz değerleri alın ve sonucu konsolda gösterin.
  6. Oluşturulan tüm nesneleri kapatın.

LINQ Nedir

Geliştiriciler, C#'ın LINQ (Dil Entegre Sorgu) özelliği ile verileri işlemek için kodlarında doğrudan net ve ifade edici sorgular oluşturabilirler. İlk olarak .NET Framework 3.5'te yer alan LINQ, veritabanları ve koleksiyonlar dahil olmak üzere birçok veri kaynağı için standart bir sorgu sözdizimi sunar. LINQ, basit görevleri filtreleme ve projeksiyon gibi operatörlerle Where ve Select kullanarak daha kolay hale getirir ve bu da kod okunabilirliğini artırır. Veri manipülasyonu işlemlerinin hızlı ve doğal bir şekilde tamamlanmasını sağlamak için gecikmeli yürütme sunması sebebiyle, bu özellik C# geliştiricileri için SQL benzeri bir şekilde kritik öneme sahiptir.

LINQ Distinct Anlamak

Yinelenen elemanlar, LINQ'un Distinct fonksiyonu kullanılarak bir koleksiyon veya diziden kaldırılabilir. Özel bir eşitlik karşılaştırıcısı bulunmadığında, öğeleri varsayılan karşılaştırıcısını kullanarak karşılaştırır. Bu, benzersiz bir koleksiyonla çalışmanız gerektiğinde ve yinelenen bileşenleri kaldırmanız gereken durumlar için harika bir seçenektir. Distinct tekniği, değerleri değerlendirmek için varsayılan eşitlik karşılaştırıcılarını kullanır. Yinelenenleri hariç tutarak yalnızca benzersiz öğeleri döndürecektir.

Temel Kullanım

Ayrı öğeleri elde etmenin en basit yolu, bir koleksiyon üzerinde doğrudan Distinct yöntemini kullanmaktır.

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);
        }
    }
}
Imports System.Linq
Imports System.Collections.Generic

Public Class DistinctExample
	Public Shared Sub Example()
		' Example list with duplicate integers
		Dim numbers As New List(Of Integer) From {1, 2, 2, 3, 4, 4, 5}

		' Using Distinct to remove duplicates
		Dim distinctNumbers = numbers.Distinct()

		' Display the distinct numbers
		For Each number In distinctNumbers
			Console.WriteLine(number)
		Next number
	End Sub
End Class
$vbLabelText   $csharpLabel

Özel Eşitlik Karşılaştırıcı

Özel bir eşitlik karşılaştırması tanımlamak için Distinct işlevinin bir aşırı yüklemesi kullanılabilir. Bu, öğeleri belirli standartlara göre karşılaştırmak isterseniz kullanışlıdır. Lütfen aşağıdaki örneğe bakın:

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}");
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Linq

Public Class Person
	Public Property FirstName() As String
	Public Property LastName() As String
End Class

Public Class PersonEqualityComparer
	Implements IEqualityComparer(Of Person)

	Public Function Equals(ByVal x As Person, ByVal y As Person) As Boolean Implements IEqualityComparer(Of Person).Equals
		Return x.FirstName = y.FirstName AndAlso x.LastName = y.LastName
	End Function

	Public Function GetHashCode(ByVal obj As Person) As Integer Implements IEqualityComparer(Of Person).GetHashCode
		Return obj.FirstName.GetHashCode() Xor obj.LastName.GetHashCode()
	End Function
End Class

Public Class DistinctCustomComparerExample
	Public Shared Sub Example()
		' Example list of people
		Dim people As New List(Of Person) From {
			New Person With {
				.FirstName = "John",
				.LastName = "Doe"
			},
			New Person With {
				.FirstName = "Jane",
				.LastName = "Doe"
			},
			New Person With {
				.FirstName = "John",
				.LastName = "Doe"
			}
		}

		' Using Distinct with a custom equality comparer
		Dim distinctPeople = people.Distinct(New PersonEqualityComparer())

		' Display distinct people
		For Each person In distinctPeople
			Console.WriteLine($"{person.FirstName} {person.LastName}")
		Next person
	End Sub
End Class
$vbLabelText   $csharpLabel

Değer Türleri ile Distinct Kullanımı

Değer türleriyle Distinct yöntemi kullanılırken, özel bir eşitlik karşılaştırması sağlamanız gerekmez.

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);
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Linq

Public Class DistinctValueTypeExample
	Public Shared Sub Example()
		Dim integers As New List(Of Integer) From {1, 2, 2, 3, 4, 4, 5}

		' Using Distinct to remove duplicates
		Dim distinctIntegers = integers.Distinct()

		' Display distinct integers
		For Each [integer] In distinctIntegers
			Console.WriteLine([integer])
		Next [integer]
	End Sub
End Class
$vbLabelText   $csharpLabel

Anonim Türlerle Distinct Kullanımı

Distinct, belirli özelliklere dayalı olarak çiftleri kaldırmak için anonim türlerle kullanılabilir. Lütfen aşağıdaki örneğe bakın:

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}");
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Linq

Public Class Person
	Public Property FirstName() As String
	Public Property LastName() As String
End Class

Public Class DistinctAnonymousTypesExample
	Public Shared Sub Example()
		Dim people As New List(Of Person) From {
			New Person With {
				.FirstName = "John",
				.LastName = "Doe"
			},
			New Person With {
				.FirstName = "Jane",
				.LastName = "Doe"
			},
			New Person With {
				.FirstName = "John",
				.LastName = "Doe"
			}
		}

		' Using Distinct with anonymous types
		Dim distinctPeople = people.Select(Function(p) New With {
			Key p.FirstName,
			Key p.LastName
		}).Distinct()

		' Display distinct anonymous types
		For Each person In distinctPeople
			Console.WriteLine($"{person.FirstName} {person.LastName}")
		Next person
	End Sub
End Class
$vbLabelText   $csharpLabel

Belirli Bir Özellik ile Distinct

Nesnelerle çalışırken, belirli bir özelliğe göre ayırt etme mantığınızı oluşturabilir veya üçüncü taraf kütüphanelerden (MoreLINQ gibi) DistinctBy genişletme metodunu kullanabilirsiniz.

// 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}");
        }
    }
}
' Ensure to include the MoreLINQ Library
Imports MoreLinq
Imports System
Imports System.Collections.Generic
Imports System.Linq

Public Class Person
	Public Property Id() As Integer
	Public Property FirstName() As String
	Public Property LastName() As String
End Class

Public Class DistinctByExample
	Public Shared Sub Example()
		Dim people As New List(Of Person) From {
			New Person With {
				.Id = 1,
				.FirstName = "John",
				.LastName = "Doe"
			},
			New Person With {
				.Id = 2,
				.FirstName = "Jane",
				.LastName = "Doe"
			},
			New Person With {
				.Id = 1,
				.FirstName = "John",
				.LastName = "Doe"
			}
		}

		' Using DistinctBy to filter distinct people by Id
		Dim distinctPeople = people.DistinctBy(Function(p) p.Id)

		' Display distinct people
		For Each person In distinctPeople
			Console.WriteLine($"{person.Id}: {person.FirstName} {person.LastName}")
		Next person
	End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF

Programcılar, .NET kütüphanesi IronPDF Websitesi yardımıyla C# dili kullanarak PDF belgeleri oluşturabilir, düzenleyebilir ve değiştirebilir. Program, HTML'den PDF oluşturma, HTML'yi PDF'ye dönüştürme, PDF belgelerini birleştirme veya bölme ve mevcut PDF'lere metin, resim ve açıklama ekleme gibi PDF dosyalarını içeren çeşitli görevleri gerçekleştirmek için bir dizi araç ve işlevsellik sunar. IronPDF hakkında daha fazla bilgi için onların IronPDF Belgelerine başvurun.

IronPDF'nin ana özelliği HTML'den PDF'ye Dönüştürme olup düzenlerinizi ve stillerinizi sağlam tutar. Web içeriğinden PDF'ler oluşturabilirsiniz, raporlar, faturalar ve belgeler için mükemmeldir. HTML dosyalarını, URL'leri ve HTML dizelerini PDF dosyalarına dönüştürmeyi destekler.

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");
    }
}
Imports IronPdf

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		Dim renderer = New ChromePdfRenderer()

		' 1. Convert HTML String to PDF
		Dim htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>"
		Dim pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent)
		pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf")

		' 2. Convert HTML File to PDF
		Dim htmlFilePath = "path_to_your_html_file.html" ' Specify the path to your HTML file
		Dim pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath)
		pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf")

		' 3. Convert URL to PDF
		Dim url = "http://ironpdf.com" ' Specify the URL
		Dim pdfFromUrl = renderer.RenderUrlAsPdf(url)
		pdfFromUrl.SaveAs("URLToPDF.pdf")
	End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF'nin Özellikleri

  • HTML'yi PDF'ye Dönüştürme: IronPDF'yi kullanarak dosyalar, URL'ler ve HTML kodu dizeleri dahil olmak üzere her türlü HTML verisini PDF belgelerine dönüştürebilirsiniz.
  • PDF Oluşturma: C# programlama dili kullanılarak PDF belgelerine programlı bir şekilde metin, resim ve diğer unsurlar eklenebilir.
  • PDF Düzenleme: IronPDF, bir PDF dosyasını birden fazla dosyaya bölebilir, birkaç PDF belgesini tek bir dosyada birleştirebilir ve zaten mevcut PDF'leri düzenleyebilir.
  • PDF Formları: Kütüphane, form verilerinin toplanıp işlenmesi gerektiği senaryolarda kullanışlı olan PDF formları oluşturma ve doldurma sağlar.
  • Güvenlik Özellikleri: IronPDF, PDF belgelerini şifrelemek ve parola ve izin koruması sağlamak için kullanılabilir.
  • Metin Çıkarma: IronPDF kullanarak PDF dosyalarından metin çıkarılabilir.

IronPDF Yükleyin

IronPDF kütüphanesini edinin; Projenizi ayarlamak için gereklidir. Bunu başarmak için NuGet Paket Yöneticisi Konsoluna aşağıdaki kodu girin:

Install-Package IronPdf

C# LINQ Distinct (Geliştiriciler İçin Nasıl Çalışır): Şekil 1 - IronPDF kütüphanesini NuGet Paket Yöneticisi Konsolu ile yüklemek için şu komutu girin: Install IronPDF veya dotnet add package IronPdf

NuGet Paket Yöneticisi kullanarak "IronPDF" paketini aramak başka bir seçenektir. Bu listedeki IronPDF ile ilişkili tüm NuGet paketlerinden gerekli paketi seçip indirebiliriz.

C# LINQ Distinct (Geliştiriciler İçin Nasıl Çalışır): Şekil 2 - IronPDF kütüphanesini NuGet Paket Yöneticisi ile yüklemek için Gözat sekmesinde IronPDF paketini arayın ve projenize indirip yüklemek için en son IronPDF sürümünü seçin.

IronPDF İle LINQ

Bir veri kümesine sahip olduğunu ve bu kümedeki farklı değerlere göre çeşitli PDF belgeleri oluşturmak istediğinizi düşünün. LINQ'un Distinct kullanışlılığı, özellikle IronPDF ile belgeleri hızlıca oluşturmak için kullanıldığında parlıyor.

LINQ ve IronPDF ile Farklı PDF'ler Üretme

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}");
    }
}
Imports IronPdf
Imports System
Imports System.Collections.Generic
Imports System.Linq

Public Class DocumentGenerator
	Public Shared Sub Main()
		' Sample data representing categories
		Dim categories As New List(Of String) From {"Technology", "Business", "Health", "Technology", "Science", "Business", "Health"}

		' Use LINQ Distinct to filter out duplicate values
		Dim distinctCategories = categories.Distinct()

		' Generate a distinct elements PDF document for each category
		For Each category In distinctCategories
			GeneratePdfDocument(category)
		Next category
	End Sub

	Private Shared Sub GeneratePdfDocument(ByVal category As String)
		' Create a new PDF document using IronPDF
		Dim renderer As New IronPdf.HtmlToPdf()
		Dim pdf As PdfDocument = renderer.RenderHtmlAsPdf($"<h1>{category} Report</h1>")

		' Save the PDF to a file
		Dim pdfFilePath As String = $"{category}_Report.pdf"
		pdf.SaveAs(pdfFilePath)

		' Display a message with the file path
		Console.WriteLine($"PDF generated successfully. File saved at: {pdfFilePath}")
	End Sub
End Class
$vbLabelText   $csharpLabel

Bu örnekte, kategoriler koleksiyonu için Distinct metodunu kullanarak bir dizi farklı kategori elde edilir. Bir diziden yinelenen öğeleri kaldırmaya yardımcı olur. Sonra, bu eşsiz unsurlarla bir PDF belgesi oluşturmak için IronPDF kullanılır. Bu yöntem, yalnızca benzersiz kategoriler için ayrı PDF belgelerinin üretildiğini garanti eder.

Konsol Çıkışı

C# LINQ Distinct (Geliştiriciler İçin Nasıl Çalışır): Şekil 3 - Konsol Çıktısı

Üretilen PDF Çıktısı

C# LINQ Distinct (Geliştiriciler İçin Nasıl Çalışır): Şekil 4 - PDF Çıktısı: Teknoloji Raporu

HTML kullanarak PDF'ler oluşturmak için IronPDF kod örneği hakkında daha fazla bilgi için, IronPDF HTML'den PDF'ye Örnek Kodna başvurun.

Sonuç

LINQ'un Distinct genişletme metodu ile IronPDF, değerler temelinde benzersiz PDF belgeleri oluşturmak için sağlam ve verimli bir mekanizma sunar. Bu yöntem, kodu basitleştirir ve kategoriler, etiketler veya ayrı belgelerin gerektiği diğer verilerle çalışırken etkili belge üretimini garanti eder.

Veri işleme için LINQ'yu ve belge üretimi için IronPDF'yi kullanarak C# uygulamalarınızın farklı yönlerini yönetmek için güvenilir ve ifade edilebilir bir çözüm geliştirebilirsiniz. Projeleriniz için bu stratejileri kullanırken, uygulamanızın özel gereksinimlerini göz önünde bulundurun ve maksimum güvenilirlik ve performansı elde etmek için uygulamayı ayarlayın.

Sıkça Sorulan Sorular

C#'ta bir koleksiyondan yinelenen girişleri nasıl kaldırabilirim?

C# dilinde bir koleksiyondan yinelenen girişleri kaldırmak için LINQ'un Distinct yöntemini kullanabilirsiniz. Bu yöntem, özellikle IronPDF ile belirli veri kategorilerinden eşsiz PDF belgeleri oluşturmak için faydalıdır.

C#'ta HTML'i PDF'ye nasıl dönüştürürüm?

C#'ta HTML'i PDF'ye dönüştürmek için IronPDF'in RenderHtmlAsPdf metodunu kullanabilirsiniz. Bu, HTML dizgilerini veya dosyalarını etkili bir şekilde PDF belgelerine dönüştürmenizi sağlar.

LINQ'un Distinct metodunu özel nesnelerle kullanabilir miyim?

Evet, özel bir eşitlik karşılaştırıcısı sağlayarak LINQ'un Distinct metodunu özel nesnelerle kullanabilirsiniz. Bu, IronPDF ile PDF oluşturma sürecinde benzersizlik belirlemek için belirli kriterler tanımlamanız gerektiğinde faydalıdır.

LINQ'u IronPDF ile kullanmanın avantajı nedir?

LINQ'u IronPDF ile kullanmak, geliştiricilerin veri işlemesine dayalı eşsiz ve verimli PDF belgeleri oluşturmasına olanak tanır. Özellikle büyük ölçekli belge oluşturma görevlerini yönetirken kod okunabilirliğini ve performansını artırır.

LINQ'un Distinct metodu PDF belge oluşturmayı nasıl geliştirir?

LINQ'un Distinct metodu, yalnızca eşsiz girişlerin nihai çıktıya dahil olmasını sağlayarak PDF belge oluşturmayı iyileştirir. Farklı veri kategorileri için belirgin PDF belgeleri oluşturmak amacıyla IronPDF ile birlikte kullanılabilir.

IronPDF kullanırken PDF çıktısını özelleştirmek mümkün mü?

Evet, IronPDF sayfa boyutlarını ayarlama, kenar boşlukları ve üst bilgi veya alt bilgi ekleme gibi çeşitli özelleştirme seçenekleri sunar. Bu özelleştirmeler, ayrıcalıklı eşsiz belge çıktıları oluşturmak için LINQ ile birleştirilebilir.

Hangi senaryolar, PDF'lerle birlikte LINQ'un Distinct metodunu kullanmaktan faydalanabilir?

Raporlar, faturalar veya bir veri setinden benzersiz olan belgeler gerektiren herhangi bir belge oluşturma senaryoları, PDF'lerle birlikte LINQ'un Distinct metodunu kullanmaktan faydalanabilir. IronPDF, temiz ve belirgin PDF çıktıları etkin bir şekilde üretmek için kullanılabilir.

LINQ veri güdümlü PDF uygulamalarının verimliliğini nasıl artırır?

LINQ, geliştiricilerin PDF'leri oluşturmadan önce veri setlerini filtrelemesine ve manipüle etmesine olanak tanıyarak veri güdümlü PDF uygulamalarının verimliliğini artırır. Bu, yalnızca gerekli ve eşsiz verilerin PDF'lere dahil edilmesini sağlayarak performansı ve kaynak kullanımını optimize eder.

Jacob Mellor, Teknoloji Direktörü @ Team Iron
Chief Technology Officer

Jacob Mellor, Iron Software'in Teknoloji Müdürü ve C# PDF teknolojisinin öncüsü olan vizyoner bir mühendis. Iron Software’in temel kod tabanının ilk geliştiricisi olarak, şirketin ürün mimarisini kuruluşundan bu yana şekillendirdi ve CEO Cameron Rimington ile birlikte NASA, Tesla ve ...

Daha Fazlasını Oku

Iron Destek Ekibi

Haftanın 5 günü, 24 saat çevrimiçiyiz.
Sohbet
E-posta
Beni Ara