5

Warning 1 The field 'MCS_SPS_School.Fees.DiscountAmt.rtvalue' is assigned but its value is never used G:\Jagadeeswaran\Nov 17\MCS-SPS School\MCS-SPS School\Fees\DiscountAmt.cs

Warning 2 The field 'MCS_SPS_School.Fees.DiscountAmt.dt' is never used G:\Jagadeeswaran\Nov 17\MCS-SPS School\MCS-SPS School\Fees\DiscountAmt.cs

This type of warning is still in my project. But the project runs safely.

Now what I do for this warnings, to fix or Ignore?

Is any dangerous if ignore that, performance wise or other?

13

It's not directly a safety problem, but it might be an indirect one. That's why it's a warning. The compiler is telling you that you've declared something but you aren't actually doing anything with it, which most likely means that your code is incomplete: you started building something and didn't finish it. This could cause bugs further down the line.

The best way to fix this warning is to either finish writing whatever was supposed to use this value, or delete it.

  • Note that this is not always possible. I sometimes have fields that are used by AOP and other external processes that the IDE doesn't know about. In those cases I usually use the IDE's //unused facility with a quick comment about what actually references the variable. – TMN Apr 25 '16 at 12:11
9

Always fix warnings and hints. They point to issues that can pose problems later on.

Even if this warning seems unimportant, when you start ignoring "unimportant" hints and warnings, you will soon be drowned in them and then you won't spot the ones that are in fact very important and do cause bugs if unaddressed.

Any development team serious about code quality will have a zero hints and warnings policy in place. Our build server will continue a build when some projects produce hints and warnings, but our QA department will be all over us if we allow these to propagate from "work" branches into the main development branch. And issues in work branches won't be "resolved" (accepted for integration into the main development branch) by them until all hints and warnings are gone and all unit tests succeed.

4

The warning means exactly that - you have declared fields in your classes that you never use.

Warning 1 means that your DiscountAmt.cs file has fields named rtvalue and dt that are declared but not referenced anywhere.

These fields take some space for each instance of the class, even though they are never used - best practice is to delete such fields.


There is another issue to do with warnings - if you don't fix these, you end up with many warnings. Some of these warnings are important, but you will never notice them because you have many other warnings that these get lost in the noise. A good practice is to have 0 warnings and 0 errors.

  • A good practice is to have 0 warnings and 0 errors. -- Very Very Thanks – Sagotharan Dec 26 '11 at 14:39
  • But not everything that is causing warning is bad. But then its good practice to explicitely supress this occurance of warning (and explain why in comment) – user470365 Dec 26 '11 at 18:28
  • @user470365 - true. But you did ask about this specific warning, not all warnings. – Oded Dec 26 '11 at 18:48
1

if you are delaying the fix for this item until later stage of the project you can turn of the warning message by using the #pragma warning disable see link: Pragma warning

otherwise remove the item if you are not using it until it is needed :)

  • now only i know pragma warning is there in .net. Thanks – Sagotharan Dec 26 '11 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.