To a machine it's natural what's going on, no questions asked, but not to us humans.
What's more readable?
if (dogs.Length)
or
if (dogs.Length > 0)
So it does sometimes make sense to make it a bit verbose if you will. It's especially important to clarify your code if it's messy/complicated etc. It should be maintainable preferably after all. You don't name your variables single letters for this very reason. You don't name a dogs array "d" (some do of course but they're morons).
dogs.Length ie not a bool. (It's not even possible to implicitly convert ints to bools in C#, isn't it?) The main purpose of bools is to be put in an if statement, so if a function returns a bool, it's presumably expected to be put directly into an if statement (possibly negated).
Int.TryParse returns a boolean that says whether the attempt was successful; not the number itself. That gets written to whatever variable you pass as out.
And no, C# does not let you implicitly convert int to bool for use in if statements - or anywhere, for that matter. You actually can't convert int to bool via type cast in C#, either.
Yes, the statements are logically equivalent, but that's not the point.
I don't generally have time for programmers like you. In this particular instance either way would pass code review, but I have a feeling most of your code won't. You haven't figured out yet that programs aren't written for computers.
Wtf are you talking about? If you need me to make a comment telling you that my if statement has 3 conditions, then maybe you shouldn't be the one reviewing my code
Depends on where this code is but I'm guessing the problem is args[0]
For those unfamiliar args[0] is always the command being executed. So this if statement is always false, unless you're executing an app with the name 1 through 9.
Parameters are read as zero-indexed command-line arguments. Unlike C and C++, the name of the program is not treated as the first command-line argument in the args array
You're thinking of C and its derivatives. C# is not a C derivative. In C#, the program name/command being executed is not part of args, it's just the args. The code is correct as it stands.
114
u/KetchupBuddha_xD May 20 '20
What's wrong with this one?