简单的扩展方法

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

namespace linqlinq
{
    class Program
    {
        /// <summary>
        /// 扩展方法
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {

            string s = "fdsfs";
          
            Console.WriteLine(s.AddSep());
            Console.ReadKey();
        }
    }
    public static class stringExt//必须是静态类
    {
        public static string AddSep(this string s)//必须是静态方法,要增加的 this(必须加) string(要增加扩展方法的类) s(参数)
        {
            return "["+s+"]";
        }
    }
}

posted @ 2011-05-19 18:14  winchou  阅读(174)  评论(0编辑  收藏  举报