Hi,
I am trying to search the item into list by passing another list with where condition using linq.
here is my code:
{
public string item { get; set; }
public short count { get; set; }
}
public class ClassItemB
{
public string item { get; set; }
}
class Program
{
static void Main(string[] args)
{
List
string[] s = { "B00B0YJQPK", "B0046HF4AY" };
string[] s1 = { "B00BGL8YWS", "B0006G4MH0" };
foreach (string sb in s)
{
ClassItemA cb = new ClassItemA();
cb.item = sb.ToString();
cb.count = 10;
b.Add(cb);
}
foreach (string sb in s1)
{
ClassItemA cb = new ClassItemA();
cb.item = sb.ToString();
cb.count = 0;
b.Add(cb);
}
List
string[] s2 = { "B00B0YJQPK", "B0046HF4AY", "B00BGL8YWS", "B0006G4MH0" };
foreach (string sb in s2)
{
ClassItemB cc = new ClassItemB();
cc.item = sb.ToString();
c.Add(cc);
}
Console.ReadLine();
}
--
Now I have to write a linq to get the items form classItemB object where items from ClassItemA which has count > 0.
Please suggest.
VulpesPosted Jan 17, 2014, 8:19 AM
The output should be:
Lawrence PondPosted Jan 20, 2014, 1:47 AM
Hello
Before the ConsoleReadLine(); insert the following code snippet
var result = from c1 in c
from b1 in b
where (b1.item == c1.item)
where (b1.count > 0)
select b1;
I just used a standard inner join here are the results
Rahul ShindePosted Jan 20, 2014, 12:39 AM