using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
{
delegate int MyDelegate(int x,int y);
class Program
{
static void Main(string[] args)
{
MyDelegate d = delegate(int a, int b)
{
if (a > b)
{
return a;
}
else
return b;
};
Console.WriteLine(d(2,3));
Console.ReadKey(false);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 获取字符串中单词的数量
{
public static class Extensions
{
public static int GetWordCount(this string s)
{
int intCount=0;
string []strArray=s.Split(' ');
foreach(var str in strArray)
{
if(str.Length>0)intCount++;
}
return intCount;
}
}
class Program
{
static void Main(string[] args)
{
string s="this is an apple";
Console.WriteLine("单词数量为{0}",s.GetWordCount());
Console.ReadKey();
}
}
}
Lambda表达式初体验·
最新推荐文章于 2024-08-14 20:13:39 发布