Friday, December 25, 2020

Concat method merge results from two separate LINQ queries into single result set - LINQ

 Q.  How you can merge the results from two separate LINQ queries into a single result set.


a. Use the ToList method.
b. Use the DataContractJsonSerializer class.
c. Use the XElement class.
d. Use the Concat method.

ANSWER: Use the Concat method.
 
Concat method is used to merge two separate lists together to form a single list.

class Program
{
static void Main()
{
List<string> list1 = new List<string>();
list1.Add( " A " );
list1.Add( " B " );

List<string> list2 = new List<string>();
list2.Add( " C " );
list2.Add( " D " );

var result = list1.Concat(list2);
List<string>finalList = result.ToList();
foreach (var entry in finalList)
{
Console.WriteLine(entry);
}
}
}

No comments:

Post a Comment

Get max value for identity column without a table scan

  You can use   IDENT_CURRENT   to look up the last identity value to be inserted, e.g. IDENT_CURRENT( 'MyTable' ) However, be caut...