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

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

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

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

  1. Yeni bir Konsol Uygulaması projesi oluşturun.
  2. C# içinde HashSet için bir nesne oluşturun. Varsayılan değeri HashSet'e ekleyin.
  3. Eklerken, HashSet, elemanın mevcut olup olmadığını kontrol ederek yinelenen öğeleri otomatik olarak kaldırır.
  4. HashSet'i sadece benzersiz öğelerle tek tek işleyin.
  5. Sonucu görüntüleyin ve nesneyi yok edin.

C#'ta HashSet'i Anlama

C#'taki HashSet, yüksek performanslı set işlemleri sağlamak için tasarlanmıştır. Bir HashSet, yinelenen öğeleri önlediği için farklı bir veri kümesini saklamanız gerektiğinde kullanılmak için mükemmel bir koleksiyondur. System.Collections.Generic ad alanında bulunur ve hızlı ekleme, silme, hızlı erişim ve arama işlemleri sağlar. C#, standart küme işlemlerini kolayca gerçekleştirmenizi sağlayan HashSet set işlemleri yöntemlerini kullanın. HashSet sınıfı, set işlemleri yöntemleri sağlar.

HashSet için birkaç C# kullanım durumu şunlardır:

Başlatma ve Temel İşlemler

Bir HashSet oluşturma ve giriş ekleme, silme ve varlığı doğrulama gibi temel işlemleri 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

Koleksiyonla Başlatma

Mevcut bir koleksiyonu bir HashSet'in başlangıç ​​noktası olarak kullanarak, kopyalar hemen ortadan kaldırılı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 ile Birleşim

UnionWith işlevini kullanarak iki HashSet örneğini birleştirerek her iki kümedeki farklı öğeleri birleştiren yeni bir küme oluşturun.

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 ile Kesişim

IntersectWith işlevini kullanarak iki HashSet örneği arasındaki paylaşılan bileşenleri belirleyin.

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

ExceptWith işlevini kullanarak bir HashSet'te bulunan ancak diğerinde bulunmayan öğeleri bulun.

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ümenin Denetlenmesi:

IsSubsetOf ve IsSupersetOf yöntemlerini kullanarak, belirli bir HashSet örneğinin diğerinin bir alt kümesi veya üst kümesi olup olmadığını belirleyebilirsiniz.

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ı (bir kümede bulunan ancak her ikisinde de bulunmayan öğeler) belirleyin.

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

Programcılar, IronPDF .NET kütüphanesi kullanarak PDF belgeleri oluşturabilir, düzenleyebilir ve değiştirebilir. Uygulama, HTML'den yeni PDF'ler oluşturma, HTML'yi PDF'ye dönüştürme, PDF belgelerini birleştirme veya bölme ve mevcut PDF'leri metin, fotoğraf ve diğer verilerle açıklama ekleme dahil olmak üzere çeşitli işlemlerle PDF dosyaları üzerinde çalışmayı sağlayacak çeşitli araçlar ve özellikler sunar. IronPDF hakkında daha fazla bilgi için resmi belgeler'e bakın.

IronPDF, HTML'den PDF'ye dönüşümde mükemmeldir, özgün düzenler ve stillerin hassas bir şekilde korunmasını sağlar. Raporlar, faturalar ve belgeler gibi web tabanlı içeriklerden PDF oluşturmak için mükemmeldir. HTML dosyaları, URL'ler ve ham HTML dizeleri için destekle, IronPDF yüksek kaliteli PDF belgelerini kolayca ü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 Özellikleri

  • HTML'den PDF'ye dönüştürme: Dosyalar, URL'ler ve HTML kodu dizgeleri de dahil olmak üzere her türlü HTML verisi, IronPDF ile PDF belgelerine dönüştürülebilir.
  • PDF Oluşturma: C# programlama dili kullanılarak PDF belgelerine metin, resimler ve diğer nesneler programlı olarak eklenebilir.
  • PDF Manipülasyonu: IronPDF, bir PDF dosyasını sayısız dosyaya bölebilir ve önceden var olan PDF dosyalarını düzenleyebilir. Birkaç PDF dosyasını tek bir dosyada birleştirebilir.
  • PDF Formları: Kütüphane kullanıcıların PDF formları oluşturmasına ve doldurmasına olanak tanıdığı için form verilerinin toplanıp işlenmesi gerektiği senaryolarda kullanışlıdır.
  • Güvenlik Özellikleri: IronPDF, PDF belgelerini şifrelemek ve parola ile izin güvenliği sağlamak için kullanılır.

IronPDF Kurulumu

IronPDF kütüphanesini edinin; yaklaşan yama bunu gerektirir. Bunu yapmak için, Paket Yöneticisine aşağıdaki kodu girin:

Install-Package IronPdf

or

dotnet add package IronPdf

HashSet C# (How It Works For Developers): Figure 1 - Install IronPDF library using Package Manager Console and entering the following commands: `Install-Package IronPdf` or .NET add package IronPDF.

Başka bir seçenek, NuGet Package Manager kullanarak "IronPDF" paketini aramaktır. IronPDF ile ilgili tüm NuGet paketlerinden, bu listeden gerekli paketi seçip indirebiliriz.

HashSet C# (Geliştirici İçin Nasıl Çalışır): Şekil 2 - NuGet Paket Yöneticisi'ni kullanarak IronPDF kütüphanesini yükleyebilirsiniz. Ara sekmesinde IronPDF paketini arayın, ardından en son sürümü seçip kurun.

IronPDF ile HashSet

C# ortamında, IronPDF, PDF belgeleriyle çalışmayı kolaylaştıran güçlü bir kütüphanedir. Farklı veri temsili ve etkili belge oluşturmanın önemli olduğu durumlarda HashSet'in verimliliğini, IronPDF'nin belge manipülasyon gücüyle birleştirmek, yaratıcı çözümlerle sonuçlanabilir.

IronPDF ile HashSet Kullanmanın Faydaları

  • Veri Tekrarını Azaltma: Sadece benzersiz öğelerin saklanmasını sağlayarak, HashSet'ler veri tekrarlamasını önlemeye yardımcı olur. Büyük veri setleriyle çalışırken, yinelenen bilgileri kaldırmak için oldukça faydalıdır.
  • Etkili Arama: Ekleme, silme ve arama gibi temel işlemler, HashSet ile sabit zaman ortalama karmaşıklığında gerçekleştirilebilir. Bu tür performans, farklı boyutlardaki veri setleriyle çalışırken çok önemlidir.
  • Belge Üretimini Basitleştirme: IronPDF, C#'ta PDF belge oluşturma sürecini kolaylaştırır. HashSet'i IronPDF ile entegre ederek, PDF'leriniz için hızlı ve etkili süreçler tesis edebilirsiniz.

Şimdi, IronPDF ile HashSet kullanımının faydalı olabileceği bir gerçek dünya senaryosuna 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 alınan benzersiz kullanıcı adlarını uniqueUserNames adlı bir HashSet kullanarak kaydediyoruz. HashSet, kopyaları otomatik olarak ortadan kaldırır. Sonrasında, IronPDF kullanarak bu farklı kullanıcı adlarından oluşan sırasız bir listeyi bir PDF belgesinde oluşturuyoruz. Kod hakkında daha fazla bilgi almak için HTML kullanarak PDF oluşturma'yı kontrol edin.

ÇIKTI

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

Sonuç

Özetlemek gerekirse, C# HashSet veri yapısı, farklı öğe setlerini organize etmek için etkili bir araçtır. IronPDF ile birleştirildiğinde, dinamik, özgün ve performans optimize edilmiş PDF belge oluşturma için yeni fırsatlar sunar.

Veri benzersizliği sağlamanın yanı sıra, IronPDF ile PDF belgeleri oluşturmak için HashSet kullanmayı verdiğimiz örnekte gösterdik. HashSet ve IronPDF kombinasyonu, veri tekrarı önleme, raporlama veya dinamik içeriği yönetme üzerinde çalışırken C# uygulamalarınızı geliştirmeye yardımcı olabilir. Daha fazla araştırma yaparken, bu kombinasyonu uygulamalarınızın kullanılabilirliğini ve işlevselliğini artırmak için kullanabileceğiniz birçok bağlamı dikkate alın.

IronPDF'nin $999 Lite sürümü, kalıcı bir lisans, yükseltme seçenekleri ve bir yıl yazılım desteği ile birlikte gelir. İşaretli deneme süresi lisanslama üzerinde IronPDF'in fiyatlandırma, lisanslama ve ücretsiz deneme hakkında daha fazla bilgi edinin. Iron Software web sitesini daha fazla bilgi için ziyaret edin.

Sıkça Sorulan Sorular

C#'ta PDF belgeleri oluştururken benzersiz veri nasıl sağlanabilir?

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

IronPDF ile bir HashSet kullanmanın faydası nedir?

IronPDF ile bir HashSet kullanmak, PDF oluştururken benzersiz verilerin verimli bir şekilde yönetilmesini sağlar. HashSet, veri eşsizlik sağlar, IronPDF ise HTML içeriğini PDF'lere dönüştürmede, düzenleri ve stilleri korumada mükemmeldir.

HTML içeriğini C#'ta bir PDF'ye nasıl dönüştürebilirim?

IronPDF'in RenderHtmlAsPdf yöntemini kullanarak, HTML içeriğini doğrudan PDF'ye dönüştürebilirsiniz. Bu yöntem, orijinal düzen ve stili muhafaza ederek HTML dizgelerini doğrudan PDF'lere dönüştürmenizi sağlar.

C#'ta bir HashSet ne tür işlemleri destekler?

C#'ta HashSet, UnionWith, IntersectWith, ExceptWith ve SymmetricExceptWith gibi çeşitli küme işlemlerini destekler, bu da verilerin verimli bir şekilde işlenmesi ve küme karşılaştırmalarını sağlar.

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

HashSet'i PDF belgesi oluşturma ile entegre etmek için, verilerinizi benzersizliğe göre yönetmek ve filtrelemek için HashSet kullanabilir, ardından son PDF belgesini oluşturmak için IronPDF'e aktarabilirsiniz.

Dinamik içerik yönetiminde bir HashSet'in rolü nedir?

Dinamik içerik yönetiminde, bir HashSet verinin benzersiz kalmasını sağlayarak belge oluşturma, raporlama ve veri bütünlüğünü sağlama gibi görevler için kritik bir rol oynar.

C# projesine IronPDF nasıl kurulur?

C# projesine IronPDF'i NuGet Paket Yöneticisi ile şu komutu kullanarak kurabilirsiniz: Install-Package IronPdf veya .NET CLI ile: dotnet add package IronPdf.

C# uygulamalarında bir HashSet performansı artırabilir mi?

Evet, HashSet, ekleme, silme ve arama gibi temel işlemler için sabit zaman karmaşıklığı sağlayarak C# uygulamalarındaki performansı önemli ölçüde artırabilir ve büyük veri kümelerinin yönetiminde verimli hale getirir.

Jacob Mellor, Teknoloji Direktörü @ Team Iron
Teknoloji Direktörü

Jacob Mellor, Iron Software'de Baş Teknoloji Yöneticisidir ve C# PDF teknolojisinde öncü bir mühendisdir. Iron Software'ın ana kod tabanının ilk geliştiricisi olarak, CEO Cameron Rimington ile birlikte şirketin ürün mimarisini 50'den fazla kişilik bir şirkete dönüştürmüştür ...

Daha Fazla Oku

Iron Destek Ekibi

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