首页 > 代码库 > 扩展方法小参考

扩展方法小参考

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
public class Student
{
public string name;
public string age;
}
public static class ExtentionMethod
{
public static Student Add(this Student str)
{
Student stu=str;
stu.name="aa";
stu.age="11";
return stu;
}
}
class Program
{

static void Main(string[] args)
{
Student stu = new Student();
stu = stu.Add();
Console.WriteLine(stu.age);
}
}
}

扩展方法小参考