您的位置:首页 > 其它

Linq101-Miscellaneous

2015-04-22 15:15 190 查看
using System;
using System.Collections.Generic;
using System.Linq;

namespace Linq101
{
class Miscellaneous
{
/// <summary>
/// This sample uses Concat to create one sequence that contains each array's values, one after the other.
/// </summary>
public void Linq94()
{
int[] numbersA = { 0, 2, 4, 5, 6, 8, 9 };
int[] numbersB = { 1, 3, 5, 7, 8 };

var allNumbers = numbersA.Concat(numbersB);

Console.WriteLine("All numbers from both arrays:");

foreach (int number in allNumbers)
{
Console.WriteLine(number);
}
}

/// <summary>
/// This sample uses Concat to create one sequence that contains the names of all customers and products, including any duplicates.
/// </summary>
public void Linq95()
{
List<Data.Customer> customers = Data.GetCustomerList();
List<Data.Product> products = Data.GetProductList();

var customerNames = from c in customers
select c.CompanyName;
var productNames = from p in products
select p.ProductName;

var allNames = customerNames.Concat(productNames);

Console.WriteLine("Customer and product names:");

foreach (string name in allNames)
{
Console.WriteLine(name);
}
}

/// <summary>
/// This sample uses EqualAll to see if two sequences match on all elements in the same order.
/// </summary>
public void Linq96()
{
var wordsA = new[] { "cherry", "apple", "blueberry" };
var wordsB = new[] { "cherry", "apple", "blueberry" };

bool match = wordsA.SequenceEqual(wordsB);

Console.WriteLine("The sequences match :{0}", match);
}

/// <summary>
/// This sample uses EqualAll to see if two sequences match on all elements in the same order.
/// </summary>
public void Linq97()
{
var wordsA = new[] { "cherry", "apple", "blueberry" };
var wordsB = new[] { "apple", "blueberry", "cherry" };

bool match = wordsA.SequenceEqual(wordsB);

Console.WriteLine("The sequences match: {0}", match);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: