扩展方法实例

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;
        }
    }
}

posted @ 2013-05-15 16:06  yuloe2012  阅读(127)  评论(0编辑  收藏  举报