ईवेंट्स
17 मार्च, 9 pm - 21 मार्च, 10 am
साथी डेवलपर्स और विशेषज्ञों के साथ वास्तविक दुनिया के उपयोग के मामलों के आधार पर स्केलेबल एआई समाधान बनाने के लिए मीटअप श्रृंखला में शामिल हों।
अभी पंजीकरण करेंयह ब्राउज़र अब समर्थित नहीं है.
नवीनतम सुविधाओं, सुरक्षा अपडेट और तकनीकी सहायता का लाभ लेने के लिए Microsoft Edge में अपग्रेड करें.
Property | Value |
---|---|
Rule ID | IDE0058 |
Title | Remove unnecessary expression value |
Category | Style |
Subcategory | Language rules (expression-level preferences) |
Applicable languages | C# and Visual Basic |
Options | csharp_style_unused_value_expression_statement_preference |
visual_basic_style_unused_value_expression_statement_preference |
This rule flags unused expression values. For example:
void M()
{
Compute(); // IDE0058: computed value is never used.
}
int Compute();
You can take one of the following actions to fix this violation:
If the expression has no side effects, remove the entire statement. This improves performance by avoiding unnecessary computation.
If the expression has side effects, replace the left side of the assignment with a discard (C# only) or a local variable that's never used. This improves code clarity by explicitly showing the intent to discard an unused value.
_ = Compute();
The options for this specify whether to prefer the use of a discard or an unused local variable:
For information about configuring options, see Option format.
Property | Value | Description |
---|---|---|
Option name | csharp_style_unused_value_expression_statement_preference | |
Applicable languages | C# | |
Option values | discard_variable |
Prefer to assign an unused expression to a discard |
unused_local_variable |
Prefer to assign an unused expression to a local variable that's never used | |
Default option value | discard_variable |
// Original code:
System.Convert.ToInt32("35");
// After code fix for IDE0058:
// csharp_style_unused_value_expression_statement_preference = discard_variable
_ = System.Convert.ToInt32("35");
// csharp_style_unused_value_expression_statement_preference = unused_local_variable
var unused = Convert.ToInt32("35");
Property | Value | Description |
---|---|---|
Option name | visual_basic_style_unused_value_expression_statement_preference | |
Applicable languages | Visual Basic | |
Option values | unused_local_variable |
Prefer to assign an unused expression to a local variable that's never used |
Default option value | unused_local_variable |
' visual_basic_style_unused_value_expression_statement_preference = unused_local_variable
Dim unused = Computation()
If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable IDE0058
// The code that's violating the rule is on this line.
#pragma warning restore IDE0058
To disable the rule for a file, folder, or project, set its severity to none
in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.IDE0058.severity = none
To disable all of the code-style rules, set the severity for the category Style
to none
in the configuration file.
[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Style.severity = none
For more information, see How to suppress code analysis warnings.
.NET प्रतिक्रिया
.NET एक ओपन सोर्स प्रोजेक्ट है. प्रतिक्रिया प्रदान करने के लिए लिंक का चयन करें:
ईवेंट्स
17 मार्च, 9 pm - 21 मार्च, 10 am
साथी डेवलपर्स और विशेषज्ञों के साथ वास्तविक दुनिया के उपयोग के मामलों के आधार पर स्केलेबल एआई समाधान बनाने के लिए मीटअप श्रृंखला में शामिल हों।
अभी पंजीकरण करें