I am using the following to convert comma separated string to list.
string productId ="1,2";
string productName = "Product1,Product2";
string prodCat = "Cat1,Cat1";
string quantity = "10,10";
string retailPrice = "12,12";
var _productId = new List<String>(productId.Trim().Split(','));
var _productName = new List<String>(productName.Trim().Split(','));
var _prodCat = new List<String>(prodCat.Trim().Split(','));
var _quantity = new List<String>(quantity.Trim().Split(','));
var _retailPrice = new List<String>(retailPrice.Trim().Split(','));
var _products = (from pi in _productId
join pro in _productName on _productId.IndexOf(pi) equals _productName.IndexOf(pro)
join pn in _prodCat on _productId.IndexOf(pi) equals _prodCat.IndexOf(pn)
join rp in _retailPrice on _productId.IndexOf(pi) equals _retailPrice.IndexOf(rp)
join q in _quantity on _productId.IndexOf(pi) equals _quantity.IndexOf(q)
where pi.Length > 0 && pro.Length > 0
select pi);
_products.Dump("Products");
The Above query returns the different result:
Products
IEnumerable<String> (8 items)
1
1
1
1
1
1
1
1
But it should be:
Products
IEnumerable<String> (2 items)
1
2
If i have different values in all the strings, i get the actual result. Here in the above example, i have the same category, quantity and price for two different products. But i am getting the result with eight wrong values.
Any clue on this, why it happens so?