tags:

views:

61

answers:

2

I have 2 lists. The first is a CountryId-list that can look like this

036
208
999

The seccond list is a coundryId to Name list that can look like this:
036, AUSTRALIA
208, DENMARK
380, ITALY
578, NORWAY

The result shall be like this:
AUSTRALIA
DENMARK
UNKNOWN ID (999)

How can I make a linq query that solves this?

A: 

A solution might be an implementing of a left outer join

Here is a resource with an example - How to: Perform Left Outer Joins (C# Programming Guide)

The DefaultIfEmpty() would be your unknown country

Svetlozar Angelov
A: 

Use LinqPad to demonstrate small part of code.
Try this solution:

List<string> ids = new List<string>(){"036","208","999"};
Dictionary<string,string> data = new Dictionary<string,string>(){
             {"036","AUSTRALIA"},  {"208","DENMARK"},
             {"380","ITALY"},{"578","NORWAY"}};
var res = from id in ids 
          from d in data
          where id == d.Key
          select d.Value;
res = res.Union(from id in ids
                where !(from d in data select d.Key).Contains(id)
                select "UNKNOWN ID ("+id+")");
res.Dump();
t34