C# - Assert() 方法有什么作用?它还有用吗? [英] C# - What does the Assert() method do? Is it still useful?

查看:23
本文介绍了C# - Assert() 方法有什么作用?它还有用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用断点进行调试并且我实现了断言调用?我以为它只用于单元测试.除了断点,它还能做什么?既然可以断点,那为什么要用Assert呢?

I am debugging with breakpoints and I realize the assert call? I thought it was only for unit tests. What does it do more than breakpoint? Since I can breakpoint, why should I use Assert?

推荐答案

在调试编译中,Assert 接受一个布尔条件作为参数,如果条件为假则显示错误对话框.如果条件为真,则程序继续进行而不会中断.

In a debug compilation, Assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.

如果在Release中编译,所有Debug.Assert 会自动排除.

If you compile in Release, all Debug.Assert's are automatically left out.

这篇关于C# - Assert() 方法有什么作用?它还有用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆