透かしなしで本番環境でテストしてください。
必要な場所で動作します。
30日間、完全に機能する製品をご利用いただけます。
数分で稼働させることができます。
製品トライアル期間中にサポートエンジニアリングチームへの完全アクセス
C#は、多くの利用可能なプログラミング言語の中で、開発者にとって人気があり、適応性の高い選択肢となっています。 コレクションの概念は、C#の広範なライブラリとフレームワークの中心にあり、これは言語の主な利点の一つです。 C#では、コレクションはデータを効果的に保存および整理するために不可欠です。 彼らは開発者に対して、難解なプログラミングの問題を解決するための幅広く効果的なツールを提供します。 この投稿では、コレクションの機能、種類、および最適な使用戦略について詳しく見ていきます。
新しいコンソールアプリプロジェクトを作成します。
C#でコレクションのオブジェクトを作成します。
複数のオブジェクト・セットを格納できるコレクション・クラスに値を追加します。
値操作を実行する、例えば追加、削除、並べ替えなど。
C#のコレクションは、プログラマがオブジェクトクラスのセットを操作したり保存したりするためのコンテナです。 これらのオブジェクトは柔軟で多くのプログラミング環境に適応可能であり、同じ種類または異なる種類のものである可能性があります。 ほとんどのコレクションクラスは、C#のSystemのコンポーネントを実装しており、System.Collections や System.Collections.Generic などの名前空間をインポートします。これにより、ジェネリックおよび非ジェネリックのさまざまなコレクションクラスが提供されます。 コレクションは、動的メモリ割り当て、アイテムの追加、検索、およびコレクションクラス内のアイテムのソートを可能にします。
ArrayList、Hashtable、およびQueueは、C#の初期バージョンに含まれていた非ジェネリックコレクションクラスの一部です。 これらのコレクションは、保持し作業したいものの種類を明示的に定義する代替手段を提供します。 しかし、開発者は汎用コレクションを選択することが多いですが、それは優れたパフォーマンスと型安全性のためです。
C#の後のバージョンでは、非ジェネリックコレクションの欠点を克服するために、ジェネリックコレクションが導入されました。 それらは、コンパイル中に型の安全性を提供し、開発者が厳密に型付けされたデータを扱うことを可能にします。 一般的なコレクションクラスとして、List
要素の迅速で簡単な挿入と削除を可能にする動的配列が、List
List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
numbers.Add(6); // adds element '6' to the end
numbers.Remove(3); // removes all the items that are '3'
List<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
numbers.Add(6); // adds element '6' to the end
numbers.Remove(3); // removes all the items that are '3'
Dim numbers As New List(Of Integer) From {1, 2, 3, 4, 5}
numbers.Add(6) ' adds element '6' to the end
numbers.Remove(3) ' removes all the items that are '3'
高速な検索速度を持ち、一連のキーと値のペアはDictionary<TKey, TValue>クラスで表されます。 データに素早くアクセスすることが重要な状況で頻繁に使用されます。 このキーは、辞書内の要素にアクセスするために使用されます。
Dictionary<string, int> ageMap = new Dictionary<string, int>();
ageMap.Add("John", 25); // the string "John" is the key that can access the value 25
ageMap["Jane"] = 30; // setting the key "Jane" to hold the value 30
Dictionary<string, int> ageMap = new Dictionary<string, int>();
ageMap.Add("John", 25); // the string "John" is the key that can access the value 25
ageMap["Jane"] = 30; // setting the key "Jane" to hold the value 30
Dim ageMap As New Dictionary(Of String, Integer)()
ageMap.Add("John", 25) ' the string "John" is the key that can access the value 25
ageMap("Jane") = 30 ' setting the key "Jane" to hold the value 30
先入れ先出しコレクション(FIFO)および後入れ先出し(LIFO)パラダイムは、それぞれジェネリックな Queue
Queue<string> tasks = new Queue<string>(); // creating a queue class
tasks.Enqueue("Task 1"); // adding to the queue
tasks.Enqueue("Task 2");
Stack<double> numbers = new Stack<double>(); // creating a stack class
numbers.Push(3.14); // adding to the stack
numbers.Push(2.71);
Queue<string> tasks = new Queue<string>(); // creating a queue class
tasks.Enqueue("Task 1"); // adding to the queue
tasks.Enqueue("Task 2");
Stack<double> numbers = new Stack<double>(); // creating a stack class
numbers.Push(3.14); // adding to the stack
numbers.Push(2.71);
Dim tasks As New Queue(Of String)() ' creating a queue class
tasks.Enqueue("Task 1") ' adding to the queue
tasks.Enqueue("Task 2")
Dim numbers As New Stack(Of Double)() ' creating a stack class
numbers.Push(3.14) ' adding to the stack
numbers.Push(2.71)
一意のアイテムが順不同のコレクションに配置されている場合、HashSet
HashSet<int> setA = new HashSet<int> { 1, 2, 3, 4 };
HashSet<int> setB = new HashSet<int> { 3, 4, 5, 6 };
HashSet<int> unionSet = new HashSet<int>(setA);
unionSet.UnionWith(setB); // combining setA and setB
HashSet<int> setA = new HashSet<int> { 1, 2, 3, 4 };
HashSet<int> setB = new HashSet<int> { 3, 4, 5, 6 };
HashSet<int> unionSet = new HashSet<int>(setA);
unionSet.UnionWith(setB); // combining setA and setB
Dim setA As New HashSet(Of Integer) From {1, 2, 3, 4}
Dim setB As New HashSet(Of Integer) From {3, 4, 5, 6}
Dim unionSet As New HashSet(Of Integer)(setA)
unionSet.UnionWith(setB) ' combining setA and setB
C#ライブラリIronPDFは、.NETアプリケーションでPDFドキュメントの作成、編集、表示を簡単にします。 それは、多くのライセンスオプション、クロスプラットフォーム互換性、高品質のレンダリング、およびHTMLからPDFへの変換を提供します。 IronPDFのユーザーフレンドリーなAPIはPDFの取り扱いを容易にし、C#開発者にとって価値あるツールとなります。
IronPDFの際立った機能は、すべてのレイアウトとスタイルを維持するHTMLからPDFへの変換の能力です。 ウェブコンテンツからPDFを生成するので、レポート、請求書、およびドキュメントに最適です。 HTMLファイル、URL、そしてHTML文字列は簡単に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");
}
}
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
IronPDFの主な機能には以下が含まれます:
パフォーマンスの最適化:大きなPDF文書や複雑なPDF文書を扱う場合でも、ライブラリは効率的なPDFの作成とレンダリングを提供するように設計されています。
IronPDFのドキュメントについて詳しく知るには、IronPDF Documentationを参照してください。
まず、パッケージマネージャーコンソールまたはNuGetパッケージマネージャーを使用してIronPDFライブラリをインストールします。
Install-Package IronPdf
NuGetパッケージマネージャーを使用して「IronPDF」パッケージを検索することも選択肢の一つです。「IronPDF」に関連するすべてのNuGetパッケージの中から、必要なパッケージを選択してダウンロードできます。
IronPDFのインターフェースに入る前に、データ構造と組織におけるコレクションの役割を理解することが重要です。 開発者は、コレクションを使用することによって、物のグループを体系的に保存、取得、および変更することができます。 List
販売取引のリストを含むレポートを作成する必要があると想像してください。 データは、追加の処理と表示の基盤として機能するList
public class Transaction
{
public string ProductName { get; set; }
public decimal Amount { get; set; }
public DateTime Date { get; set; }
}
List<Transaction> transactions = new List<Transaction>
{
new Transaction { ProductName = "Product A", Amount = 100.50m, Date = DateTime.Now.AddDays(-2) },
new Transaction { ProductName = "Product B", Amount = 75.20m, Date = DateTime.Now.AddDays(-1) },
// Add more transactions as needed
};
public class Transaction
{
public string ProductName { get; set; }
public decimal Amount { get; set; }
public DateTime Date { get; set; }
}
List<Transaction> transactions = new List<Transaction>
{
new Transaction { ProductName = "Product A", Amount = 100.50m, Date = DateTime.Now.AddDays(-2) },
new Transaction { ProductName = "Product B", Amount = 75.20m, Date = DateTime.Now.AddDays(-1) },
// Add more transactions as needed
};
Public Class Transaction
Public Property ProductName() As String
Public Property Amount() As Decimal
Public Property [Date]() As DateTime
End Class
Private transactions As New List(Of Transaction) From {
New Transaction With {
.ProductName = "Product A",
.Amount = 100.50D,
.Date = DateTime.Now.AddDays(-2)
},
New Transaction With {
.ProductName = "Product B",
.Amount = 75.20D,
.Date = DateTime.Now.AddDays(-1)
}
}
PDF内で、各製品名、取引額、取引日時を一覧表示する簡単な表を作成します。
var pdfDocument = new IronPdf.HtmlToPdf();
// HTML content with a table populated by data from the 'transactions' list
string htmlContent = "<table><tr><th>Product Name</th><th>Amount</th><th>Date</th></tr>";
foreach (var transaction in transactions)
{
htmlContent += $"<tr><td>{transaction.ProductName}</td><td>{transaction.Amount}</td><td>{transaction.Date.ToShortDateString()}</td></tr>";
}
htmlContent += "</table>";
// Convert HTML to PDF
PdfDocument pdf = pdfDocument.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs(pdfFilePath);
var pdfDocument = new IronPdf.HtmlToPdf();
// HTML content with a table populated by data from the 'transactions' list
string htmlContent = "<table><tr><th>Product Name</th><th>Amount</th><th>Date</th></tr>";
foreach (var transaction in transactions)
{
htmlContent += $"<tr><td>{transaction.ProductName}</td><td>{transaction.Amount}</td><td>{transaction.Date.ToShortDateString()}</td></tr>";
}
htmlContent += "</table>";
// Convert HTML to PDF
PdfDocument pdf = pdfDocument.RenderHtmlAsPdf(htmlContent);
pdf.SaveAs(pdfFilePath);
Dim pdfDocument = New IronPdf.HtmlToPdf()
' HTML content with a table populated by data from the 'transactions' list
Dim htmlContent As String = "<table><tr><th>Product Name</th><th>Amount</th><th>Date</th></tr>"
For Each transaction In transactions
htmlContent &= $"<tr><td>{transaction.ProductName}</td><td>{transaction.Amount}</td><td>{transaction.Date.ToShortDateString()}</td></tr>"
Next transaction
htmlContent &= "</table>"
' Convert HTML to PDF
Dim pdf As PdfDocument = pdfDocument.RenderHtmlAsPdf(htmlContent)
pdf.SaveAs(pdfFilePath)
開発者は、生成されたPDFドキュメントをディスクに保存するか、ユーザーに表示するかを選択することができます。 IronPDFは、ブラウザストリーミング、ファイル保存、クラウドストレージ統合など、いくつかの出力オプションを提供します。
上記の画面は、上記のコードから生成された出力を示しています。 コードの詳細については、HTMLを使用してPDFを作成する例をご参照ください。
IronPdfとコレクションを組み合わせることで、ダイナミックなドキュメント制作が可能になります。 開発者はコレクションを利用してデータを効果的に管理および整理でき、IronPDF を使用することで視覚的に美しい PDF ドキュメントを簡単に作成できます。 IronPDF とコレクションの連携による強力なソリューションは、C# アプリケーションにおける動的コンテンツ生成に対して信頼性と適応性を提供します。請求書、レポート、その他どのような種類のドキュメントを生成する場合でも対応可能です。
IronPDF の $749 Lite エディションには、1 年間のソフトウェアサポート、アップグレードオプション、および永久ライセンスが含まれています。 ユーザーは、透かし入りの試用期間中に実際の状況で製品を評価する機会も得られます。 IronPDF の費用、ライセンス、および無料トライアルについて詳しく知るには、IronPDF のライセンス情報をご覧ください。 詳細については、Iron Softwareのウェブサイトをご覧ください。