Click here to Skip to main content
15,566,160 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: C# 6, you dirty dog! Pin
PIEBALDconsult1-Sep-22 8:00
professionalPIEBALDconsult1-Sep-22 8:00 
GeneralTwo of my most frequent issues with .net inconsistencies PinPopular
PIEBALDconsult24-Aug-22 11:28
professionalPIEBALDconsult24-Aug-22 11:28 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
MarkTJohnson24-Aug-22 11:31
professionalMarkTJohnson24-Aug-22 11:31 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
Greg Utas24-Aug-22 12:29
mveGreg Utas24-Aug-22 12:29 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
PIEBALDconsult24-Aug-22 12:37
professionalPIEBALDconsult24-Aug-22 12:37 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
Greg Utas24-Aug-22 14:35
mveGreg Utas24-Aug-22 14:35 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
englebart1-Sep-22 7:59
professionalenglebart1-Sep-22 7:59 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
Richard Deeming24-Aug-22 23:06
mveRichard Deeming24-Aug-22 23:06 
The DateTime vs TimeSpan is more insidious than you think. DateTime.UtcNow.TimeOfDay.ToString("hh\\:mm\\:ss") will always use ":" as the separator, whereas DateTime.UtcNow.ToString("hh:mm:ss") will use the current culture's time separator. Whilst the default seems to use ":" consistently, I believe the user can override this in the OS settings.
C#
var format = new DateTimeFormatInfo { TimeSeparator = "#" };
DateTime.UtcNow.ToString("hh:mm:ss", format); // 07#56#00
DateTime.UtcNow.TimeOfDay.ToString("hh\\:mm\\:ss", format); // 07:56:00

The argument exception one is annoying, but I can sort-of understand how it came to be. With an ArgumentNullException, there's an obvious default error message, and the main thing you care about is the name of the argument which was null. But with an ArgumentException, there's no obvious default error message, and the error could be caused by a combination of parameters, so the message is the main thing, and the parameter name is optional.

Since C# 4 introduced named parameters, you can use them to make the invocations consistent:
C#
new ArgumentException(paramName: nameof(foo), message: "Bar");
new ArgumentNullException(paramName: nameof(foo), message: "Bar");

NB: Starting with .NET 6, the recommendation is to use ArgumentNullException.ThrowIfNull(parameter); instead of if (parameter is null) throw new ArgumentNullException(nameof(parameter));:

ArgumentNullException.ThrowIfNull Method (System) | Microsoft Docs[^]
Introduce static methods to allocate and throw key exception types. · Issue #48573 · dotnet/runtime · GitHub[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
PIEBALDconsult25-Aug-22 4:21
professionalPIEBALDconsult25-Aug-22 4:21 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
Richard Deeming25-Aug-22 6:05
mveRichard Deeming25-Aug-22 6:05 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
PIEBALDconsult25-Aug-22 8:40
professionalPIEBALDconsult25-Aug-22 8:40 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
Bernhard Hiller25-Aug-22 22:09
Bernhard Hiller25-Aug-22 22:09 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
PIEBALDconsult27-Aug-22 7:19
professionalPIEBALDconsult27-Aug-22 7:19 
GeneralRe: Two of my most frequent issues with .net inconsistencies Pin
Eddy Vluggen1-Sep-22 4:44
professionalEddy Vluggen1-Sep-22 4:44 
GeneralTECO Macros - show me the codez Pin
MrChug10-Aug-22 18:39
MrChug10-Aug-22 18:39 
GeneralRe: TECO Macros - show me the codez Pin
PIEBALDconsult10-Aug-22 18:44
professionalPIEBALDconsult10-Aug-22 18:44 
GeneralRe: TECO Macros - show me the codez Pin
englebart1-Sep-22 8:06
professionalenglebart1-Sep-22 8:06 
GeneralRe: TECO Macros - show me the codez Pin
PIEBALDconsult1-Sep-22 8:28
professionalPIEBALDconsult1-Sep-22 8:28 
GeneralWeird: Very confusing Base64 problem (includes quiz) Pin
raddevus21-Jul-22 12:12
mvaraddevus21-Jul-22 12:12 
GeneralRe: Weird: Very confusing Base64 problem (includes quiz) Pin
Randor 21-Jul-22 22:40
professional Randor 21-Jul-22 22:40 
GeneralRe: Weird: Very confusing Base64 problem (includes quiz) Pin
raddevus22-Jul-22 3:50
mvaraddevus22-Jul-22 3:50 
GeneralRe: Weird: Very confusing Base64 problem (includes quiz) Pin
Marc Clifton4-Aug-22 5:24
mvaMarc Clifton4-Aug-22 5:24 
GeneralRe: Weird: Very confusing Base64 problem (includes quiz) Pin
RickZeeland10-Aug-22 21:47
mveRickZeeland10-Aug-22 21:47 
GeneralRe: Weird: Very confusing Base64 problem (includes quiz) Pin
Richard Deeming10-Aug-22 22:59
mveRichard Deeming10-Aug-22 22:59 
GeneralRe: Weird: Very confusing Base64 problem (includes quiz) Pin
RickZeeland10-Aug-22 23:20
mveRickZeeland10-Aug-22 23:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.