using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LocalApp.ConsoleApp
{
class Program
{
delegate void LambdaHandler();
static void Main(string[] args)
{
//Func 封裝一個具有 1 - 4 個引數並返回 TResult 引數指定的型別值的方法。
Func<int, string> func = delegate(int i) { return Convert.ToString(i * i); };
Console.WriteLine(func(3));
/**//******************************************/
// lambda 表示式,i 引數
Func<int, string> func2 = i => Convert.ToString(i * i);
Console.WriteLine(func2(4));
/**//******************************************/
Func<string, string> func3 = a => a.ToUpper();
string[] array = { "hebei","hubei","beijing","12" };
IEnumerable<string> _array = array.Where<string>(b => b.EndsWith("i")); // array.Select(func3);
foreach (string i in _array)
Console.WriteLine(i);
/**//******************************************/
Func<string, string, string, string, string> __func = (a, b, c, d) => { return a + "_" + b + "_" + c + "_" + d; };
Console.WriteLine(__func("h","e","l","lo"));
/**//******************************************/
Func<string> __func2 = () => "123456";
Console.WriteLine(__func2());
/**//******************************************/
LambdaHandler lam = () => Console.WriteLine( "1111111111");
lam += () => Console.WriteLine("22222222222");
lam();
/**//******************************************/
//擴充套件方法
string extTest = "hello world";
Console.WriteLine(extTest.WordCount());
foreach(string i in extTest.WordSplit())
{
Console.WriteLine(i);
}
/**//******************************************/
Console.ReadKey(true);
}
}
/**//// <summary>
/// 擴充套件方法
/// </summary>
public static class Extensions
{
public static int WordCount(this String str)
{
return str.Split(new char[] { ' ', '.', '?' }, StringSplitOptions.RemoveEmptyEntries).Length;
}
public static string[] WordSplit(this String str)
{
return str.Split(new char[] {' ','.','?' }, StringSplitOptions.None);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LocalApp.ConsoleApp
{
class Program
{
delegate void LambdaHandler();
static void Main(string[] args)
{
//Func 封裝一個具有 1 - 4 個引數並返回 TResult 引數指定的型別值的方法。
Func<int, string> func = delegate(int i) { return Convert.ToString(i * i); };
Console.WriteLine(func(3));
/**//******************************************/
// lambda 表示式,i 引數
Func<int, string> func2 = i => Convert.ToString(i * i);
Console.WriteLine(func2(4));
/**//******************************************/
Func<string, string> func3 = a => a.ToUpper();
string[] array = { "hebei","hubei","beijing","12" };
IEnumerable<string> _array = array.Where<string>(b => b.EndsWith("i")); // array.Select(func3);
foreach (string i in _array)
Console.WriteLine(i);
/**//******************************************/
Func<string, string, string, string, string> __func = (a, b, c, d) => { return a + "_" + b + "_" + c + "_" + d; };
Console.WriteLine(__func("h","e","l","lo"));
/**//******************************************/
Func<string> __func2 = () => "123456";
Console.WriteLine(__func2());
/**//******************************************/
LambdaHandler lam = () => Console.WriteLine( "1111111111");
lam += () => Console.WriteLine("22222222222");
lam();
/**//******************************************/
//擴充套件方法
string extTest = "hello world";
Console.WriteLine(extTest.WordCount());
foreach(string i in extTest.WordSplit())
{
Console.WriteLine(i);
}
/**//******************************************/
Console.ReadKey(true);
}
}
/**//// <summary>
/// 擴充套件方法
/// </summary>
public static class Extensions
{
public static int WordCount(this String str)
{
return str.Split(new char[] { ' ', '.', '?' }, StringSplitOptions.RemoveEmptyEntries).Length;
}
public static string[] WordSplit(this String str)
{
return str.Split(new char[] {' ','.','?' }, StringSplitOptions.None);
}
}
}