❔ If statement isn't working as expected?
Basically, I'm writing an app with
WinForms
and I am implementing a version system that fetches the up to date version number from my GitHub and compares it to the local version file (_ver.apim
).
But for some reason, even when both values are the same, it shows the message even though the if statement is inverted by !=
. I'm new to C# and still getting the hang of it, but I just can't seem to figure it out.25 Replies
The most obvious reason is that both strings aren't the same
Maybe one has a trailing newline or something?
Prove to us that both are the same 🙂
Use the debugger to see what the strings actually are
Could be the
WebClient
is just returning null
on a bad request or something
Wouldn't surprise me, it had to be deprecated for a reason lolboth of them definitely have just one line
do you have any dlls / libraries to replace it?
HttpClient
And, sure, they have just one line... but are all the characters in that line the exact same?
cat
and cat
are not the same, neither are dog
and Dog
1000%
Aight, show the screenshot of the debugger that shows both variables
same, no spaces even matches in
sit
I don't see the debugger
idk how to use dbg
im beginner
No better time to learn than now, then
$debug
Tutorial: Debug C# code - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
thanks
i think ill just attempt to use restsharp and if i get the same problem then ill find another way
Looks to me like the first one has a newline after?
Try calling
.Trim()
on both stringsim dumb
thats it
😆
i tried a combo of setting output lines to
//
and one of them didnt return a newlinethe file doesnt have new line
ill just use trim
no more new lines, but my code still runs?
hmm
Not sure what you mean by that I'm afraid
Did you expect your code to refuse to run?
the statement should be false
because they are the same values
yet
MessageBox.Show("A new version of ProtoSploit is available!", "ProtoSploit Update");
still runsRead them into separate variables, then look at them in the debugger
k
when reading them into vars
net
and file
, how could file
be null even tho its printed to the console? Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.