C# 常用扩展方法

Posted zhang1f

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C# 常用扩展方法相关的知识,希望对你有一定的参考价值。

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

namespace CommonSD

    public static class MyExtensions
    
        public static void DisplayDefiningAssembly(this object obj) // 
        
            //Console.WriteLine("0 lives here:=> 1\n", obj.GetType().Name, Assembly.GetAssembly(obj.GetType()).GetName().Name);
        

        public static int ReverseDigits(this int i)
        
            // 把int翻译为string然后获取所有字符
            char[] digits = i.ToString().ToCharArray();
            // 现在反转数组中的项
            Array.Reverse(digits);
            // 放回string
            string newDigits = new string(digits);
            // 最后以int返回修改后的字符串
            return int.Parse(newDigits);
        

        public static int ToInt(this string value)
        
            return int.Parse(value);
        
    

以后内容再做补充

以上是关于C# 常用扩展方法的主要内容,如果未能解决你的问题,请参考以下文章

C# DataRow的扩展

this(C# 参考)

C# 扩展方法

C#的扩展方法解析

如何使用 c# 扩展方法扩展类? [复制]

最佳实践:C# 扩展方法命名空间和推广扩展方法