|
Good thing the battery can't give 110% like some developers do.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I wonder what he would have done if they suddenly wanted to display the battery life at 0.1% accuracy...
.
|
|
|
|
|
An idiot did not write this, for I'm sure they used copy/paste to comprise most of it with assistance from type-ahead.
Besides, being the float that it is, he merely wanted to float himself more hours to enable himself to float (er, buy a boat) on the lake.
Thus, he used the float associatively correct.
|
|
|
|
|
A padded number in a file name!
int fileCount = Directory.GetFiles("[censored]", "*.csv", SearchOption.AllDirectories).Length + 1;
string fileCountStr = (fileCount <= 999 ? fileCount <= 99 ? fileCount <= 9 ? "000" : "00" : "0" : "") + fileCount;
I think this should win an award for readability in a triply-nested ternary condition .
|
|
|
|
|
And what about when someone deletes 085.csv ?
speramus in juniperus
|
|
|
|
|
Oh, don't worry. None of the accounts have delete permissions. 
|
|
|
|
|
It's so good to know that the hard work of the developers of String.PadLeft[^] and Int32.ToString[^] is providing so much joy to so many, other than you.
By the way, what language is that? It can't be C#, or did you also override the + operator? 
|
|
|
|
|
PIEBALDconsult wrote: It can't be C#
Really?
When one or both operands are of type string, + concatenates the string representations of the operands.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: When one or both operands are of type string
Yes, and are they?
|
|
|
|
|
PIEBALDconsult wrote: Yes, and are they?
Yes, the first operand is a string. It's the result of the ternary operator:
fileCount <= 999
? fileCount <= 99
? fileCount <= 9
? "000"
: "00"
: "0"
: ""
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
PIEBALDconsult wrote: And the second?
Doesn't matter. The documentation clearly states, "When one or both operands are of type string...", so the type of the other operand is irrelevant.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I missed that the first time also.
BDF
The internet makes dumb people dumber and clever people cleverer.
-- PaulowniaK
|
|
|
|
|
|
|
PIEBALDconsult wrote: I'm fairly sure that no self-respecting C# professional uses it that way. Heh, I go for the shorter version. If it doesn't make sense with a mishmash of ints/strings I use brackets or ToString() to clarify.
int i = 124, j = 253;
string s = "JD" + i + j;
string t = "JD" + (i + j);
But yeah, usually I don't bother.
Although, theoretically, I could now do
string s = 0;
string t = "" + 0;
So, let's get back to self-respecting... 
|
|
|
|
|
string t = System.String.Format ( "JD{0}" , i + j ) ;
|
|
|
|
|
Make that:
string t = string.Format(CultureInfo.InvariantCulture, "JD{0:D}", i + j);
You typically don't want culture-specific formatting or group separators in the result.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I've never had that problem.
|
|
|
|
|
And of course don't forget to set the string to "" at the end, else if the garbage collector is a little slow you might run out of memory!
Better yet, just keep re-using global strings.
|
|
|
|
|
I think I wrote it in one of those points in the week where I just couldn't think. Methinks I'll replace it tomorrow.
|
|
|
|
|
Wonderful code!
When I was new to programming I used to do something like this too.
Then I figured out a trick: just add 1.000.000.000 to the number and take the last 4 characters.
Now I just use PadLeft, PadRight or Format
|
|
|
|
|
Just found this gem in the .NET BCL documentation on Process.WaitForExit(Int32):
In the .NET Framework version 3.5 and earlier versions, if milliseconds was -1, the WaitForExit(Int32) overload waited for MaxValue milliseconds (approximately 24 days), not indefinitely.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
I think you will find that 24 days is the maximum number of milliseconds a int32 wil hold.
How do I know this?
Well I wrote a millisecond counter with an int32 and wondered why every 20 or so days the program which was running on someone else's machine crashed.
I never hit the error as I switched my machine off every night and was only away on holiday for less than 20 days when the software was running without a nightly shutdown.
[edit - I missed the first line...]
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
|
|
|
|
|
The difference between eternity and 24 days matters actually. Windows 9x did crash after 49.7 days. They used unsigned int back then...
“Today is the first day of the rest of your life.”
|
|
|
|