C#_扩展方法

简述:

  • 扩展方法所属类必需是静态类(类名依据规范通常为XXXExtension,XXX为被扩展类)
  • 扩展方法必需是公有静态方法
  • 扩展方法的首个参数由this修饰,参数类型为被扩展类型

示例:

cs 复制代码
static class DoubleExtension
{
    public static double Round(this double input, int digits)
    {
        double result = Math.Round(input, digits);
        return result;
    }
}

此时可对double类型的变量调用Round方法

相关推荐
宝桥南山31 分钟前
GitHub Models - 尝试一下使用GitHub Models
microsoft·ai·微软·c#·github·.netcore
hixiong1233 小时前
C# OpenvinoSharp部署INSID3
开发语言·人工智能·ai·c#·openvinosharp
星辰徐哥4 小时前
Unity C#入门:变量的定义与访问权限(public/private)
unity·c#·lucene
leoufung4 小时前
LeetCode 30:Substring with Concatenation of All Words 题解(含 C 语言 uthash 实现)
c语言·leetcode·c#
hacker7074 小时前
Visual Studio安装教程(C#开发版)
ide·c#·visual studio
SKY -dada5 小时前
Understand 使用教程
开发语言·c#·流程图·软件构建·敏捷流程·代码复审·源代码管理
William_cl7 小时前
【C#/.NET 进阶】ASP.NET 架构与最佳实践:DI 依赖注入(IoC 核心)从入门到避坑
c#·asp.net·.net
武藤一雄7 小时前
WPF:MessageBox系统消息框
前端·microsoft·c#·.net·wpf
武藤一雄7 小时前
WPF进阶:万字详解WPF如何性能优化
windows·性能优化·c#·.net·wpf·.netcore·鲁棒性
xiaogutou11211 天前
2026年历史课件PPT模板选购指南:教师备课效率与精度的平衡方案
开发语言·c#