LIST capacity & count is getting different

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
when i declare list then i mention what would my list size but its capacity is getting higher means more allocation is happening which occupy memory.

see my code

List<MyData> JoinResult2 = new List<MyData>(5);
JoinResult2 = (from p in dt.AsEnumerable()
join t in dtTax.AsEnumerable()
on p.Field<int>("Tax Id") equals t.Field<int>("Tax Id") into pj
from r in pj.DefaultIfEmpty()
select new MyData
{
ProductName = p.Field<string>("Product Name"),
BrandName = p.Field<string>("Brand Name"),
ProductCategory = r == null ? "" : r.Field<string>("Product Category"),
TaxCharge = r == null ? 0 : r.Field<int>("Charge")
}).ToList();


its capacity is getting 8 when count is 5. how to force list to create 5 element instead of 8 ? where i made the mistake in my code?

Continue reading...
 
Back
Top