• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天下

            記錄修行的印記

            C#委派Delegate

            1:
            //直接上MSDN上的C#代碼:
            using System;
            public class SamplesDelegate
            {

                
            // Declares a delegate for a method that takes in an int and returns a String.
                public delegate String myMethodDelegate(int myInt);

                
            // Defines some methods to which the delegate can point.
                public class mySampleClass
                {

                    
            // Defines an instance method.
                    public String myStringMethod(int myInt)
                    {
                        
            if (myInt > 0)
                            
            return ("positive");
                        
            if (myInt < 0)
                            
            return ("negative");
                        
            return ("zero");
                    }

                    
            // Defines a static method.
                    public static String mySignMethod(int myInt)
                    {
                        
            if (myInt > 0)
                            
            return ("+");
                        
            if (myInt < 0)
                            
            return ("-");
                        
            return ("");
                    }
                }

                
            public static void Main()
                {

                    
            // Creates one delegate for each method. For the instance method, an
                    
            // instance (mySC) must be supplied. For the static method, use the
                    
            // class name.
                    mySampleClass mySC = new mySampleClass();
                    myMethodDelegate myD1 
            = new myMethodDelegate(mySC.myStringMethod);
                    myMethodDelegate myD2 
            = new myMethodDelegate(mySampleClass.mySignMethod);

                    
            // Invokes the delegates.
                    Console.WriteLine("{0} is {1}; use the sign \"{2}\"."5, myD1(5), myD2(5));
                    Console.WriteLine(
            "{0} is {1}; use the sign \"{2}\"."-3, myD1(-3), myD2(-3));
                    Console.WriteLine(
            "{0} is {1}; use the sign \"{2}\"."0, myD1(0), myD2(0));
                }

            }


            2:
            // d11.cpp : Defines the entry point for the console application.
            //C++代碼

            #include 
            "stdafx.h"
            #include 
            <iostream>
            #include 
            <string>

            using namespace std;

            typedef 
            string myMethodDelegate(int myInt);

            string myStringMethod ( int myInt )  {
                
            if ( myInt > 0 )
                    
            return string"positive" );
                
            if ( myInt < 0 )
                    
            return string"negative" );
                
            return string"zero" );
            }

            string mySignMethod ( int myInt )  {
                
            if ( myInt > 0 )
                    
            return string"+" );
                
            if ( myInt < 0 )
                    
            return string"-" );
                
            return  string"" );
            }

            int _tmain(int argc, _TCHAR* argv[])
            {
                myMethodDelegate
            * myD1 = myStringMethod;
                myMethodDelegate
            * myD2 = mySignMethod;

                
            // Invokes the delegates.
                printf( "{%d} is {%s}; use the sign \"{%s}\". \r\n"5, myD1( 5 ).c_str(), myD2( 5 ).c_str() );
                printf( 
            "{%d} is {%s}; use the sign \"{%s}\". \r\n"-3, myD1( -3 ).c_str(), myD2( -3 ).c_str() );
                printf( 
            "{%d} is {%s}; use the sign \"{%s}\".\r\n"0, myD1( 0 ).c_str(), myD2( 0 ).c_str() );
                
            return 0;
            }







            posted on 2012-06-07 16:41 天下 閱讀(407) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C#

            <2015年12月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評(píng)論

            久久久久亚洲?V成人无码| 狠狠88综合久久久久综合网| 久久精品国产亚洲AV无码娇色 | 日韩欧美亚洲综合久久| 99久久精品免费国产大片| 九九久久99综合一区二区| 亚洲国产欧美国产综合久久| 囯产极品美女高潮无套久久久 | 久久精品国产精品亚洲艾草网美妙 | 青青久久精品国产免费看 | 亚洲国产成人精品女人久久久 | 久久天天躁狠狠躁夜夜不卡 | 少妇久久久久久被弄高潮| 亚洲欧洲日产国码无码久久99| 麻豆久久久9性大片| 久久精品国产2020| 伊人久久综合精品无码AV专区| 性做久久久久久久| 漂亮人妻被黑人久久精品| 99国产欧美久久久精品蜜芽| 伊人久久大香线蕉精品| 青青草原综合久久大伊人导航 | 久久久国产打桩机| 久久久久亚洲AV无码专区体验| 久久精品视频免费| 亚洲国产成人久久一区WWW| 精品久久久久成人码免费动漫| 午夜精品久久久久久久| 中文字幕亚洲综合久久| 久久毛片一区二区| 精品精品国产自在久久高清| 欧美粉嫩小泬久久久久久久 | 午夜精品久久久久成人| 欧洲成人午夜精品无码区久久 | 久久99精品久久久久久久不卡| 品成人欧美大片久久国产欧美... 品成人欧美大片久久国产欧美 | 狠狠色丁香久久婷婷综合图片| 久久男人Av资源网站无码软件| 久久精品无码一区二区日韩AV| 97久久国产露脸精品国产| 久久精品嫩草影院|