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

            <2013年6月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            30123456

            導航

            統計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            久久亚洲精品中文字幕三区| 精品久久人人爽天天玩人人妻| 色8久久人人97超碰香蕉987| 99热精品久久只有精品| 国产精品熟女福利久久AV| 精品多毛少妇人妻AV免费久久| 久久国产精品99国产精| 久久精品无码免费不卡| 久久久久亚洲AV无码专区体验| 亚洲精品乱码久久久久久蜜桃图片| 9久久9久久精品| 久久99热这里只有精品国产| 久久久久国色AV免费看图片| 精品久久亚洲中文无码| 情人伊人久久综合亚洲| 久久青青国产| 国产日韩久久久精品影院首页| 伊人色综合久久天天网| 精品久久久久久久久午夜福利| 久久久午夜精品福利内容| 国产亚洲综合久久系列| 国产精品伦理久久久久久| 亚洲愉拍99热成人精品热久久| 欧美日韩成人精品久久久免费看| 91精品国产91久久久久福利| 欧美亚洲国产精品久久蜜芽| 亚洲欧美伊人久久综合一区二区| 久久99精品久久久久久9蜜桃| 久久久久久久亚洲Av无码| 久久精品夜色噜噜亚洲A∨| 色婷婷久久综合中文久久蜜桃av| 狠狠色丁香久久婷婷综合| 久久伊人色| 91久久精品电影| 欧美精品一本久久男人的天堂| 久久久噜噜噜久久中文字幕色伊伊 | AAA级久久久精品无码区| 久久亚洲精品人成综合网| 国产成人久久精品一区二区三区 | 亚洲综合精品香蕉久久网97| 久久精品一本到99热免费|