I have two list : (Note: List’s Items are combination of “NAME” & “ID” )
List<string> ListA = new List() {"SAM001","SAM002","SAM003","PIT001","PIT002","PIT004","ROSE001","ROSE002","JASE001" };
//so on
List<string> ListB = new List() {"SAM001","SAM003","PIT000","ROSE002","JASE001","INDI000"};`
//so on...
Now Based on these two list i want to create two new list suppose listCommon & listUncommon.
listCommon will contain all matched items of ListA & ListB.
listUnCommon will contain all remaining items of ListA
Now My condition is if Any item in ListB has NAME + 000 then all the items of ListA starting with that Name should add in my listCommon.
Example 1 : if ListB item is PIT000 and ListA item are PIT001,PIT002,PIT003,ABC001
then listCommon = PIT001,PIT002,PIT003 because ListB has PIT with 000 so condition true all ListA ‘PIT’ items added in listcommon
So as above list and my condition i want my final list below
List<string> listCommon = new List() {"SAM001","SAM003", "PIT001","PIT002","PIT004","ROSE002", "JASE001" };
List<string> listUncommon = new List() {"SAM002", "ROSE001"};
Please suggest..i just spend my couple of minutes in loops but not getting actual result as i mentioned 🙁
This should work.
Using an insersect, then you are selecting any from list A where list B has an entry that matches the first 3 letters and ends with 000.
This is not the most efficient way of doing this, however it is terse code-wise.