【发布时间】:2013-05-03 17:13:13
【问题描述】:
在 C# 中有很多方法可以访问 Match 的值:
Match mtch = //whatever
//you could do
mtch.Value
//or
mtch.ToString()
//or
mtch.Groups[0].Value
//or
mtch.Groups[0].ToString()
我的问题是:访问它的最佳方式是什么?
(我知道这是微优化,我只是想知道)
【问题讨论】:
-
嗯,这似乎很容易让您使用您真正感兴趣的正则表达式中的适当样本数据来测试自己。这些测试进展如何?
-
测试如下:
Match.ToString(): 13823982 Match.Value: 11846245 Match.Groups[0].Value: 22549607 Match.Groups[0].ToString(): 22549607(滴答声)。为什么我很感兴趣的是为什么 Value 和 ToString 完全相同,因为这一定意味着它们中必须有完全相同的代码。