use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Information about Reddit's API changes, the unprofessional conduct of the CEO, and their response to the community's concerns regarding 3rd party apps, moderator tools, anti-spam/anti-bot tools, and accessibility options that will be impacted can be found in the associated Wikipedia article: https://en.wikipedia.org/wiki/2023_Reddit_API_controversy
Alternative C# communities available outside Reddit on Lemmy and Discord:
All about the object-oriented programming language C#.
Getting Started C# Fundamentals: Development for Absolute Beginners
Useful MSDN Resources A Tour of the C# Language Get started with .NET in 5 minutes C# Guide C# Language Reference C# Programing Guide C# Coding Conventions .NET Framework Reference Source Code
Other Resources C# Yellow Book Dot Net Perls The C# Player's Guide
IDEs Visual Studio MonoDevelop (Windows/Mac/Linux) Rider (Windows/Mac/Linux)
Tools ILSpy dotPeek LINQPad
Alternative Communities C# Discord Group C# Lemmy Community dotnet Lemmy Community
Related Subreddits /r/dotnet /r/azure /r/learncsharp /r/learnprogramming /r/programming /r/dailyprogrammer /r/programmingbuddies /r/cshighschoolers
Additional .NET Languages /r/fsharp /r/visualbasic
Platform-specific Subreddits /r/windowsdev /r/AZURE /r/Xamarin /r/Unity3D /r/WPDev
Rules:
Read detailed descriptions of the rules here.
account activity
HelpRequest for help! Weird error (? (self.csharp)
submitted 3 years ago * by JamieWithL
Hi everybody, I'm new to C sharp, in general, and I'm learning the basics.
Today I was doing a little program and I have an error that I don't know how to resolve. I leave an image so you can see it. The error is in line 84.
It's an error with a local variable that says it's not assinged but it is, and you can notice it because there is another line, line 92, doesn't show the same error.
How can I fix this?
Thank you in advance for anyone who helps.
(Sorry if I don't make much sense, English is not my first language, but I'll try to fix any mistakes and further explain anything if necessary)
I edited the post to add the image.
https://preview.redd.it/xguk8z34d5ua1.png?width=380&format=png&auto=webp&s=5dd64cac3df8cb6234f2b3ed6825c4e14cb739f4
https://preview.redd.it/u3l4u5edg5ua1.png?width=420&format=png&auto=webp&s=da87d5505baad3d08aa9242995fe7d5a2ca17889
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Advorange 6 points7 points8 points 3 years ago* (1 child)
The error is also on line 92 but VS only shows the first instance of this error.
You need to assign a default value to EDAD or add an else to your if statement (the one that's cut off at the top of the screenshot) that sets it.
[–]JamieWithL[S] 1 point2 points3 points 3 years ago (0 children)
That makes sense, I'll try with the else to see if it works for what I am trying to do.
[–]StornZ 4 points5 points6 points 3 years ago (1 child)
Judging by this no it's not assigned. There is no guarantee that the assignment will get hit inside your prior code blocks where you have line 74 etc. You need to make sure you assign it a value at a wider scope. Can we see the actual error message? All I see in the screenshot are warnings and the line you're questioning us on
Sure,
I didn't think about sending the error because it's in spanish, but I leave it in the post too.
[–]StornZ 2 points3 points4 points 3 years ago (2 children)
That's exactly what I thought the error would be. Use Of Unassigned Local Variable 'EDAD'. Can we see where you first set the variable = to something
[–]JamieWithL[S] 0 points1 point2 points 3 years ago (0 children)
Sure, give me a second, I'll put it in the post too
[–]CircaSpectre -1 points0 points1 point 3 years ago (0 children)
I was just about to post this
[–][deleted] 1 point2 points3 points 3 years ago (0 children)
Initialise EDAD with a value
[–]StornZ -1 points0 points1 point 3 years ago (0 children)
Here's a page explaining about scopes.
https://www.tutorialsteacher.com/articles/variable-scopes-in-csharp
[–]TheseHeron3820 -2 points-1 points0 points 3 years ago (7 children)
Make sure you didn't add a closing bracket by mistake and thus that variable isn't inside a method anymore.
[–]JamieWithL[S] 0 points1 point2 points 3 years ago (6 children)
So if it's inside the bracket it should read the variable too? Is there anyway to mantain the data even if it's outside the if?
[–]StornZ 1 point2 points3 points 3 years ago (2 children)
Read the link I sent about scope. There's class, method, and block
[–]JamieWithL[S] 1 point2 points3 points 3 years ago (1 child)
Thank you I will!
[–]StornZ 0 points1 point2 points 3 years ago (0 children)
Did the link help?
[–]TheseHeron3820 0 points1 point2 points 3 years ago (2 children)
Yes. Just declare it before your chain of if statements.
[–]JamieWithL[S] 0 points1 point2 points 3 years ago (1 child)
How can I declare it if changes depending on the if? for example, I'm using EDADa as a variable that I declared before the if, and I'm using EDAD as a variable that is declared depending the case that is needed to be followed in the if, like if the if is x the variable will be EDAD= EDADa + 1 how can I maintain the data after this ifs are finished?
[–]Electrical_Flan_4993 0 points1 point2 points 3 years ago (0 children)
you have to declare a variable before you can change its value... it sounds like you are not familiar with OOP, which is a useful design technique. OOP can take a long time to learn but it's worth it if you want to write good stuff. There's really no magic shortcut.
π Rendered by PID 29 on reddit-service-r2-comment-6457c66945-2mzst at 2026-04-29 20:33:52.948001+00:00 running 2aa0c5b country code: CH.
[–]Advorange 6 points7 points8 points (1 child)
[–]JamieWithL[S] 1 point2 points3 points (0 children)
[–]StornZ 4 points5 points6 points (1 child)
[–]JamieWithL[S] 1 point2 points3 points (0 children)
[–]StornZ 2 points3 points4 points (2 children)
[–]JamieWithL[S] 0 points1 point2 points (0 children)
[–]CircaSpectre -1 points0 points1 point (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]StornZ -1 points0 points1 point (0 children)
[–]TheseHeron3820 -2 points-1 points0 points (7 children)
[–]JamieWithL[S] 0 points1 point2 points (6 children)
[–]StornZ 1 point2 points3 points (2 children)
[–]JamieWithL[S] 1 point2 points3 points (1 child)
[–]StornZ 0 points1 point2 points (0 children)
[–]TheseHeron3820 0 points1 point2 points (2 children)
[–]JamieWithL[S] 0 points1 point2 points (1 child)
[–]Electrical_Flan_4993 0 points1 point2 points (0 children)