使用扩展方法替换字符串

use*_*193 4 .net c#

如果我有字符串,我想用星号替换该字符串中的最后一个字符.

我试过这个

var myString = "ABCDEFGH";
myString.ReplaceCharacter(mystring.Length - 1, 1, "*"); 

public static string ReplaceCharacter(this string str, int start, int length, string replaceWith_expression)
{
    return str.Remove(start, length).Insert(start, replaceWith_expression);
}
Run Code Online (Sandbox Code Playgroud)

我试图使用此扩展方法,但这不起作用.为什么这不起作用?

adr*_*dar 8

实际上,该方法会替换该字符,但您必须捕获结果

myString = myString.ReplaceCharacter(myString.Length - 1, 1, "*"); 
Run Code Online (Sandbox Code Playgroud)