• <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)論

            欧美激情一区二区久久久| 99久久人妻无码精品系列| 国产福利电影一区二区三区久久久久成人精品综合 | 久久久久久久久久久免费精品| 日本精品久久久久久久久免费| 伊人久久大香线蕉亚洲五月天| 久久99国产精品尤物| 久久久网中文字幕| 久久精品aⅴ无码中文字字幕不卡| 国产高清国内精品福利99久久| 久久婷婷人人澡人人爽人人爱 | 国产成人精品久久免费动漫| 国产福利电影一区二区三区久久老子无码午夜伦不 | 国产精品欧美久久久久天天影视| 日本久久中文字幕| 97久久精品人妻人人搡人人玩| 四虎亚洲国产成人久久精品| 精品久久久久久无码中文字幕一区| 久久久久人妻精品一区三寸蜜桃| 亚洲精品乱码久久久久久久久久久久| 青青草国产精品久久| 国产精品一久久香蕉国产线看| 色播久久人人爽人人爽人人片aV| 久久精品国产半推半就| 热re99久久精品国99热| 久久这里的只有是精品23| 久久WWW免费人成—看片| 久久91精品久久91综合| 色婷婷综合久久久久中文| 久久久SS麻豆欧美国产日韩| 亚洲午夜精品久久久久久app| 久久夜色撩人精品国产小说| 久久久国产精品| 精品国产综合区久久久久久| 狠狠色丁香婷婷综合久久来来去| 欧美亚洲另类久久综合| 国产精品熟女福利久久AV| 久久精品成人国产午夜| 国产午夜精品久久久久九九| 女人香蕉久久**毛片精品| 伊人久久免费视频|