Q: Custom arrays compare or find value which is not exist in another array with linq I have two custom class, 


*

*BeneficiaryResponse and 

*BeneficiaryDetail
Both have key Id and AliasName field. 
I want to those missing value from 1st class i.e. BeneficiaryResponse which is not exist in Beneficiary Detail with help of Linq query.
eg. BeneficiaryResponse have 30 parameters and Beneficiary have 20 parameters then i want those missing 10 parameters from BeneficiaryResponse.
public class BeneficiaryDetail
{
     public BeneficiaryDetail[] beneInternal
     {
        get;
        set;
     }

     public int? Id
     {
        get;
        set;
     }

     public string AliasName
     {
        get;
        set;
     }
}

public class BeneficiaryResponse
{
    public int Id
    {
        get;
        set;
    }

    public string AliasName
    {
        get;
        set;
    }
}

Now BeneficiaryResponse have following,
[{"Id":763886,"AliasName":"ABC-3594"},
 {"Id":763759,"AliasName":"ABC-6789"},
 {"Id":763661,"AliasName":"ABC-9111"},
 {"Id":763668,"AliasName":"ABC-9111"},
 {"Id":764467,"AliasName":"ABC-3594"}]
and BeneficiaryDetail have,
[{"Id":763886,"AliasName":"ABC-3594"},
 {"Id":763759,"AliasName":"ABC-6789"},
 {"Id":764467,"AliasName":"ABC-3594"}]
How to get rest of 2 missing from BeneficiaryResponse.

A: You can use following linq code for output. 
It will give output based on ID parameter.
It may be helpful for you.
var result= (from c in BeneficiaryResponse 
             where !(from o in BeneficiaryDetail select o.ID).Contains(c.ID)  
             select c);

or
var result= from BResponse in BeneficiaryResponse 
            where !(BeneficiaryDetail.Any
                   (BDetail => BDetail.ID == Response.ID 
                    && BDetail.AliasName == BResponse.AliasName))
            select BResponse;


A: Add Newtonsoft.Josn dll
    public void Main(string[] args)
    {
        string strBR = "[{ 'Id':763886,'AliasName':'ABC-3594'},{ 'Id':763759,'AliasName':'ABC-6789'},{ 'Id':763661,'AliasName':'ABC-9111'},{ 'Id':763668,'AliasName':'ABC-9111'},{ 'Id':764467,'AliasName':'ABC-3594'}]";
        string strBD = " [{'Id':763886,'AliasName':'ABC-3594'},{'Id':763759,'AliasName':'ABC-6789'},{'Id':764467,'AliasName':'ABC-3594'}]";

        var resultBR = JsonConvert.DeserializeObject<List<BeneficiaryResponse>>(strBR);
        var resultBD = JsonConvert.DeserializeObject<List<BeneficiaryDetail>>(strBD);

        var missingData = resultBR.Where(x => !resultBD.Select(n => n.Id).Contains(x.Id)).ToList();

        foreach (var item in missingData)
        {
            Console.WriteLine(item.Id);
        }

    }
    public class BeneficiaryResponse
    {
        public int Id { get; set; }
        public string AliasName { get; set; }

    }
    public class BeneficiaryDetail
    {
        public int Id { get; set; }
        public string AliasName { get; set; }
    }


Output: 763661 763668

