This rule flags unnecessary value assignments. For example:
C#
// IDE0059: value written to 'v' is never// read, so assignment to 'v' is unnecessary.int v = Compute();
v = Compute2();
You can take one of the following actions to fix this violation:
If the expression on the right side of the assignment has no side effects, remove the expression or the entire assignment statement. This improves performance by avoiding unnecessary computation.
C#
int v = Compute2();
If the expression on the right side of the assignment has side effects, replace the left side of the assignment with a discard (C# only) or a local variable that's never used. Discards improve code clarity by explicitly showing the intent to discard an unused value.
C#
_ = Compute();
int v = Compute2();
Options
The options for this specify whether to prefer the use of a discard or an unused local variable:
Šī satura avotu var atrast vietnē GitHub, kur varat arī izveidot un pārskatīt problēmas un atgādāšanas pieprasījumus. Lai iegūtu papildinformāciju, skatiet mūsu līdzstrādnieku rokasgrāmatu.
.NET atsauksmes
.NET ir atklātā pirmkoda projekts. Atlasiet saiti, lai sniegtu atsauksmes:
Pievienojieties meetup sērijai, lai kopā ar citiem izstrādātājiem un ekspertiem izveidotu mērogojamus AI risinājumus, kuru pamatā ir reālas lietošanas gadījumi.