Variable Validation

MMetalkon8/29/2022
What are the advantages/disadvantages between both of these bits of code to validate the correct input type? The top one is mine and the bottom is from a video I was just watching and i've been wondering if my method is just too sloppy/ugly/etc.
Image
KKiel8/29/2022
whileCondition is a bit redundant for what you are doing: you can use break; instead to break out of the while loop - this also means you don't need the else{} block and can just put the two lines inside it on their own, but it's still fine to keep since you are returning result in the end anyway, you can actually replace whileCondition = true with return result; directly :)

Console.ReadLine() can return a null string in certain cases, so the example code from the video which does the string.IsNullOrEmpty() check is valid (though most people I know prefer using string.IsNullOrWhiteSpace()). Never too early to get in the habit of checking things for null
PPobiega8/29/2022
Not to mention noise-to-signal ratio.
PPobiega8/29/2022
The second piece of code does the same thing, but is less "fluff" around the important bits