首页 > 其他 > 详细

使用扩展方法(this 扩展类型)

时间:2014-03-19 02:10:01      阅读:357      评论:0      收藏:0      [点我收藏+]

namespace ConsoleApp_UseExtendWays
{
class Program
{
static void Main(string[] args)
{
Student s = new Student();
Console.WriteLine(s.GetSexString());
Console.WriteLine(s.GetAge());
Console.ReadKey();
}
}
public static class StudentExtension
{
public static string GetSexString(this Student argStudent)//扩展方法 this 扩展类型
{
return argStudent.GetSex() == true ? "男" : "女";
}

public static int GetAge(this Student ss)
{
return ss.Age;
}
}
public class Student
{
public bool GetSex()
{
return false;
}

public int Age = 12;
}

//public static class StudentConverter
//{
// public static string GetSexString(Student argStudent)
// {
// return argStudent.GetSex() == true ? "男" : "女";
// }
//}
}

使用扩展方法(this 扩展类型),布布扣,bubuko.com

使用扩展方法(this 扩展类型)

原文:http://www.cnblogs.com/jx270/p/3608938.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!