c# - 字符串用户函数

标签 c#

如何向字符串类型添加自定义函数

例子:

string test = "hello";

test.userFn("world");

public string userFn(strng str) {
   return " " + str;
}

最佳答案

http://msdn.microsoft.com/en-us/library/bb383977.aspx

namespace ExtensionMethods
{
    public static class MyExtensions
    {
        public static string userFn(this string str)
        {
            return " " + str;
        }
    }   
}

关于c# - 字符串用户函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1850503/

相关文章:

c# - 如何在 C# 中实现长轮询客户端?

c# - 无法将 Json 对象反序列化为字典

c# - 从 SOAP 响应中获取附件并保存文件

c# - 默认方法是 "virtual"还是 "not virtual"? :

c# - IronPython 可以向 C# 类动态添加方法吗?

c# - Interlocked 用于递增/模拟 bool 值,这安全吗?

c# - 从 Cosmos 中删除数据时出现分区键错误

c# - 将位图保存为 32bpp 不保持透明度

c# - 设置没有 Setter 的 C# 属性

c# - 以管理员身份运行 cmd 和命令?