8,497
社区成员
发帖
与我相关
我的任务
分享
static class Program
{
static void Main(string[] args)
{
LinqTest();
}
public static void LinqTest()
{
int[] vectorA = { 0, 2, 4, 5, 6 };
int[] vectorB = { 1, 3, 5, 7, 8 };
foreach (var num in vectorA.Combine(vectorB, (a, b) => a * b))
{
Console.WriteLine("Dot product: {0}", num);
}
Console.ReadLine();
}
public static IEnumerable<int> Combine(this IEnumerable<int> first, IEnumerable<int> second, Func<int, int, int> func)
{
var e1 = first.GetEnumerator();
var e2 = second.GetEnumerator();
while (e1.MoveNext() && e2.MoveNext())
yield return func(Convert.ToInt32(e1.Current), Convert.ToInt32(e2.Current));
}
}
var h = new Hashtable { {"fuck", "fuck you"}, {"shit", "a piece of shit"}, {"dick", "suck my dick"} };
Func<Hashtable, string> fuck = f => { return f.Contains("fuck") ? f["fuck"].ToString() : "I don't give a fuck"; };
Label1.Text = fuck(h);