- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
My money is on this being a WTF.
But it is conceivable that it can be used to change the collection size in much the same way that StringBuilder.Length is used. I have on occasion used StringBuilder for doing things like comma separated lists where the last item must not have a comma and I can achieve it like so:
Admin
My best guess would be that it began life as a sort of proto-C++, back well before the arrival of C++98's STL, or maybe even just plain C, and was then "ported" to C-flat, and management said, "You shall port all the old code, really all of it. We'll get someone from outside to audit what you did, and if the auditors find anything that wasn't ported, there will be seventy-three kinds of Hell to pay!" So they did exactly what they were told, and left nothing of the old code out of the port, for fear that management really meant "three hundred seventy" when they said "seventy-three".
No, wondering about it is not a WTF. Well, maybe it is. Maybe the correct verb is "despair"...
Admin
I mean, writable length properties are not really that special, System.IO.Stream has one of those as well, as do various builders like StringBuilder.
Admin
A lot of people just automatically make getters and setters for all properties because they don't really know why they're supposed to have private variables.
Admin
This seems most likely.
Admin
As long as .net forces you to use a property for binding a variable to a control, someone will always find a way to abuse it.
Admin
That sounds plausible to me. I interned at a company that builds such machines around the turn of the century and they were using plain C at the time.
Admin
I think you have a wrong word in there. Try this instead:
Admin
As pointed out in the highlighted comment of 2026-02-18's article, why not do something to the effect of, "if there is more than one item in the list, add the first one to the stringbuilder, then for all the rest add a comma and the next item"? Means you don't have to remove anything at the end.
Admin
Or add them to a List<string> and then do a Join() at the end to insert the commas.
Admin
Depends. I've seen properties used to add range-checking (or null-checking) to variables that would otherwise be public.
Admin
I highly doubt it, but maybe they behave like JavaScript's
Array.length:Admin
That'll remove the comma and the preceding item. What happens if the list is empty?
Admin
The count is a signed Int32. I wonder what happens if you set it negative.
Admin
OK, sure, but we see all too many examples here of
{ get; set; }which transforms the private variable into a public variable with a slightly different name. (Like in today's contribution.Admin
Before I read on and found that customising the HMI meant consuming a C# api, methought the user was given access to a css file so they could do things like
#logo { background-url: var("http://www.shittycorp.com/wp_uploads/2001/y2k_logo-site_new (updated) v2_NEW_NEW.gif.jpg"); }. Then I remembered there are still things that aren't an electron app.Admin
This is just a regular getter/setter pattern in C#. The real WTF is anyone actually using the obscurities of C#, but yes, this is valid.
Admin
And then you get ASP.NET Core Web API, whose JSON serialization only uses properties and not fields, forcing you to change all fields in your DTO to properties.
Admin
You mean t is syntactically valid. In relation to the count of objects in a collection, it is not logically valid, at least not without adding some extra semantic baggage. For example, you could have the code in the setter delete obkjects from the end of the collection when it is made smaller (assuming the collection has some defined ordering) or add a default value to pad out the collection when it is made bigger.
Admin
as I happen to know about this (I submitted this line years ago) it seems to be a COM program which is now wrapped by .NET (Framework, of course)