使用IronBarcode与C#、VB.NET和F

This article was translated from English: Does it need improvement?
Translated
View the article in English

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)
$vbLabelText   $csharpLabel

输出

由 C# 中的 IronBarcode 生成的 QR 码编码 https://ironsoftware.com
控制台输出显示从生成的QR码中解码出的https://ironsoftware.com

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)
$vbLabelText   $csharpLabel

输出内容与上文的 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)
F#

输出内容与上文的 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.

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 2,169,908 | 版本: 2026.4 刚刚发布
Still Scrolling Icon

还在滚动吗?

想快速获得证据? PM > Install-Package BarCode
运行示例 观看您的字符串变成 BarCode。