C# 从app.config文件传入动态密钥

C# 从app.config文件传入动态密钥,c#,model-view-controller,key,app-config,C#,Model View Controller,Key,App Config,我在配置文件中有以下键,我想从配置文件中动态地将“add key”传递到我的conn变量,我可以成功地传递qp.cat.qmgr,在我的conn变量中,我想知道如何将其他键传递到我的变量中,我是否从.config中传递下一个键,如+“qp.cat.quser”,即 var conn=new RabbitMqConnection(Helpers.AppSettings.Get(“qp.cat.qmgr”)+(“qp.cat.quser”)+(“qp.cat.qpassword”); var con

我在配置文件中有以下键,我想从配置文件中动态地将“add key”传递到我的conn变量,我可以成功地传递qp.cat.qmgr,在我的conn变量中,我想知道如何将其他键传递到我的变量中,我是否从.config中传递下一个键,如+“qp.cat.quser”,即

var conn=new RabbitMqConnection(Helpers.AppSettings.Get(“qp.cat.qmgr”)+(“qp.cat.quser”)+(“qp.cat.qpassword”);
var conn=new RabbitMqConnection(Helpers.AppSettings.Get(“qp.cat.qmgr”)、“theTestingUAT”、“catquat”)//这是可行的,但是“测试”和“catquat”是硬编码的,不希望它们是硬编码的

请告知。

您应该这样使用它:

//Helpers.AppSettings.Get<string>("qp.cat.qmgr")
//Helpers.AppSettings.Get<string>("qp.cat.quser")
//Helpers.AppSettings.Get<string>("qp.cat.qpassword")

var conn = new RabbitMqConnection(Helpers.AppSettings.Get<string>("qp.cat.qmgr"), Helpers.AppSettings.Get<string>("qp.cat.quser"), Helpers.AppSettings.Get<string>("qp.cat.qpassword"));
//Helpers.AppSettings.Get(“qp.cat.qmgr”)
//Helpers.AppSettings.Get(“qp.cat.quser”)
//Helpers.AppSettings.Get(“qp.cat.qpassword”)
var conn=new RabbitMqConnection(Helpers.AppSettings.Get(“qp.cat.qmgr”)、Helpers.AppSettings.Get(“qp.cat.quser”)、Helpers.AppSettings.Get(“qp.cat.qpassword”);
//Helpers.AppSettings.Get<string>("qp.cat.qmgr")
//Helpers.AppSettings.Get<string>("qp.cat.quser")
//Helpers.AppSettings.Get<string>("qp.cat.qpassword")

var conn = new RabbitMqConnection(Helpers.AppSettings.Get<string>("qp.cat.qmgr"), Helpers.AppSettings.Get<string>("qp.cat.quser"), Helpers.AppSettings.Get<string>("qp.cat.qpassword"));