| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2264 人关注过本帖
标题:求一段能编译通过的int类型的拓展方法
只看楼主 加入收藏
the_second
Rank: 2
等 级:论坛游民
帖 子:115
专家分:80
注 册:2015-9-13
结帖率:78.95%
收藏
已结贴  问题点数:20 回复次数:2 
求一段能编译通过的int类型的拓展方法
例如调用的时候
int i = 1234;
           Console.WriteLine(i.ReverseDigits());
ReverseDigits()为int的拓展函数
求一段代码借鉴借鉴,学习一下,谢谢
搜索更多相关主题的帖子: 拓展 
2016-04-21 22:45
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:8 
http://blog.
http://
https://msdn.

   唯实惟新 至诚致志
2016-04-21 23:26
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:12 
程序代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleTest
{
    static class intExtendMethod
    {
        public static void showmsg(this int i)
        {
            Console.WriteLine("int show extend message!");
        }

        public static int ReverseDigits(this int i)
        {
            /*************/
            /*degisn here*/
            /*************/
            return --i;  //return your result
        }

        public static int addOne(this int i,int n)
        {
            return i + n;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Program test = new Program();

            int i = 0;           
            test.testExtend(i, 1);

            i = 12345;
            test.testExtend(i, 10);

            i = -12345;
            test.testExtend(i, -10);

            Console.ReadKey();
        }

        private void testExtend(int m,int n)
        {
            m.showmsg();
            Console.WriteLine("{0}", m.ReverseDigits());
            Console.WriteLine("{0}", m.addOne(n));
        }
    }
}

   唯实惟新 至诚致志
2016-04-22 09:02
快速回复:求一段能编译通过的int类型的拓展方法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015934 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved