我有一個名爲isStringOnlyWhitespace()方法:是否有任何理由使用這個Regex方法而不是String.IsNullOrEmpty()?
public static bool isStringOnlyWhitespace(string toEval)
{
string stringNoWhitespace = Regex.Replace(toEval, @"\s", "");
if (stringNoWhitespace.Length > 0) return false;
else return true;
}
是否有任何理由使用這種方法比String.IsNullOrEmpty檢查空/空字符串()?
'string.IsNullOrWhitespace'與.NET介紹4.0,所以舊版本只能使用'string.IsNullOrEmpty'。 – Oded 2010-08-24 16:33:08
謝謝Oded,我忘了它是新的。我編輯了我的答案以反映這一點。 – 2010-08-24 16:34:22
+1,輕微抱怨。我寧願只是手動編寫IsNullOrWhitespace而不是分配代碼。該方法相當直接地進行編碼。 – JaredPar 2010-08-24 16:38:52