My code is working nicelly but I would like to know if you can suggest something more performatic to get the values frm my dynamic controls.
public class Obj
{
public int ID { get; set; }
public int Quantity { get; set; }
public List<int> getValues (List<Obj> myList)
{
List<Obj> listQuatity = new List<Obj>();
foreach (Obj item in myList)
{
listQuatity.Add(new Obj
{
ID = item.ID,
Quantity = Request.Params["codControl" + item.ID].Trim().Equals("")
? 0
: Convert.ToInt32(Request.Params["codControl" + item.ID])
});
}
}
}
There is no much space for optimization, your loop is pretty simple and straightforward.
One thing I would improve – caching of the
Request.Paramvalue instead accessing it twice:(This could be rewritten using LINQ so would look more elegant but it would not be faster)
Let’s see how LINQ query would look: