- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有一组字符串需要存储在一个集合中,比如:
身份证、名字、姓氏、城市、国家、语言
以上都适用于一个人(用ID表示)
现在我有 60 到 70 个(并且还在增加),我该如何组织它们?我查看了 NameValueCollection 类 - 它完全符合我的要求(如果我只有两个字段),但由于我有 6 个字段,所以我无法使用它。例如:
public NameValueCollection personCollection = new NameValueCollection
{
{ "harry", "townsend", "london", "UK", "english" },
{ "john", "cowen", "liverpool", "UK", "english" },
// and so on...
};
虽然这行不通:(有人可以建议另一种实现此目的的方法吗?
最佳答案
用你需要的属性创建一个 Person 类怎么样?
public class Person
{
public int id { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
// more attributes here
}
然后,只需实例化 Person 类并创建新的 Person 对象。然后,您可以将这些人添加到列表中。
Person somePerson = new Person();
somePerson.firstname = "John";
somePerson.lastname = "Doe";
somePerson.id = 1;
List<Person> listOfPersons = new List<Person>();
listOfPersons.Add(somePerson);
关于c# - 使用 NameValueCollection 类存储两个以上的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11063549/
在我尝试用内部 NameValueCollection 初始化 NameValueCollection 后,c# 编译器说必须是 NameValueCollection(string,string)。
有没有办法从 NameValueCollection 中提取与特定模式/命名约定相关的键,而不必遍历集合中的每个值? 最佳答案 名称值集合的设计并不是特别有效地进行这样的搜索。无论您使用哪种方法,它都
我必须将通用对象转换为 NameValueCollection。我正在尝试使用反射。虽然我可以获得父属性,但我无法获取作为对象的父属性的属性。 Class One public string name
有人可以阐明我的 NameValueCollection 返回 Length 属性而不是 Name 和 Value 可以告诉我我在这里做错了什么。我无法为下拉列表设置 DataTextField 或
如何将动态转换为 NameValueCollection? 我尝试将它转换为字典,然后转换为 NameValueCollection,但它会针对不同类型抛出异常。 [...] NameValueC
我读过 NameValueCollection 允许添加重复的键,但是当我尝试使用它时,情况似乎并非如此。 我的代码 using (var wb = new WebClient()) { v
我有两个 NameValueCollection: NameValueCollection customTag = (NameValueCollection)System.Configuration.
假设我有一个匿名类实例 var foo = new { A = 1, B = 2}; 有没有快速生成 NameValueCollection 的方法?我想在事先不知道匿名类型的属性的情况下获得与下面的
我有一个 NameValueCollection,我想遍历这些值。目前,我正在这样做,但似乎应该有一种更简洁的方法来做到这一点: NameValueCollection nvc = new NameV
在 automapper 中,如何将名称值集合映射到强类型集合? Mapper.Map>(); public class MetaModel { public string Name;
例如,如果我们有 {"Parameters":["name" : "test"]}它将被序列化为 {"Parameters":["name"]} . (使用 System.Text.Json) 这是为
有没有办法使 NameValueCollection 或派生类可序列化? 最佳答案 NameObjectCollectionBase ( NameValueCollection 的基类)已经实现了 I
有谁知道断言 NameValueCollection 是否等效的好方法?目前我正在使用 NUnit,但 CollectionAssert.AreEquivalent() 似乎只声明键。不是键和值。 我
我有枚举, public enum ClearAttributes { S_DURATION, S_TYPE } 我正在使用枚举中的描述将项目添加到 NameValueCollecti
NameValueCollection x = new NameValueCollection(Request.QueryString); string x1 = x.ToString(); Name
我有一个 NameValueCollection 变量 queryDict。 有些键没有值。但是我想遍历所有键,即使它们没有关联的值。 使用这个,如果值为空,我得到 null 而不是键名: forea
如果不是,确定两个 NameValueCollections 对象是否相等的最佳方法是什么。 我用它来确定解析到名称值集合中的两个查询字符串是否具有相同的键和值,而不管顺序如何。 最佳答案 Equal
我有一种情况,我不能使用字典来收集字符串的名称值。我的名称值对包含重复键,因为我需要支持遗留系统。所以请不要让我停止支持重复键。我尝试使用 NameValueCollection 但这不能与 Data
在我的 web.config 中,我将配置部分分解为单独的文件: 然后我使用 ConfigurationManager 检索设置: NameValueCollection appSettings
在 .NET(反)序列化的幕后发生了什么,使它的行为方式与它在以下场景中的行为方式相同? (这是一个测试应用程序,仅用于说明我的设置。) 我有一个带有 NameValueCollection 属性的类
我是一名优秀的程序员,十分优秀!