110,535
社区成员
发帖
与我相关
我的任务
分享
using System;
namespace Test
{
class Program
{
static void Main(string[] args)
{
string s = "Hello Extension Methods";
int i = s.WordCount();
Console.WriteLine(i.ToString());
Console.ReadKey();
}
}
public static class MyExtensions
{
public static int WordCount(this String str)
{
return str.Split(new char[] { ' ', '.', '?' }, StringSplitOptions.RemoveEmptyEntries).Length;
}
}
}
public static bool IsNull(this object o)
{
return o == null;
}
object o = null;
bool isnull = o.IsNull();
public static bool IsNull(this object o)
{
return object == null;
}
object o = null;
bool isnull = o.IsNull();
public static EntityDto ToEntityDto(this Entity entity)
{
EntityDto result = new EntityDto();
//将entity转换成EntityDto。
......
return result;
}
var e = new Entity();
var dto = e.ToEntityDto();