使用IronBarcode与C#、VB.NET和F
IronBarcode 基于 .NET Standard 2.0 构建,因此无需额外配置即可原生支持 C#、VB.NET 和 F#。 这三种语言的 API 接口完全一致。 C# 中提供的所有方法、类和属性,在 VB.NET 和 F# 项目中同样可用。
安装
从 NuGet 安装 IronBarcode:
Install-Package BarCode
同一 BarCode 软件包适用于这三种语言。 不需要语言特定的包。
C# 示例
C# 是 IronBarcode 最常用的编程语言。 此示例生成一个 QR 码并将其保存为 PNG 格式:
:path=/static-assets/barcode/content-code-examples/get-started/net-language-support/net-language-support.cs
using IronBarCode;
// Generate a QR code and save it as an image
var qrCode = QRCodeWriter.CreateQrCode("https://ironsoftware.com", 250);
qrCode.SaveAsPng("qr-code.png");
// Read the barcode back from the saved image
var result = BarcodeReader.Read("qr-code.png");
Console.WriteLine(result.First().Value);
Imports IronBarCode
' Generate a QR code and save it as an image
Dim qrCode = QRCodeWriter.CreateQrCode("https://ironsoftware.com", 250)
qrCode.SaveAsPng("qr-code.png")
' Read the barcode back from the saved image
Dim result = BarcodeReader.Read("qr-code.png")
Console.WriteLine(result.First().Value)
输出
QRCodeWriter.CreateQrCode 生成一个 250×250 的 QR 码,该 QR 码由 BarcodeReader.Read 解码为 https://ironsoftware.com。
VB.NET 示例
VB.NET 使用与 C# 相同的 IronBarcode 方法。 仅语法发生变化:
Imports IronBarCode
' Generate a QR code and save it as an image
Dim qrCode = QRCodeWriter.CreateQrCode("https://ironsoftware.com", 250)
qrCode.SaveAsPng("qr-code.png")
' Read the barcode back from the saved image
Dim result = BarcodeReader.Read("qr-code.png")
Console.WriteLine(result.First().Value)
Imports IronBarCode
' Generate a QR code and save it as an image
Dim qrCode = QRCodeWriter.CreateQrCode("https://ironsoftware.com", 250)
qrCode.SaveAsPng("qr-code.png")
' Read the barcode back from the saved image
Dim result = BarcodeReader.Read("qr-code.png")
Console.WriteLine(result.First().Value)
Imports IronBarCode
' Generate a QR code and save it as an image
Dim qrCode = QRCodeWriter.CreateQrCode("https://ironsoftware.com", 250)
qrCode.SaveAsPng("qr-code.png")
' Read the barcode back from the saved image
Dim result = BarcodeReader.Read("qr-code.png")
Console.WriteLine(result.First().Value)
输出内容与上文的 C# 示例完全一致。
VB.NET在.NET Framework和.NET Core项目中都得到支持。 有关详细的演练,请参见<VB.NET条码生成教程。
F# 示例
F#开发人员可以直接引用IronBarcode。 该库可在标准 F# 项目中使用,也可在 F# Interactive 中通过 #r 指令使用:
open IronBarCode
// Generate a QR code and save it as an image
let qrCode = QRCodeWriter.CreateQrCode("https://ironsoftware.com", 250)
qrCode.SaveAsPng("qr-code.png")
// Read the barcode back from the saved image
let result = BarcodeReader.Read("qr-code.png")
printfn "%s" (result.First().Value)
open IronBarCode
// Generate a QR code and save it as an image
let qrCode = QRCodeWriter.CreateQrCode("https://ironsoftware.com", 250)
qrCode.SaveAsPng("qr-code.png")
// Read the barcode back from the saved image
let result = BarcodeReader.Read("qr-code.png")
printfn "%s" (result.First().Value)
输出内容与上文的 C# 示例完全一致。
支持的.NET版本
IronBarcode支持所有三种语言的广泛.NET运行时:
- .NET 9、8、7、6、5
- .NET Core 3.x、2.x
- .NET Framework 4.6.2+
- .NET Standard 2.0
有关特定平台的NuGet包(Windows、Linux、macOS、iOS、Android),请参阅高级安装指南。
常见问题解答
What languages are supported by IronBarcode?
IronBarcode supports C#, VB.NET, and F# with an identical API, making it versatile across different .NET languages.
How do I install IronBarcode?
You can install IronBarcode from NuGet using the package manager for your respective language environment with the command `Install-Package BarCode`.
Can I use IronBarcode with .NET Core and .NET Framework?
Yes, IronBarcode is compatible with both .NET Core and .NET Framework, supporting .NET Core 3.x, 2.x, and .NET Framework 4.6.2+.
Is there a difference in using IronBarcode between C#, VB.NET, and F#?
The API surface is identical across C#, VB.NET, and F#, so the functionality remains the same, with only syntax differences.
How can I generate a QR code using C# with IronBarcode?
In C#, you can generate a QR code using IronBarcode by calling `QRCodeWriter.CreateQrCode("https://ironsoftware.com", 250)` and saving it with `qrCode.SaveAsPng("qr-code.png")`.
Is IronBarcode compatible with F# Interactive?
Yes, IronBarcode can be used in F# Interactive by referencing it directly with the `#r` directive.
IronBarcode支持哪些.NET版本?
IronBarcode supports a wide range of .NET versions including .NET 9, 8, 7, 6, 5, .NET Core 3.x, 2.x, and .NET Framework 4.6.2+.
Do I need language-specific packages to use IronBarcode?
No, the same `BarCode` package from NuGet works for C#, VB.NET, and F# without the need for language-specific packages.
How do I read a barcode from an image using VB.NET?
Using VB.NET, you can read a barcode from an image with IronBarcode by calling `BarcodeReader.Read("qr-code.png")` and accessing the result.
Are there platform-specific installation guides for IronBarcode?
Yes, for platform-specific NuGet packages (Windows, Linux, macOS, iOS, Android), you can refer to the advanced installation guide.

