Reputation: 1196
I'm populating my List
like this:
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);
}
}
How may I loop through the list and get those values now ? The Description
and the ID
I'd like to know a way to get exactly the fieldName, like:
string name = ListFunction["FieldName"].ToString()
Upvotes: 1
Views: 71
Reputation: 62492
You just enumerate over the returned list. For example:
var functions=ListFunctions(0); // For example
foreach(var function in functions)
{
Console.WriteLine("{0} = {1}",function.ID, function.Description);
}
Upvotes: 1