• <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 天下 閱讀(417) 評論(0)  編輯 收藏 引用 所屬分類: C#

            <2018年4月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            導航

            統計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            天天躁日日躁狠狠久久| 亚洲国产精品久久66| 久久综合九色欧美综合狠狠| 伊人久久成人成综合网222| 77777亚洲午夜久久多喷| 久久99精品久久久久久| 一本久久精品一区二区| 国产精品无码久久久久久| 精品国产综合区久久久久久| 欧美精品丝袜久久久中文字幕 | 99精品伊人久久久大香线蕉| 久久精品国产清自在天天线| 亚洲精品无码久久久久| 久久精品国产WWW456C0M| 久久人人爽人人爽人人片av高请| 久久精品国内一区二区三区| 久久婷婷五月综合成人D啪 | 伊人精品久久久久7777| 99久久精品国产麻豆| 性欧美大战久久久久久久| 久久精品www| 国产亚洲美女精品久久久2020| 国产精品免费久久久久久久久 | 久久久久国色AV免费观看| 久久精品无码专区免费东京热| 欧美午夜A∨大片久久| 国产L精品国产亚洲区久久| 久久久久亚洲精品天堂| 国产A三级久久精品| 亚洲精品成人网久久久久久| 国产精品xxxx国产喷水亚洲国产精品无码久久一区| 精品久久久久成人码免费动漫| 狠狠色伊人久久精品综合网 | 久久99精品久久久久久hb无码| 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 热久久最新网站获取| 久久人人爽人人爽人人片AV麻豆 | 久久精品青青草原伊人| 亚洲成av人片不卡无码久久 | 伊人热热久久原色播放www| 亚洲精品美女久久久久99小说|