c# - Foreach loop show value's only once if repeated -
i have foreach loop in values repeated , group value's , out put values once. code looks this
foreach (loopitem in getloop("product.prices")){     var pricequantity = "";     if(i.getinteger("ecom:product.prices.quantity") == 0){         pricequantity = "1";     } else if(i.getinteger("ecom:product.prices.quantity") >= 1){         pricequantity = i.getstring("ecom:product.prices.quantity");     }        <!--@translate(ved, "ved")--> @pricequantity <!--@translate(count, "stk")-->. - <!--@translate(count, "stk")-->. <!--@translate(price, "pris")-->. @i.getvalue("ecom:product.prices.amountformatted")<br/>      }   which gives following out put 1 stk, 1 stk, 1 stk, 12 stk, 8 stk, 8 stk, 1 stk
i output 1 stk, 12 stk, 8 stk
how can achieve output please help
var result = getloop("product.prices").groupby(x => x.quantity).select(x => x.first());   and can print result collection conditions.
    foreach (loopitem in result){         var pricequantity = "";         if(i.getinteger("ecom:product.prices.quantity") == 0){             pricequantity = "1";         } else if(i.getinteger("ecom:product.prices.quantity") >= 1){             pricequantity = i.getstring("ecom:product.prices.quantity");         }            <!--@translate(ved, "ved")--> @pricequantity <!--@translate(count, "stk")-->. - <!--@translate(count, "stk")-->. <!--@translate(price, "pris")-->. @i.getvalue("ecom:product.prices.amountformatted")<br/>      }   but can in way, using hashset<t>
var sequence = getloop("product.prices"); var alreadyin = new hashset<t>(); foreach(var in sequence) {         if(alreadyin.add(i))// returns false if item in set         {            if(i.getinteger("ecom:product.prices.quantity") == 0){                pricequantity = "1";            }else if(i.getinteger("ecom:product.prices.quantity") >= 1){              pricequantity = i.getstring("ecom:product.prices.quantity");            }            <!--@translate(ved, "ved")--> @pricequantity <!--@translate(count, "stk")-->. - <!--@translate(count, "stk")-->. <!--@translate(price, "pris")-->. @i.getvalue("ecom:product.prices.amountformatted")<br/>          }               }      
Comments
Post a Comment