Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

don't know how to solve this

coding in c#. i tried to code some myself, but got a error and don't know how to solve it. i thought i assigned it in the while loop, but it just doesn't work


Best Answer

  • JellyCOREJellyCORE Member
    Accepted Answer

    Heya! ^^

    I looked up what you have there and, at first, found something a bit more complex,

    but then I came across this here, which I think explains it in a way that's easier to understand (To me, anyhow! I'll post the link to the more complex thing at the bottom): https://www.dummies.com/programming/java/local-variables-in-java/

    Don't mind the website name XD They're actually really helpful in lots of areas, not just coding!

    But anyhow, since "userName" seems to be a local variable, there are two things I've found that might be causing this!

    • Have you initialised "userName" inside the same method you're using it in? Local variables (As far as I now know) can only be used inside the same method they were created in!
    • Have you assigned "userName" a value? As far as I know, local variables need to be assigned a value before you can use them! Since "userName" is a "String" variable, meaning one with text, this here would be an example of initialising it with an assigned value:

    String userName = "example";

    Or this here!

    String userName;

    userName = "example";



    I hope this helps and isn't too confusing ^^' Please let me know if it helps!

    And the link to the other website I found: https://stackoverflow.com/questions/9233000/why-compile-error-use-of-unassigned-local-variable

    Best of luck to you~!

Answers

Sign In or Register to comment.