我試圖將項目添加到列表中(項目是不同類型的)。這是我如何做的。將不同類型的項目添加到.Net中的列表中
private List<JiraIssues> GetIssues(string result)
{
string x = null;
var summary = x;
List<JiraIssues> returnResulttoReport = new List<JiraIssues>();
RootObject myresult = JsonConvert.DeserializeObject<RootObject>(result);
foreach (var item in myresult.issues)
{
Console.WriteLine(item.fields.summary);
summary = item.fields.summary;
foreach (var commentitem in item.fields.comment.comments)
{
var authorname = commentitem.author.name;
Console.WriteLine(commentitem.author.name);
}
}
/*var vnlist = (from up in spcall
where up.Caption == "Contacted"
select new JiraIssues
{
summary,
authorname,
ActualDate,
Value = up.Value
}).ToList();*/
returnResulttoReport.AddRange(summary,authorname);
return returnResulttoReport ;
}
獲取錯誤;
AddRange不能帶2個參數。
爲了更好的可視性我在這裏把我的JiraIssues:
[DataContract]
public class JiraIssues
{
public JiraIssues()
{
Comments = new List<JiraComment>();
//Components = new List<JiraComponent>();
}
[DataMember(Order = 0)]
public string IssueKey;
[DataMember(Order = 1)]
public string Id;
[DataMember(Order = 2)]
public string Description;
[DataMember(Order = 3)]
public string Assignee;
[DataMember(Order = 4)]
public DateTime? Created;
[DataMember(Order = 5)]
public DateTime? Duedate;
[DataMember(Order = 6)]
public string Environment;
[DataMember(Order = 7)]
public string Priority;
[DataMember(Order = 8)]
public string Project;
[DataMember(Order = 9)]
public string Reporter;
[DataMember(Order = 10)]
public string Resolution;
[DataMember(Order = 11)]
public string Status;
[DataMember(Order = 12)]
public string Summary;
[DataMember(Order = 13)]
public string IssueType;
[DataMember(Order = 14)]
public DateTime? Updated;
[DataMember(Order = 15)]
public long? Votes;
[DataMember(Order = 16)]
public string Components;
[DataMember(Order = 17)]
public List<JiraComment> Comments;
}
[DataContract]
public class JiraComment
{
[DataMember(Order = 0)]
public string CommentBody;
[DataMember(Order = 1)]
public string CommentAuthor;
[DataMember(Order = 2)]
public DateTime? CommentCreated;
[DataMember(Order = 3)]
public string CommentUpdateAuthor;
[DataMember(Order = 4)]
public DateTime? CommentUpdated;
[DataMember(Order = 5)]
public string CommentId;
[DataMember(Order = 6)]
public string CommentGroupLevel;
[DataMember(Order = 7)]
public string CommentParentKeyId;
[DataMember(Order = 8)]
public string CommentParentId;
}
我怎樣才能解決售後服務做到這一點?我需要添加並返回方法中的所有字符串。
是'Summary'和'AuthorName'型與'JiraIssues'都兼容嗎? –
['列表 .AddRange'](https://msdn.microsoft.com/en-us/library/z883w3dc%28v=vs.110%29.aspx)的文檔在我看來很清楚。如何將它們添加到不同的'AddRange'中?但是'summary' _already_看起來像'string'。考慮改變你的邏輯。目前還不清楚你想要做什麼。 –
您已將returnResulttoReport聲明爲JiraIssues的列表。您可以添加到該列表中的唯一類型是JiraIssues。 AddRange()方法就像Add()方法,只是它將JiraIssues列表添加到列表中。 – HaukurHaf