<bdo id='bhxHw'></bdo><ul id='bhxHw'></ul>
  • <legend id='bhxHw'><style id='bhxHw'><dir id='bhxHw'><q id='bhxHw'></q></dir></style></legend>

      <small id='bhxHw'></small><noframes id='bhxHw'>

    1. <i id='bhxHw'><tr id='bhxHw'><dt id='bhxHw'><q id='bhxHw'><span id='bhxHw'><b id='bhxHw'><form id='bhxHw'><ins id='bhxHw'></ins><ul id='bhxHw'></ul><sub id='bhxHw'></sub></form><legend id='bhxHw'></legend><bdo id='bhxHw'><pre id='bhxHw'><center id='bhxHw'></center></pre></bdo></b><th id='bhxHw'></th></span></q></dt></tr></i><div id='bhxHw'><tfoot id='bhxHw'></tfoot><dl id='bhxHw'><fieldset id='bhxHw'></fieldset></dl></div>
      1. <tfoot id='bhxHw'></tfoot>
      2. Parse 诉 TryParse

        Parse v. TryParse(Parse 诉 TryParse)
          <tbody id='DDuN3'></tbody>
      3. <i id='DDuN3'><tr id='DDuN3'><dt id='DDuN3'><q id='DDuN3'><span id='DDuN3'><b id='DDuN3'><form id='DDuN3'><ins id='DDuN3'></ins><ul id='DDuN3'></ul><sub id='DDuN3'></sub></form><legend id='DDuN3'></legend><bdo id='DDuN3'><pre id='DDuN3'><center id='DDuN3'></center></pre></bdo></b><th id='DDuN3'></th></span></q></dt></tr></i><div id='DDuN3'><tfoot id='DDuN3'></tfoot><dl id='DDuN3'><fieldset id='DDuN3'></fieldset></dl></div>

        1. <legend id='DDuN3'><style id='DDuN3'><dir id='DDuN3'><q id='DDuN3'></q></dir></style></legend>

          • <tfoot id='DDuN3'></tfoot>
              • <small id='DDuN3'></small><noframes id='DDuN3'>

                  <bdo id='DDuN3'></bdo><ul id='DDuN3'></ul>
                • 本文介绍了Parse 诉 TryParse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Parse() 和 TryParse() 有什么区别?

                  What is the difference between Parse() and TryParse()?

                  int number = int.Parse(textBoxNumber.Text);
                  
                  // The Try-Parse Method
                  int.TryParse(textBoxNumber.Text, out number);
                  

                  是否有某种形式的错误检查,例如 Try-Catch 块?

                  Is there some form of error-checking like a Try-Catch Block?

                  推荐答案

                  Parse 如果无法解析值会抛出异常,而 TryParse 返回 bool表示是否成功.

                  Parse throws an exception if it cannot parse the value, whereas TryParse returns a bool indicating whether it succeeded.

                  TryParse 不只是 try/catch 在内部 - 它的全部意义在于它是在没有异常的情况下实现的,因此速度很快.事实上,它最有可能实现的方式是,Parse 方法内部会调用 TryParse,然后如果返回 false 则抛出异常.

                  TryParse does not just try/catch internally - the whole point of it is that it is implemented without exceptions so that it is fast. In fact the way it is most likely implemented is that internally the Parse method will call TryParse and then throw an exception if it returns false.

                  简而言之,如果您确定该值有效,请使用 Parse;否则使用 TryParse.

                  In a nutshell, use Parse if you are sure the value will be valid; otherwise use TryParse.

                  这篇关于Parse 诉 TryParse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                  Accessing attribute info from DTE(从 DTE 访问属性信息)
                  c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                  Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                  C# Attributes and their uses(C# 属性及其用途)
                  C# - Getting all enums value by attribute(C# - 按属性获取所有枚举值)
                  <tfoot id='rMkgE'></tfoot>
                    <tbody id='rMkgE'></tbody>

                        <bdo id='rMkgE'></bdo><ul id='rMkgE'></ul>

                        <small id='rMkgE'></small><noframes id='rMkgE'>

                        <legend id='rMkgE'><style id='rMkgE'><dir id='rMkgE'><q id='rMkgE'></q></dir></style></legend>

                          • <i id='rMkgE'><tr id='rMkgE'><dt id='rMkgE'><q id='rMkgE'><span id='rMkgE'><b id='rMkgE'><form id='rMkgE'><ins id='rMkgE'></ins><ul id='rMkgE'></ul><sub id='rMkgE'></sub></form><legend id='rMkgE'></legend><bdo id='rMkgE'><pre id='rMkgE'><center id='rMkgE'></center></pre></bdo></b><th id='rMkgE'></th></span></q></dt></tr></i><div id='rMkgE'><tfoot id='rMkgE'></tfoot><dl id='rMkgE'><fieldset id='rMkgE'></fieldset></dl></div>