Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在String类-C中添加方法#_C#_String_Methods_Extension Methods_Static Methods - Fatal编程技术网

C# 如何在String类-C中添加方法#

C# 如何在String类-C中添加方法#,c#,string,methods,extension-methods,static-methods,C#,String,Methods,Extension Methods,Static Methods,我希望在string类下添加以下方法IsProcess(string str) 对于ExmapleString.IsNullOrEmpty(str) 我不希望像“Value.IsProcess() 我的期望值是String.IsProcess(value) 请帮助我。你不能 您可以创建扩展方法。除此之外,无法向System.String添加其他静态成员。请在没有扩展方法的情况下查看,这可能是不可能的。另外,String类是密封的,所以您不能扩展它。您不能向类添加任意静态方法。没有这种能力。您可以

我希望在string类下添加以下方法
IsProcess(string str)

对于Exmaple
String.IsNullOrEmpty(str)

我不希望像
“Value.IsProcess()

我的期望值是
String.IsProcess(value)

请帮助我。

你不能
您可以创建扩展方法。除此之外,无法向System.String添加其他静态成员。

请在没有扩展方法的情况下查看,这可能是不可能的。另外,
String
类是密封的,所以您不能扩展它。您不能向类添加任意静态方法。没有这种能力。您可以通过扩展方法向对象“添加”实例方法。。。但这完全是另一回事。c#不提供javascript原型之类的功能,而且字符串类是密封的,您不能从中创建包装器。如果它是您想要的静态方法,那么它在这个类或那个类中又有什么关系呢?C#不允许您将静态方法添加到另一个程序集(如System.String)中的类型。
public bool IsProcess(string str)
{
    bool flag = false;

    // LOGICS

    retrun flag;
}
public static bool IsProcess(this string str)
{
    bool flag = false;

    // LOGICS

    retrun flag;
}