English 中文(简体)
Try-Catch or Check Length?
原标题:Try-Catch or Check Length?
  • 时间:2010-03-18 14:20:34
  •  标签:
  • c#
  • try-catch

我只是想到的是,哪一个成本会更低,使用一个试捕集区,将指数从约束区中排出,或检查多面阵列的长度和比较价值?

我感觉到,时间长,因为我可以把时间长短储存在一个变数中,然后,如果价格相对较低的话,就这样做了。 我不敢肯定的是,审判渔获量是多么昂贵。

感谢!

最佳回答

缩短时间比达到例外情况便宜得多。 当你有尝试时,它会把额外结构列入你关于追捕例外的法典——这是罚款,我不说是错的,但如果你可以检查约束的长短,那么就这样做了。

问题回答

与检查愤怒的价值相比,增加一个例外非常昂贵。 然而,这无关紧要。 更重要的是,即使例外是廉价的,它们仍然是错误的选择。 例外情况是,它代表了例外情况发生:<>。 理想的例外只能用来代表意外、少见、最好致命的东西。

另一种研究方式:如果你重新进入其约束区外的阵列,你有bug<>。 .。 一位例外的手稿hides the bug, it don t fix the bug

举一个例外是昂贵的作业(因为你必须产生ack痕)。 检查时间。

如果你们想想一下,对你们的处境来说,什么是更有效率的,我就说“措施”。

例如: 哪些非约束性条件极为罕见? 因此,不受约束者永远不会抛弃...... 在这种情况下,所有额外的“男性”约束检查都会放缓。

CVEATS:审判/渔获量需要围绕许多包裹,因此,审判的建立不太重要。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...