C# - 什么是断言()方法呢?它仍然有用吗? [英] C# - What does the Assert() method do? Is it still useful?

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

问题描述

我断点调试,我意识到断言电话吗?我认为这是唯一的单元测试。这是什么做的比断点吗?因为我可以断点,我为什么要使用断言?

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?

推荐答案

在调试汇编,断言接受一个布尔条件作为参数,并显示错误对话框,如果条件为假。如果条件为真,程序进入而没有任何中断。

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.

如果您在版本编译,所有Debug.Assert的公司将被自动排除在外。

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

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

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