ZengCode.Com (The Thai Php Framework)  


Home   Download   Manual   About us    

Facebook   


MAIN MENU
News
Php Tips
Android Programming
Design Pattern By PHP
C# using Linq น่าใช้จริงๆ
C# Tips & Technique
C# Design Pattern
Linux Quick Tips
Java & JavaScript Tips
Database & SQL
ZengCode Framework Guide
Zeng Code Code
Programming
IPhone (Tips and Trick)

Download เอกสารที่น่าสนใจ

      เคยสงสัยไหมว่า Object เรียก method เป็นทอดๆ ได้ยังไง  (2009-09-11)

ผมคิดว่าน่าจะประมาณนี้นะครับ

<?php
Class MyObj{
    function A(){
        echo "AAAAAA    ";
        return $this;
    }
    function B(){
        echo "BBBBBB    ";
        return $this;
    }
    function C(){
        echo "CCCCCC    ";
        return $this;
    }
}

class TestClass {
      public  $Obj;
      function TestClass(){
          $this->Obj = new MyObj();
      }
}

$test = new TestClass();
$test->Obj->A()->B()->C();
?>

ถ้าเป็น C# ก็ประมาณนี้นะ

class Test
    {
        public Test  A()
        {
            Console.WriteLine("A");
            return this;
        }
        public Test B()
        {
            Console.WriteLine("B");
            return this;
        }
        public Test C()
        {
            Console.WriteLine("C");
            return this;
        }
    }


    class Program
    {
        static void Main(string[] args)
        {
            Test test = new Test();
            test.A().B().C();
            Console.Read();
        }
    }

 

 

เป็นไงล่ะ เท่ห์ซะไม่มีผมว่า

 


Comment
Name
Comment
Security CodeCAPTCHA Image

easy tracking
avis car rental discount code

This page took 0.067775 seconds to load.