zoukankan      html  css  js  c++  java
  • Linq原理(扩展方法)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Collections;

    namespace ConsoleApplication1
    {
        static class Book
        {
            public static Double ToDouble(this string s)
            {
                return Double.Parse(s);
            }
        }

        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("12".ToDouble());
                Console.Read();
            }
        }
    }

    扩展方法一定要放在静态类中,扩展方法必须是静态的,注意参数(this string s)  this 后的类型表示扩展那个类型

    上面代码的意思是扩展string 中的ToDouble方法

  • 相关阅读:
    找水王续
    找水王续
    本周学习进度
    Node.js 学习
    在Linux机器上安装MySQL
    ZStack串口通信
    Java编写串口程序
    ServerSocket
    ZigBee毕设
    ZigBee相关网站链接
  • 原文地址:https://www.cnblogs.com/blosaa/p/2055869.html
Copyright © 2011-2022 走看看