c# - Grouping and Sum DataTable Rows without Linq -



c# - Grouping and Sum DataTable Rows without Linq -

i have datatable this

name cost product1 10 product1 12 product2 3 product2 5 product2 7 product3 22

i grouping same named products , sum prices --->

name cost product1 10 product1 12 22 product2 3 product2 5 product2 7 15 product3 22 22

i should't create linq. how can distinguish different value of names , sum them in table.

you dictionary key name of product, , value sum of same product prices.

var allproducts = context.products.where(.....what products want take db).tolist(); dictionary<string, int32> dictionary = new dictionary<string, int32>(); foreach(var product in allproducts) { int32 value = 0; if(!dictionary.trygetvalue(product.name, out value)) { dictionary.add(product.name, product.price); continue; } value += product.price; dictionary[product.name] = value; }

c# asp.net datatable

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -