空出在C#中的参数?出在、参数

由网友(此用户已成仙)分享简介:阅读计算器的经过检查,你应该使用DateTime.TryParse日期时间的格式的情况下。在尝试一些正则表达式EX pressions他们似乎得到长期和讨厌的覆盖地段的格式。After reading on stackoverflow that in the case of checking the format o...

阅读计算器的经过检查,你应该使用DateTime.TryParse日期时间的格式的情况下。在尝试一些正则表达式EX pressions他们似乎得到长期和讨厌的覆盖地段的格式。

After reading on stackoverflow that in the case of checking the format of a DateTime you should use DateTime.TryParse. After trying some regex expressions they seem to get long and nasty looking to cover lots of the formatting.

不过的TryParse需要一个出参数,因为我只想做一个验证格式检查我不需要实际的结果。

But TryParse requires an "out" parameter and since I just want to do a validation format check I don't need the actual result.

所以我留下了持有出的结果,我什么都不做它一个变量。有没有一种方法,所以我没有做出来的参数?

So I am left with a variable that holds the "out" result and am to do nothing with it. Is there a way so I don't have to do a out parameter?

所以我摆脱这个警告,并停止具有可变只是飞来飞去。

So I get rid of this warning and stop having a variable just flying around.

推荐答案

都能跟得上。我把它包在一个方法的地方,以保持噪声在主流的:

Nope. I'd wrap it in a method somewhere to keep the noise out of the main flow:

  bool IsValidDate(string value)
  {
     DateTime result;
     return DateTime.TryParse(value, out result); //result is stored, but you only care about the return value of TryParse()
  }
阅读全文

相关推荐

最新文章