我在本节中有错误: 我需要+运算符为二和List ...
public partial class Question
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Question()
{
this.Answers = new HashSet<Answer>();
}
public long Question_Code { get; set; }
public Nullable<byte> Question_ExamCode { get; set; }
public Nullable<byte> Question_LessonCode { get; set; }
public string Question_Text { get; set; }
public string Question_OrginalLable { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Answer> Answers { get; set; }
public virtual Exam Exam { get; set; }
public virtual Lesson Lesson { get; set; }
}
然后:
public class FinalQuestions
{
public FinalQuestions() { }
public List<Question> StoreQuestions { get; set; }
public static List<Question> operator +(List<Question> FQ1, List<Question> FQ2)
{
foreach (var item in FQ2)
FQ1.Add(item);
return FQ1;
}
}
二元运算符的一个参数必须是包含类型!!!
答案 0 :(得分:1)
正如Jon Skeet评论的那样,这是不可能的。
组合两个序列的惯用方法是使用Enumerable.Concat。这样您就可以将两个列表中包含的问题合并到第三个列表中,如下所示:
var all = first.Concat(second).ToList();