我有以下代码:
Match matcher = new Regex("[0-9]+.[0-9]+.[0-9]+").Match("12/02/1994");
if (matcher.Success)
{
string matchedString1 = matcher.Value;
string matchedString2 = matcher.ToString();
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下matchedString1,matchedString2包含相同的值"12/02/1994".是matcher.Value和matcher.ToString()总是返回相同的结果对于任何正则表达式?
Match类派生自Group类,这个派生自Capture类.
Capture类使用以下代码覆盖ToString()方法:
[__DynamicallyInvokable, TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public override string ToString()
{
return this.Value;
}
Run Code Online (Sandbox Code Playgroud)
所以,是的,它是相同的价值.
| 归档时间: |
|
| 查看次数: |
3051 次 |
| 最近记录: |