How to fix the errors

BenTam-3003 686 Reputation points
2022-04-04T14:02:47.247+00:00

Dear All,

How to fix the errors? The errors are:

CS0165	Use of unassigned local variable 'x'  
CS0165	Use of unassigned local variable 'y'  

189791-error.gif

Developer technologies C#
0 comments No comments
{count} votes

Accepted answer
  1. P a u l 10,761 Reputation points
    2022-04-04T14:04:51.403+00:00

    The error's saying you're trying to use a variable that hasn't had a value assigned.

    int startAt = 0, i, x = 0, y = 0;
    

    It's generally better for readability to break these sorts of variables out to separate lines though, although that's just my preference.

    var startAt = 0;
    var x = 0;
    var y = 0;
    
    int i;
    

    The first three can use var because 0 can be inferred to be a 32-bit integer. The type for i can't be inferred because it's set below.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.