链式编程example

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Person p = new Person();
            //链式编程
            p.Sayhi().Hello();
            Console.ReadKey();
        }
    }
    class Person
    {
        public int Age { get; set; }
        public string  Name { get; set; }
        public Person Sayhi()
        {
            Console.WriteLine(
                "hhaha");
            //链式编程的关键:执行方法之后,返回当前对象.
            return this;
        }
        public Person Hello()
        {
            Console.WriteLine(
                "hello");
            return this;
        }
    }
}

posted @ 2013-07-26 00:23  nqsan  阅读(167)  评论(0编辑  收藏  举报