警告如何影响c#中的代码 [英] how does the warning effects the code in c#

查看:93
本文介绍了警告如何影响c#中的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个网络应用程序,当我构建它时,我发现很多警告说很多变量已声明但从未使用过。其中一些是catch块等中的异常对象。之前已声明了其他对象,但现在需求发生了变化。还有许多其他警告,如类型转换等...现在我想知道这种代码是否会影响项目的性能。如果是的话怎么样?



i知道这是一种糟糕的编程,但这是现有的项目,有很多页面我有这个问题所以不想去每个页面并删除该代码等...

Hi,
i have one web application when i build it i found lot of warning which says that lot of variables are declared but never used. some of them are exception objects in catch blocks etc..others are declared previously but now the requirement changes. there are many other warning like type casting etc... now i would like to know does this kind of code affect the performance of the project. if yes how ?

i know this is kind of bad programming but this is existing project and there are a lot of pages where i have this problem so not want to go to every page and remove that code and etc...

推荐答案

Quote:

编译器警告可以为您的代码库提供一些额外的洞察力和质量控制。他们可以告诉您过时的代码,未使用的变量以及您在视觉检查中不一定会看到的许多其他项目。警告也可以表示错误,例如可能的空引用异常,或总是评估为true的表达式。

Compiler warnings can provide some additional insight and quality controls on your codebase. They can tell you about obsolete code, unused variables, and many other items that you wouldn’t necessarily see on visual inspection. Warnings can also surface bugs, such as possible null reference exceptions, or expressions that always evaluate to "true".





引用 [ ^ ]



警告会影响性能项目以更大的方式进行。诸如声明变量和从不使用变量之类的警告意味着内存消耗会因内存分配给不需要/未使用的变量而上升。



在代码中有效使用异常处理的情况也是如此。



并且,最好避免这些是将编译器警告视为错误。



参考

将警告视为错误 [< a href =http://visualstudiotips.wordpress.com/2006/04/16/tip-treat-warnings-as-errors/target =_ blanktitle =New Window> ^ ]


未使用的变量不会对代码稳定性或性能产生任何影响。声明变量而不使用变量只是一种糟糕的编程习惯。



相反,catch块中未使用的异常变量意味着您没有记录异常。它甚至可能是一个空的catch块,这意味着如果在运行时抛出异常,那么你应用程序会吞下异常,但对它没有任何作用。它可能会导致应用程序中的数据状态不稳定。



每个警告都有不同的含义,必须进行调查和修复。
Unused variables will not have any effect on your code stability or performance. It's just a bad programming practice to declare variables and not use them.

On the contrary, unused Exception variables in the catch block means you're not logging the exceptions. It could even be an empty catch block which means that if an exception is thrown at runtime, you app swallows the exception but does nothing about it. It might lead to an unstable data state in your app.

Each warning has a different meaning that must be investigated and fixed.


这篇关于警告如何影响c#中的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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