Just another one CS0165: Use of unassigned variable #7291
-
Was not able to find exactly the same one. Consider the following method:
While due to the same check |
Beta Was this translation helpful? Give feedback.
Answered by
RikkiGibson
Jun 20, 2023
Replies: 1 comment 5 replies
-
if In the past there were already some improvements of the Definite Assignment Analysis. But I think it is not only hard for the compiler to see this - for humans it is hard, too. I would refactor the code to: using System;
public class C {
public void M() {
if (!SomePredicate())
{
if (!OutFunction(out int value))
{
return;
}
int result = -1; //other code here...
if (SomeCondition(result, value)) // CS0165: Use of unassigned variable 'value'.
{
}
}
bool SomePredicate() => false;
bool OutFunction(out int i) => throw new Exception();
bool SomeCondition(int i, int j) => false;
}
} |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dotnet/roslyn#36927 (comment)