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

HashSet C# (Geliştiriciler İçin Nasıl Çalışır)

C# dilinde programlama esnektir ve çeşitli işleri etkili bir şekilde yönetmek için geniş bir veri yapıları yelpazesi sunar. HashSet, temel işlemler için sabit zaman ortalama karmaşıklık ve benzersiz bileşenler sunan böyle etkili bir veri yapısıdır. Bu gönderi, PDF belgeleriyle çalışmak için güçlü bir kütüphane olan IronPDF ile nasıl kullanılabileceğini ve C# dilinde HashSet kullanımını inceleyecektir.

C#'ta HashSet Nasıl Kullanılır

  1. Yeni bir Konsol Uygulama projesi oluşturun.
  2. C#'ta HashSet için bir nesne oluşturun. Varsayılan değeri HashSet'e ekleyin.
  3. Eklerken, HashSet, elemanın var olup olmadığını kontrol ederek yinelenen elemanları otomatik olarak kaldırır.
  4. HashSet'teki yalnızca benzersiz elemanları birer birer işleyin.
  5. Sonucu gösterin ve nesneyi yok edin.

C#'ta HashSet'i Anlamak

C#'ta HashSet, yüksek performanslı küme işlemleri sağlamak için tasarlanmıştır. Bir HashSet, tekrar eden elemanları önlediği için ayrı veri kümesi tutmanın gerekli olduğu durumlarda kullanılacak ideal koleksiyondur. System.Collections.Generic ad alanı içinde yer alır ve hızlı ekleme, silme, daha hızlı erişim ve arama işlemleri sunar. C#'ta, HashSet küme işlemleri yöntemlerini kullanarak standart küme işlemlerini kolayca gerçekleştirin. HashSet sınıfı küme işlemleri yöntemleri sağlar.

Aşağıdakiler, C#'ta bir HashSet kullanımının bazı yollarıdır:

Başlatma ve Temel İşlemler

Bir HashSet oluşturma ve ekleme, silme ve girdilerin varlığını doğrulama gibi temel eylemleri gerçekleştirme.

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        // Initializes a HashSet of integers
        HashSet<int> numbers = new HashSet<int>();

        // Adds elements to the HashSet
        numbers.Add(1);
        numbers.Add(2);
        numbers.Add(3);

        // Removes an element from the HashSet
        numbers.Remove(2);

        // Checks for membership of an element
        bool containsThree = numbers.Contains(3);

        Console.WriteLine($"Contains 3: {containsThree}");
    }
}
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        // Initializes a HashSet of integers
        HashSet<int> numbers = new HashSet<int>();

        // Adds elements to the HashSet
        numbers.Add(1);
        numbers.Add(2);
        numbers.Add(3);

        // Removes an element from the HashSet
        numbers.Remove(2);

        // Checks for membership of an element
        bool containsThree = numbers.Contains(3);

        Console.WriteLine($"Contains 3: {containsThree}");
    }
}
Imports System
Imports System.Collections.Generic

Friend Class Program
	Shared Sub Main()
		' Initializes a HashSet of integers
		Dim numbers As New HashSet(Of Integer)()

		' Adds elements to the HashSet
		numbers.Add(1)
		numbers.Add(2)
		numbers.Add(3)

		' Removes an element from the HashSet
		numbers.Remove(2)

		' Checks for membership of an element
		Dim containsThree As Boolean = numbers.Contains(3)

		Console.WriteLine($"Contains 3: {containsThree}")
	End Sub
End Class
$vbLabelText   $csharpLabel

Bir Koleksiyon İle Başlatma

Mevcut bir koleksiyonu başlangıç noktası olarak kullanarak HashSet için tekrarlar hemen ele alınır.

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        // Creates a list with duplicate elements
        List<int> duplicateNumbers = new List<int> { 1, 2, 2, 3, 3, 4 };

        // Initializes a HashSet with the list, automatically removes duplicates
        HashSet<int> uniqueNumbers = new HashSet<int>(duplicateNumbers);

        Console.WriteLine("Unique numbers:");
        foreach (var number in uniqueNumbers)
        {
            Console.WriteLine(number);
        }
    }
}
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        // Creates a list with duplicate elements
        List<int> duplicateNumbers = new List<int> { 1, 2, 2, 3, 3, 4 };

        // Initializes a HashSet with the list, automatically removes duplicates
        HashSet<int> uniqueNumbers = new HashSet<int>(duplicateNumbers);

        Console.WriteLine("Unique numbers:");
        foreach (var number in uniqueNumbers)
        {
            Console.WriteLine(number);
        }
    }
}
Imports System
Imports System.Collections.Generic

Friend Class Program
	Shared Sub Main()
		' Creates a list with duplicate elements
		Dim duplicateNumbers As New List(Of Integer) From {1, 2, 2, 3, 3, 4}

		' Initializes a HashSet with the list, automatically removes duplicates
		Dim uniqueNumbers As New HashSet(Of Integer)(duplicateNumbers)

		Console.WriteLine("Unique numbers:")
		For Each number In uniqueNumbers
			Console.WriteLine(number)
		Next number
	End Sub
End Class
$vbLabelText   $csharpLabel

Başka Bir HashSet İle Birleşim

İki HashSet örneğini birleşik, her iki setten de ayrı öğeyi birleştirerek yeni bir küme oluşturmak için UnionWith fonksiyonunu kullanma.

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        HashSet<int> set1 = new HashSet<int> { 1, 2, 3 };
        HashSet<int> set2 = new HashSet<int> { 3, 4, 5 };

        // Merges set2 into set1
        set1.UnionWith(set2);

        Console.WriteLine("Union of set1 and set2:");
        foreach (var item in set1)
        {
            Console.WriteLine(item);
        }
    }
}
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        HashSet<int> set1 = new HashSet<int> { 1, 2, 3 };
        HashSet<int> set2 = new HashSet<int> { 3, 4, 5 };

        // Merges set2 into set1
        set1.UnionWith(set2);

        Console.WriteLine("Union of set1 and set2:");
        foreach (var item in set1)
        {
            Console.WriteLine(item);
        }
    }
}
Imports System
Imports System.Collections.Generic

Friend Class Program
	Shared Sub Main()
		Dim set1 As New HashSet(Of Integer) From {1, 2, 3}
		Dim set2 As New HashSet(Of Integer) From {3, 4, 5}

		' Merges set2 into set1
		set1.UnionWith(set2)

		Console.WriteLine("Union of set1 and set2:")
		For Each item In set1
			Console.WriteLine(item)
		Next item
	End Sub
End Class
$vbLabelText   $csharpLabel

Başka Bir HashSet İle Kesişim

İki HashSet örneği arasındaki ortak bileşenleri belirlemek için IntersectWith fonksiyonunu kullanma.

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        HashSet<int> set1 = new HashSet<int> { 1, 2, 3 };
        HashSet<int> set2 = new HashSet<int> { 3, 4, 5 };

        // Keeps only elements that are present in both sets
        set1.IntersectWith(set2);

        Console.WriteLine("Intersection of set1 and set2:");
        foreach (var item in set1)
        {
            Console.WriteLine(item);
        }
    }
}
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        HashSet<int> set1 = new HashSet<int> { 1, 2, 3 };
        HashSet<int> set2 = new HashSet<int> { 3, 4, 5 };

        // Keeps only elements that are present in both sets
        set1.IntersectWith(set2);

        Console.WriteLine("Intersection of set1 and set2:");
        foreach (var item in set1)
        {
            Console.WriteLine(item);
        }
    }
}
Imports System
Imports System.Collections.Generic

Friend Class Program
	Shared Sub Main()
		Dim set1 As New HashSet(Of Integer) From {1, 2, 3}
		Dim set2 As New HashSet(Of Integer) From {3, 4, 5}

		' Keeps only elements that are present in both sets
		set1.IntersectWith(set2)

		Console.WriteLine("Intersection of set1 and set2:")
		For Each item In set1
			Console.WriteLine(item)
		Next item
	End Sub
End Class
$vbLabelText   $csharpLabel

Başka Bir HashSet ile Fark

Tek bir HashSet'te bulunduğu halde diğerinde bulunmayan ögeleri bulmak için ExceptWith fonksiyonunu kullanma.

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        HashSet<int> set1 = new HashSet<int> { 1, 2, 3 };
        HashSet<int> set2 = new HashSet<int> { 3, 4, 5 };

        // Removes elements from set1 that are also in set2
        set1.ExceptWith(set2);

        Console.WriteLine("Difference of set1 and set2:");
        foreach (var item in set1)
        {
            Console.WriteLine(item);
        }
    }
}
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        HashSet<int> set1 = new HashSet<int> { 1, 2, 3 };
        HashSet<int> set2 = new HashSet<int> { 3, 4, 5 };

        // Removes elements from set1 that are also in set2
        set1.ExceptWith(set2);

        Console.WriteLine("Difference of set1 and set2:");
        foreach (var item in set1)
        {
            Console.WriteLine(item);
        }
    }
}
Imports System
Imports System.Collections.Generic

Friend Class Program
	Shared Sub Main()
		Dim set1 As New HashSet(Of Integer) From {1, 2, 3}
		Dim set2 As New HashSet(Of Integer) From {3, 4, 5}

		' Removes elements from set1 that are also in set2
		set1.ExceptWith(set2)

		Console.WriteLine("Difference of set1 and set2:")
		For Each item In set1
			Console.WriteLine(item)
		Next item
	End Sub
End Class
$vbLabelText   $csharpLabel

Alt Küme veya Üst Küme Kontrolü:

Bir HashSet örneğinin başka bir HashSet'in alt kümesi veya üst kümesi olup olmadığını belirlemek için IsSubsetOf ve IsSupersetOf yöntemlerini kullanma.

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        HashSet<int> set1 = new HashSet<int> { 1, 2, 3 };
        HashSet<int> set2 = new HashSet<int> { 2, 3 };

        // Checks if set2 is a subset of set1
        bool isSubset = set2.IsSubsetOf(set1);

        // Checks if set1 is a superset of set2
        bool isSuperset = set1.IsSupersetOf(set2);

        Console.WriteLine($"Is set2 a subset of set1: {isSubset}");
        Console.WriteLine($"Is set1 a superset of set2: {isSuperset}");
    }
}
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        HashSet<int> set1 = new HashSet<int> { 1, 2, 3 };
        HashSet<int> set2 = new HashSet<int> { 2, 3 };

        // Checks if set2 is a subset of set1
        bool isSubset = set2.IsSubsetOf(set1);

        // Checks if set1 is a superset of set2
        bool isSuperset = set1.IsSupersetOf(set2);

        Console.WriteLine($"Is set2 a subset of set1: {isSubset}");
        Console.WriteLine($"Is set1 a superset of set2: {isSuperset}");
    }
}
Imports System
Imports System.Collections.Generic

Friend Class Program
	Shared Sub Main()
		Dim set1 As New HashSet(Of Integer) From {1, 2, 3}
		Dim set2 As New HashSet(Of Integer) From {2, 3}

		' Checks if set2 is a subset of set1
		Dim isSubset As Boolean = set2.IsSubsetOf(set1)

		' Checks if set1 is a superset of set2
		Dim isSuperset As Boolean = set1.IsSupersetOf(set2)

		Console.WriteLine($"Is set2 a subset of set1: {isSubset}")
		Console.WriteLine($"Is set1 a superset of set2: {isSuperset}")
	End Sub
End Class
$vbLabelText   $csharpLabel

Simetrik Fark

SymmetricExceptWith tekniğini kullanarak simetrik farkı belirleyin (bir sette bulunan ama ikisinde de olmayan elemanlar).

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        HashSet<int> set1 = new HashSet<int> { 1, 2, 3 };
        HashSet<int> set2 = new HashSet<int> { 3, 4, 5 };

        // Keeps elements that are in set1 or set2 but not in both
        set1.SymmetricExceptWith(set2);

        Console.WriteLine("Symmetric difference of set1 and set2:");
        foreach (var item in set1)
        {
            Console.WriteLine(item);
        }
    }
}
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        HashSet<int> set1 = new HashSet<int> { 1, 2, 3 };
        HashSet<int> set2 = new HashSet<int> { 3, 4, 5 };

        // Keeps elements that are in set1 or set2 but not in both
        set1.SymmetricExceptWith(set2);

        Console.WriteLine("Symmetric difference of set1 and set2:");
        foreach (var item in set1)
        {
            Console.WriteLine(item);
        }
    }
}
Imports System
Imports System.Collections.Generic

Friend Class Program
	Shared Sub Main()
		Dim set1 As New HashSet(Of Integer) From {1, 2, 3}
		Dim set2 As New HashSet(Of Integer) From {3, 4, 5}

		' Keeps elements that are in set1 or set2 but not in both
		set1.SymmetricExceptWith(set2)

		Console.WriteLine("Symmetric difference of set1 and set2:")
		For Each item In set1
			Console.WriteLine(item)
		Next item
	End Sub
End Class
$vbLabelText   $csharpLabel

IronPDF

IronPDF .NET kütüphanesi kullanarak programcılara PDF dokümanlarını oluşturma, düzenleme ve değiştirme imkânı verir. Uygulama, HTML'den yeni PDF'ler oluşturma, HTML'yi PDF'ye çevirme, PDF dokümanlarını birleştirme veya bölme ve mevcut PDF'lere metin, fotoğraf ve diğer verilerle not düşme dahil, PDF dosyalarıyla farklı işlemleri sağlayan çok sayıda araç ve özellik sunar. IronPDF hakkında daha fazla bilgi için resmi dokümantasyona bakınız.

HTML'den PDF'ye dönüştürmede IronPDF, özgün düzenlerin ve tarzların hassas korunmasını sağlamakta üstünlük sağlar. Web tabanlı içeriklerden, örneğin raporlar, faturalar ve belgeler gibi PDF'ler oluşturmak için mükemmeldir. HTML dosyaları, URL'ler ve ham HTML dizeleri desteği ile IronPDF kolaylıkla yüksek kaliteli PDF belgeler üretir.

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'den PDF'ye Çevirme: Dosyalar, URL'ler ve HTML kod dizeleri dahil her tür HTML verisini IronPDF kullanarak PDF dokümanlarına çevirin.
  • PDF Üretimi: C# programlama dilini kullanarak PDF belgelerine metin, görüntü ve diğer nesneler ekleyebilirsiniz.
  • PDF Manipülasyonu: IronPDF bir PDF dosyasını birden fazla dosyaya bölebilir ve var olan PDF dosyalarını düzenleyebilir. Birden fazla PDF dosyasını tek bir dosya hâlinde birleştirebilir.
  • PDF Formları: Kütüphane kullanıcıların PDF formları oluşturmasını ve tamamlamasını sağladığı için form verilerinin toplanıp işlenmesi gereken durumlarda faydalı olur.
  • Güvenlik Özellikleri: IronPDF, PDF dokümanlarını şifrelemeye ve parola ile izin güvenliğine olanak tanır.

IronPDF Yükleyin

IronPDF kütüphanesini edinin. Bunu yapmak için aşağıdaki kodu Paket Yöneticisi'ne girin:

Install-Package IronPdf

veya

dotnet add package IronPdf

HashSet C# (Geliştiriciler İçin Nasıl Çalışır): Şekil 1 - IronPDF kütüphanesini Paket Yöneticisi Konsolu kullanarak yükleyin ve şu komutları girin: Install-Package IronPDF veya dotnet add package IronPdf.

Başka bir seçenek olarak NuGet Paket Yöneticisi kullanarak "IronPDF" paketini arayabilirsiniz. IronPDF ile ilgili tüm NuGet paketlerinden ihtiyaç duyduğumuz paketi bu listeden seçip indirebiliriz.

HashSet C# (Geliştiriciler İçin Nasıl Çalışır): Şekil 2 - IronPDF kütüphanesini NuGet Paket Yöneticisi ile yükleyebilirsiniz. Gezinme sekmesinde ironpdf paketini aratın, sonra IronPDF'nin en son sürümünü seçip yükleyin.

IronPDF İle HashSet

C# ortamında IronPDF, PDF belgeleriyle çalışmayı daha kolay hale getiren güçlü bir kütüphanedir. Ayrı veri temsili ve etkili doküman oluşturulmasının önemli olduğu durumlarda HashSet'in verimliliği ile IronPDF'nin doküman manipülasyon güçlerini birleştirmek yaratıcı çözümler sunabilir.

IronPDF İle HashSet Kullanmanın Faydaları

  • Veri Yedekliliğini Azaltma: Sadece ayrı elemanların tutulmasını sağlayarak HashSet'ler veri tekrarını önlemeye yardımcı olur. Bu durum, büyük veri kümesi ile tekrar eden bilgileri kaldırma işlemiyle uğraşıldığında oldukça faydalıdır.
  • Etkin Arama: Ekleme, silme ve arama gibi temel işlemler HashSet kullanılarak sabit zaman ortalama karmaşıklığı ve performansı ile yapılabilir. Bu tür bir performans, farklı boyutlardaki veri setleri ile çalışırken çok önemlidir.
  • Belgelerin Basitleştirilmiş Üretimi: IronPDF, C# PDF belge oluşturma sürecini düzenler. HashSet'i IronPDF ile entegre ederek özgün ve dinamik içerik için hızlı ve etkili süreçler kurabilirsiniz.

Şimdi IronPDF ile HashSet kullanmanın yararlı olabileceği gerçek bir senaryoya bakalım.

Benzersiz Verilerle PDF Oluşturma

using IronPdf;
using System;
using System.Collections.Generic;

class PdfGenerator
{
    static void Main()
    {
        // Sample user names with duplicates
        string[] userNames = { "Alice", "Bob", "Charlie", "Bob", "David", "Alice" };

        // Using HashSet to ensure unique user names
        HashSet<string> uniqueUserNames = new HashSet<string>(userNames);

        // Generating PDF with unique user names
        GeneratePdf(uniqueUserNames);
    }

    static void GeneratePdf(HashSet<string> uniqueUserNames)
    {
        // Create a new PDF document using IronPDF
        HtmlToPdf renderer = new HtmlToPdf();

        // Render a PDF from an HTML document consisting of unique user names
        var pdf = renderer.RenderHtmlAsPdf(BuildHtmlDocument(uniqueUserNames));

        // Save the PDF to a file
        string pdfFilePath = "UniqueUserNames.pdf";
        pdf.SaveAs(pdfFilePath);

        // Display a message with the file path
        Console.WriteLine($"PDF generated successfully. File saved at: {pdfFilePath}");
    }

    static string BuildHtmlDocument(HashSet<string> uniqueUserNames)
    {
        // Build an HTML document with unique user names
        string htmlDocument = "<html><body><ul>";
        foreach (var userName in uniqueUserNames)
        {
            htmlDocument += $"<li>{userName}</li>";
        }
        htmlDocument += "</ul></body></html>";
        return htmlDocument;
    }
}
using IronPdf;
using System;
using System.Collections.Generic;

class PdfGenerator
{
    static void Main()
    {
        // Sample user names with duplicates
        string[] userNames = { "Alice", "Bob", "Charlie", "Bob", "David", "Alice" };

        // Using HashSet to ensure unique user names
        HashSet<string> uniqueUserNames = new HashSet<string>(userNames);

        // Generating PDF with unique user names
        GeneratePdf(uniqueUserNames);
    }

    static void GeneratePdf(HashSet<string> uniqueUserNames)
    {
        // Create a new PDF document using IronPDF
        HtmlToPdf renderer = new HtmlToPdf();

        // Render a PDF from an HTML document consisting of unique user names
        var pdf = renderer.RenderHtmlAsPdf(BuildHtmlDocument(uniqueUserNames));

        // Save the PDF to a file
        string pdfFilePath = "UniqueUserNames.pdf";
        pdf.SaveAs(pdfFilePath);

        // Display a message with the file path
        Console.WriteLine($"PDF generated successfully. File saved at: {pdfFilePath}");
    }

    static string BuildHtmlDocument(HashSet<string> uniqueUserNames)
    {
        // Build an HTML document with unique user names
        string htmlDocument = "<html><body><ul>";
        foreach (var userName in uniqueUserNames)
        {
            htmlDocument += $"<li>{userName}</li>";
        }
        htmlDocument += "</ul></body></html>";
        return htmlDocument;
    }
}
Imports IronPdf
Imports System
Imports System.Collections.Generic

Friend Class PdfGenerator
	Shared Sub Main()
		' Sample user names with duplicates
		Dim userNames() As String = { "Alice", "Bob", "Charlie", "Bob", "David", "Alice" }

		' Using HashSet to ensure unique user names
		Dim uniqueUserNames As New HashSet(Of String)(userNames)

		' Generating PDF with unique user names
		GeneratePdf(uniqueUserNames)
	End Sub

	Private Shared Sub GeneratePdf(ByVal uniqueUserNames As HashSet(Of String))
		' Create a new PDF document using IronPDF
		Dim renderer As New HtmlToPdf()

		' Render a PDF from an HTML document consisting of unique user names
		Dim pdf = renderer.RenderHtmlAsPdf(BuildHtmlDocument(uniqueUserNames))

		' Save the PDF to a file
		Dim pdfFilePath As String = "UniqueUserNames.pdf"
		pdf.SaveAs(pdfFilePath)

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

	Private Shared Function BuildHtmlDocument(ByVal uniqueUserNames As HashSet(Of String)) As String
		' Build an HTML document with unique user names
		Dim htmlDocument As String = "<html><body><ul>"
		For Each userName In uniqueUserNames
			htmlDocument &= $"<li>{userName}</li>"
		Next userName
		htmlDocument &= "</ul></body></html>"
		Return htmlDocument
	End Function
End Class
$vbLabelText   $csharpLabel

Yukarıdaki kod örneğinde bir diziden elde edilen benzersiz kullanıcı adlarını uniqueUserNames adlı bir HashSet kullanarak saklıyoruz. HashSet, tekrar edenleri otomatik olarak eler. Daha sonra IronPDF kullanarak bu ayrı kullanıcı adlarının sıralanmamış bir listesini bir PDF belgesinde oluştururuz. Kod hakkında daha fazla bilgi için HTML kullanarak PDF oluşturma sayfasına bakın.

ÇIKTI

HashSet C# (Geliştiriciler İçin Nasıl Çalışır): Şekil 3 - Çıktı: UniqueUserNames.pdf

Sonuç

Özetle, C# HashSet veri yapısı, ayrı ögeler topluluklarını düzenlemek için etkili bir araçtır. IronPDF ile birleştirildiğinde dinamik, benzersiz ve performans optimize edilmiş PDF belge oluşturma için yeni fırsatlar sunar.

Veri benzersizliğini garanti altına almak için HashSet'i nasıl kullandığımızı ve IronPDF kullanarak PDF belgeleri oluşturduğumuzu verdiğimiz örnekte gösterdik. Güçlü ve etkili C# uygulamaları geliştirme, bütünleşik HashSet ve IronPDF ile veri tekilleştirme, raporlama veya dinamik içerik yönetimi üzerinde çalışırken yararlıdır. Daha fazla araştırma yaparken uygulamalarınızın kullanışlılık ve işlevselliğini geliştirmek için bu uyumu kullanabileceğiniz çeşitli bağlamları dikkate alın.

IronPDF'nin $799 Lite sürümü, kalıcı lisans, yükseltme seçenekleri ve bir yıl süreyle yazılım desteği ile gelir. Lisanslama ile ilgili ücretsiz deneme dönemince IronPDF'nin fiyat, lisanslama ve ücretsiz deneme hakkında daha fazla bilgi edinin. Iron Software hakkında daha fazla bilgi için Iron Software web sitesini ziyaret edin.

Sıkça Sorulan Sorular

C# ile PDF belgeleri oluştururken benzersiz verileri nasıl sağlayabilirim?

PDF belgenizi oluşturmadan önce benzersiz veri öğelerini, örneğin kullanıcı adlarını, saklamak için bir HashSet kullanabilirsiniz. Bu, yinelenen girişlerin kaldırılmasını sağlayarak daha temiz ve daha doğru PDF içeriği sunar.

IronPDF ile HashSet kullanmanın faydası nedir?

IronPDF ile bir HashSet kullanmak, PDF oluştururken benzersiz verilerin verimli bir şekilde yönetilmesini sağlar. HashSet veri benzersizliğini garanti ederken, IronPDF HTML içeriğini PDF'lere dönüştürmede, mizanpajları ve stilleri koruyarak mükemmel performans gösterir.

C# dilinde HTML içeriği nasıl PDF'e dönüştürülür?

C# kullanarak IronPDF'nin RenderHtmlAsPdf yöntemi ile HTML içeriğini PDF'ye dönüştürebilirsiniz. Bu yöntem, HTML dizgilerini doğrudan PDF'lere dönüştürmenize olanak tanır ve orijinal düzen ile stili korur.

HashSet, C#'te hangi işlemleri destekler?

HashSet C# içinde UnionWith, IntersectWith, ExceptWith ve SymmetricExceptWith gibi çeşitli küme işlemlerini destekler, bu da verimli veri manipülasyonu ve küme karşılaştırmalarını kolaylaştırır.

HashSet'i PDF belgesi oluşturma ile nasıl entegre edebilirim?

Bir HashSet'i PDF belge oluşturma ile entegre etmek için, verilerinizi eşsizliğini korumak amacıyla yönetmek ve filtrelemek üzere HashSet'i kullanın ve ardından son PDF belgesini oluşturmak için IronPDF'ye iletin.

HashSet'in dinamik içerik yönetimindeki rolü nedir?

Dinamik içerik yönetiminde, bir HashSet veri benzersizliğini garanti ederek belge oluşturma, raporlama ve veri bütünlüğünü koruma gibi görevler için hayati bir rol oynar.

IronPDF bir C# projesine nasıl kurulur?

IronPDF, C# projesine NuGet Paket Yöneticisi kullanarak Install-Package IronPdf komutuyla veya .NET CLI kullanarak dotnet add package IronPdf komutuyla yüklenebilir.

Bir HashSet, C# uygulamalarında performansı artırabilir mi?

Evet, HashSet, ekleme, silme ve arama gibi temel işlemler için sabit zaman karmaşıklığı sağlayarak C# uygulamalarında performansı önemli ölçüde artırabilir, bu da büyük veri kümelerini yönetmede verimli olmasını sağlar.

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