扩展方法实例
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ExtentsFunctions
{
class Program
{
static void Main(string[] args)
{
string str = "A";
Console.WriteLine(str.ConvertStr());
int ints = 100;
Console.WriteLine(ints.ConvertInt32());
Console.ReadLine();
}
}
public static class Extents
{
public static string ConvertStr(this string str)
{
return "new string format strings:" + str;
}
public static string ConvertInt32(this int ints)
{
return "new int format strings:" + ints;
}
}
}