追加到 C# 中的列表

Appending to a list in C#

我有一个 table,它提取一个值,如果该列中有任何错误消息,我需要给出一条硬编码消息,说 "Error is found"

// Property 
Public partial Class section: IXmlserializable
public List<string> ErrorMessage {get, set}

if(ErrorMessage != null && ErrorMessage.Count > 0)
    Writer.WriteElement("Notifications")

Writer.WriteEndElement();

// I call this in my Body of the Page
Datatable dt = this.GetErrorMessage(rountingcode, BookKey,userobject)

if(dt != null dt.Rows.Count > 0)
{
    Book.ErrorMessage.add(dt.Rows[0]["ErrorColumn"].ToString());
}

// Idea is to add from the Book to its SECTION property ErrorMessage
if(Book.ErrorMessage!= null && Book.ErrorMessage.Count>0 )
// INITIALIZE 

sec.ErrorMessage = new List<string>();
// IF the Book does contain any Error message that we pulled from the table
// Display HARD coded message
sec.ErrorMessage.Add("Hey Buddy you have a error in the BODY ") 
}

现在,如果我有其他错误怎么办,因为在我的 Header Book.ErrorMessage 中来自不同的 PROC,它使用相同的 属性 ErrorMessage 具有 STRING ("Hey Buddy you have a error in the HEADER") 从其他数据表中提取 HEADER 错误

所以说到条件

if(dt != null dt.Rows.Count > 0 )  // It want go inside 

但是

if(Book.ErrorMessage!= null && Book.ErrorMessage.Count>0)
// Will go here
// As it is using the same Property ErrorMessage for to get the HEADER 
//Error.

有没有什么方法可以附加它,因为我们可以同时显示 ErrorMessage 现在它总是覆盖。

<Notification>
Hey Buddy you have a error in the BODY   
Hey Buddy you have a error in the HEADER</Notification>

我使用 SQL 查询通过提取包含错误 list.If 的列来完成此操作,该列有 1 行作为错误,它应该使用数据 table 检索值。我使用 linq 查询查询数据 table 并添加到列表中。谢谢大家的帮助