0
我想从一个iList中获取名称到另一个名称中,它们都包含相同的ID。C#创建两个iLists之间的关系
public class Notifications
{
[JsonProperty("note_id")]
public int note_id { get; set;}
[JsonProperty("sender_id")]
public int sender_id { get; set;}
public string sender_name { get; set; }
[JsonProperty("receiver_id")]
public int receiver_id { get; set; }
[JsonProperty("document_id")]
public int document_id { get; set; }
[JsonProperty("search_name")]
public string search_name { get; set; }
[JsonProperty("unread")]
public int unread { get; set; }
}
public class CompanyDirectory
{
[JsonProperty("contact_id")]
public int contact_id { get; set; }
[JsonProperty("first_name")]
public string first_name { get; set; }
[JsonProperty("second_name")]
public string second_name { get; set; }
[JsonProperty("extension")]
public string extension { get; set; }
[JsonProperty("direct_dial")]
public string direct_dial { get; set; }
[JsonProperty("job_title")]
public string job_title { get; set; }
[JsonProperty("company_id")]
public int company_id { get; set; }
}
然后我做以下,名单都得到填充罚款。怪异的位遇到错误说,在那里我做CompanyDir.first_name该属性不存在,它显然不?:
// This occurs just after the class declaration
public IList<Notifications> Notes;
public IList<CompanyDirectory> CompanyDir;
// Ignore that these both use the same string they're created at different parts of the load process
CompanyDir = JsonConvert.DeserializeObject<IList<CompanyDirectory>>(responseString);
Notes = JsonConvert.DeserializeObject<IList<Notifications>>(responseString);
// Now I thought I should be able to do
foreach(var s in Notes){
var thename = CompanyDir.first_name.Where(contact_id.Contains(s.sender_id))
}
大声笑,我几乎恨你是多么简单...... – 2014-11-06 09:32:06
嗯,每个ID应该有一个条目在CompanyDir中,如果我将ToList更改为ToString我不会得到first_name我得到System.Linq.Enumerable in Notes.name字段 – 2014-11-06 09:44:44
Aha tis ok了! – 2014-11-06 10:02:27