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

            鏈接

            最新隨筆

            搜索

            最新評論

            久久国产精品-久久精品| 久久综合久久综合久久| 狠狠色丁香久久婷婷综合_中 | 亚洲欧美久久久久9999 | 99久久精品国产一区二区蜜芽| 99久久精品九九亚洲精品| 无码人妻久久一区二区三区蜜桃| 欧美国产成人久久精品| 久久香综合精品久久伊人| 国产叼嘿久久精品久久| 亚洲人成伊人成综合网久久久| 一级做a爰片久久毛片16| 亚洲伊人久久综合中文成人网| 久久夜色精品国产网站| 99久久国产亚洲高清观看2024| 伊人久久大香线蕉综合热线| 97久久超碰成人精品网站| 99久久这里只精品国产免费| 狠狠狠色丁香婷婷综合久久俺| 亚洲精品NV久久久久久久久久| 国内精品久久久久伊人av | 久久久国产精品亚洲一区| 99久久精品无码一区二区毛片 | 久久综合亚洲色一区二区三区| 91精品婷婷国产综合久久 | 久久青青草原精品国产| 无码人妻久久一区二区三区蜜桃| 国产精品久久自在自线观看| 亚洲精品无码久久久影院相关影片| 国产精品成人久久久久三级午夜电影| 国产毛片欧美毛片久久久| 亚洲精品综合久久| 久久露脸国产精品| 久久久久黑人强伦姧人妻| 久久国产免费观看精品| 精品久久久久久久久中文字幕| 久久一日本道色综合久久| 久久狠狠高潮亚洲精品| 中文字幕久久波多野结衣av| 国产精品久久久香蕉| 久久精品国产免费观看|