【发布时间】:2020-01-06 05:19:51
【问题描述】:
我正在从事一个涉及 KeyValuePair 的项目。我有 int 作为键,字符串作为值。
我想要的是从 KeyValuePair 中获取值。
我有这个代码:
var list = new List<KeyValuePair<int, string>>()
{
new KeyValuePair<int, string>(obj,_Obj.Questions)
};
Dictionary<int, string> d = new Dictionary<int, string>
{
{ 1, "Welcome, How are you?" },
{ 2, "Tell me something about yourself."},
{ 3, "How much experience do you have?"},
};
因此,如果您在 KVP 中看到字符串 Values,例如“Welcome, How are you?”、“Tell me something about your”等,则是静态的。所有这些值都已经存在于我的本地数据库中。我只想要数据库中的这些字符串值。
我正在使用 MS SQL 数据库
这可能吗??
【问题讨论】:
-
d[1] 将为您提供 1 的 KVP 价值
-
不完全确定我是否理解,因为您提到了数据库。但是,如果您想要键值对中的值,您将使用 .Value。 docs.microsoft.com/en-us/dotnet/api/…。如果您尝试从字典中获取每个值,则可以循环字典并访问每个项目的 .Value。
-
KeyValuePair 是如何存储在 Db 中的?你能分享一下你的桌子是什么样子的吗?
标签: c# sql-server dictionary keyvaluepair