我List
像这样填充我的:
public List<Functions> ListFunctions(int proj)
{
List<Functions> lFunctions = new List<Functions>();
try
{
string sql = "SELECT id, description FROM functios WHERE project = @project ORDER BY description ASC";
MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add(new MySqlParameter("@project", MySqlDbType.Int32)).Value = proj;
using (MySqlDataReader reader = _dal.ExecutaReader(cmd))
{
while (reader.Read())
{
lFunctions.Add(new Function
{
ID = Convert.ToInt32(reader["id"]),
Descripton = reader["description"].ToString()
});
}
}
return lFunction;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
我现在如何遍历列表并获取这些值?Description
和_ID
我想知道一种准确获取字段名称的方法,例如:
string name = ListFunction["FieldName"].ToString()