C# 如何将变量从命名空间传递到引用命名空间
我的脑子坏了。程序设置为询问用户地址。一个简单的控制台问题,将用户的输入放入字符串中。然后,我希望将变量传递给引用类库,以将字符串放入QRcode“条形码”中 二维码:C# 如何将变量从命名空间传递到引用命名空间,c#,qr-code,nuget-package,C#,Qr Code,Nuget Package,我的脑子坏了。程序设置为询问用户地址。一个简单的控制台问题,将用户的输入放入字符串中。然后,我希望将变量传递给引用类库,以将字符串放入QRcode“条形码”中 二维码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; using QRCoder; namespace Q
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using QRCoder;
namespace QRmaker
{
class program
{
public void codeMake()
{
QRCodeGenerator generator = new QRCodeGenerator();
QRCodeData qrCodeData = generator.CreateQrCode(input, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20);
qrCodeImage.Save("Address.bmp");
}
}
}
试试这个:
在QRMaker中:
namespace QRmaker
{
class Program
{
public static void codeMake(string input)
{
var generator = new QRCodeGenerator();
var qrCodeData = generator.CreateQrCode(input, QRCodeGenerator.ECCLevel.Q);
var qrCode = new QRCode(qrCodeData);
var qrCodeImage = qrCode.GetGraphic(20);
qrCodeImage.Save("Address.bmp");
}
}
}
在AddressInq中:
namespace AddressInq
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter the address: ");
QRmaker.Program.codeMake(Console.ReadLine());
}
}
}
我所做的是将codeMake
方法转换为static
,这样您就不必实例化程序
类来访问它。。。
您必须调用
QRmaker
命名空间中的程序类
,包括类名称前面的命名空间:命名空间.class.Method
您不能将输入作为参数传递给codeMake吗?像codeMake(字符串输入)?
namespace AddressInq
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter the address: ");
QRmaker.Program.codeMake(Console.ReadLine());
}
}
}