If KeyboardInput[0] is a char type then you can do something like this KeyboardInput[0] - '0'. Assuming of course that you are certain that this char will only ever be in the range of 0-9.
A unichar, in my mind, is 32bits to handle literally any UTF32 character. This is the weird Microsoft 16bit kinda handles most characters but actually doesn't encoding.
Actually it was back before UTF-8 existed. When they went with UCS-2 then did an in-place extension to UTF-16 when the number of codepoints they needed to cover expanded. So Microsoft has a whole OS and application marketplace full of wide-char applications, not really a lot you can do at that point except slowly introduce ways to natively handle UTF-8.
That’s because Microsoft decided UTF-16 was the character encoding to use. Almost every other thing ever will use UTF-8 and correspondingly have char be 8 bits
(I don't know C# well) I would probably make 2 temporary variables for the pair or array, whatever the [] is, instead of frankensteining it in one less readable call.
32
u/dumbasPL Feb 17 '23
Int parse from toString? What type is keyboard input?
2
u/Bisquizzle Feb 17 '23
and if it's not parsable to int?
2
u/DajBuzi Feb 17 '23
Your "fix" is now more error prone. Imagine the input will be
99and then compare output of the two solutions posted.101
u/ventus1b Feb 17 '23
I guess most developers have woken up to a mess of code they wrote last night.
Sometimes you don’t know where to go until you get there.
At least your old code is correct, just a bit verbose 🤓
139
u/miran248 Feb 17 '23
Use some variables, please.
19
u/NetherFX Feb 17 '23
I'm not saying the first is good code, but there's nothing wrong with prototyping first to understand the logic behind it
32
u/[deleted] Feb 17 '23 edited Feb 17 '23
From
Int.Parseto.toString... DudeEdit: formatting
10
u/Cybasura Feb 17 '23
I think you were tired lol
With that said, dont use magic numbers, use variables
Variables dont eat up that much memory, especially since you are using C# and it has automated garbage collection
8
u/augenvogel Feb 17 '23
Both of them are cursed in it’s own way.
5
u/PooSham Feb 17 '23
Something tells me GetInt does not just get the int
3
u/Escaped_Escapement Feb 17 '23
Ever heard of clean code? :)
3
u/maltazar1 Feb 17 '23
Yandere dev quality code
3
u/iEliteTester Feb 17 '23 edited Feb 22 '23
Ah yes the classic:
3
u/Darknety Feb 17 '23
No offense, but both are cursed.
2
u/jrb9249 Feb 18 '23
“Are you sure you don’t want to use this one-liner?”
-Resharper, following morning.
1
u/FishInferno Feb 17 '23
It’s usually easier to improve upon a poor solution than get it perfect the first time.
1
u/Sanduhr32 Feb 18 '23
(I don't know C# well)
I would probably make 2 temporary variables for the pair or array, whatever the [] is, instead of frankensteining it in one less readable call.
1
u/okay-wait-wut Feb 18 '23
Indexing considered harmful. Switch statements preferred.
1
u/[deleted] Feb 19 '23
hell no