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);
}
}
}
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