How to initialize a dictionary with a collection initializer - C#

Learn how to initialize a dictionary in C#, using either the Add method or an index initializer. This example shows both options.

These are the official docs for the programming language. Fuck all the way off with this

gee, thanks microsoft. I love that "surprises and mistakes" are now an expected outcome of following your official docs.

fuck you into the sun

@jenniferplusplus I hate that with any class of AI products - "surprises and mistakes" are just to be expected. How the hell can we build anything reliable with this?
@jenniferplusplus If there's *one* thing a programming language is supposed to do, it sure as fuck isn't *that*.
@jenniferplusplus This is the same Microsoft who, for decades, has sent "Help/See documentation" requests from their own OS to their search engine (where results could be "gamed") instead of directly to the actual authoritative page on their website.
@jenniferplusplus it makes programming more exciting! you'll never know what you're gonna get!
@jenniferplusplus vibe coding is literally gambling
@jenniferplusplus
Ten years later:
"Do you know where we can get Copilot 2025? I need to rebuild a project."
@jenniferplusplus a little happy surprise of completely broken code!
@jenniferplusplus breaking the "your program does EXACTLY what you tell it, nothing more, nothing less" contract seems like a really bad idea.
@jenniferplusplus worst part is, even among the AI evangelists people think AI is bad at C#. There's whole tools dedicated to forcing the AI to be slightly better at C#. So this is even more egregious

@jenniferplusplus this always seemed so counterproductive to me, I thought the point of AI was supposed to be precisely that you wouldn't need to look in the docs in the first place, if you need to be instructed on how to prompt it, what the hell is it even for?

I mean of course I know really that the answer is "the docs don't exist to help people, they exist to push the ai" but come on man, push it in a way that makes sense (if you have one)

@andrewt
Also, if I know I want to initialize a dictionary, shouldn't I just... initialize the damn dictionary? I mean, come on, I am a lazy one, but I have my limits.
@jenniferplusplus
@ozzelot @jenniferplusplus yeah, this really seems like a case where you'll need to internalise this knowledge sooner rather than later, probably worth doing this one old school even if just as an exercise

@jenniferplusplus I'm sorry what

Is this for real???

How many C# devs & contributors quit for this

@ity @jenniferplusplus
MAUI was basically abandoned to shift resources to this shit
@ki @ity @jenniferplusplus also, apparently WinUI. And Kiota.
@chucker @ki @ity just one more unified gui framework bro, it'll all work out if we have just one more framework
@jenniferplusplus @ki @ity oh, don’t get me started 😫
We're Gonna Build a Framework

Music "We Didn't Start the Fire" by Billy Joel © 1989 Columbia Records. Clickable lyrics (yes, they're all actual real frameworks) : http://www.dylanbeattie....

YouTube
@chucker @ity @jenniferplusplus
WinUI seemed pretty much dead from the start tbf. And then there's WPF, which is an unmaintained mess kept on life support
@ki @ity @jenniferplusplus I'm still porting code _to_ WPF. I really don't understand why they they maintain multiple competing UI frameworks, none of which even have much _internal_ usage, instead of trying to e.g. unify the XAML capabilities (e.g. x:Bind)

@chucker @ity @jenniferplusplus
I'm also porting code to WPF in my day job. It's still a widely used framework, it's just that it's basically a huge chunk of technical debt without much maintenance. There are some community PRs that get accepted every so often, but that's about it

There are a lot of supposed reasons for all these newer frameworks, but all of them are so half-assed it's just sad to see them come and go

@jenniferplusplus i love the idea that ai is going to revolutionize coding because you "dont have to know how to code" but then its also just "write this really long, specific prompt using these technical terms that you would need to know to just code it normally, except now it has a chance to not work"
@Li @jenniferplusplus someone ran a pilot where I work where a team did a project they'd basically done before, but now with AI. Took 'em less time, unsurprisingly. Questions regarding the fact that *they already knew how to do the project the second time around* were waved aside. They don't care! And it doesn't make sense.
@Li @jenniferplusplus Let's all switch from a language that's designed from the ground up to be unambiguous and otherwise fit for purpose, to English. It'll be great.

@hosford42 @jenniferplusplus

that is the other thing, its kinda clear its being boosted by people who've never coded anything in their life, because like, actually writing the code is like the easy part.

@Li @jenniferplusplus I'm not surprised! It's hard to get this from the outside. The code looks complicated so people assume that's where the difficulty lies, but it's really in designing the patterns the code is there to represent. Not something that can just be gone around.
@Li @jenniferplusplus the AI singularity is now: when people turn up on a forum to say they're stuck they also add "and I asked chatgpt but its answers didn't work either"
@jenniferplusplus Oh hell. I am NOT prepared to open a discussion about changing our entire fucking tech stack, but... guess that's where we are?
@jenniferplusplus i didn't know Why i was getting out of the .net ecosystem when i migrated off windows/microsoft i just knew a reason would appear at some point in the future
@jenniferplusplus as an aside who is this for lmao. like this feels specifically aimed at people who slept through the first 6 weeks of some early cs class, got told "initialize a dictionary with the collection initializer", and didn't know what any of those words meant
@kirakira As with the large majority of AI features, it's for no one. No one wanted it. It's there in spite of how disinterested or actively opposed the audience is. The whole thing only works if it becomes absolutely ubiquitous and unavoidable, to the point that nothing works *at all* without paying for some chatbot's API. So this just adds to the ubiquity.
Divide strings using String.Split - C#

The Split method returns an array of strings split from a set of delimiters. It's an easy way to extract substrings from a string.

@jenniferplusplus

so what happens when AI read these docs and you ask the AI how to split a string and it says go ask AI

@gloriouscow
It could ask itself and just overload the datacenter... It would probably be a disaster of some kind, but also funny as all hell.
@jenniferplusplus

@ozzelot @gloriouscow @jenniferplusplus

Can't wait to see the day when asking Copilot to initialize a dictionary results in:

Dictionary d = eval(copilot.api.ask("write an initializer for a dictionary"))

I guess *this* is what they meant when talking about the singularity?

@jenniferplusplus what!? Which language is this so I can avoid it like the plague?
@jenniferplusplus What the fuck, no.
@jenniferplusplus We're going to reach the day where the AI goes to read the official docs... and the world implodes.
@jenniferplusplus here I already was of the opinion that corporations shouldn't be allowed to own programming languages, but this image just bumped all the way up to exhibit A, it might be all the evidence I need
@jenniferplusplus Microsoft is really fighting tooth and nail to make me hate my favourite programming language
@jenniferplusplus i want to learn how to program for fun but i have been hesitant with using git hub for being a microsoft website.
@MeimeiTakuto At this point I think that's wise. Don't let it put you off of learning something you want to learn! But do store your code somewhere else. Gitlab is somewhat better. Codeberg seems to be the most viable ethically operated alternative.
@jenniferplusplus Thank you for the suggestion! is codeberg another site like git hub where you can save and share code? #bluesky #bridyfed
@MeimeiTakuto exactly. It's developed and operated by a European nonprofit. The features and behavior are pretty similar to github. And the central feature of providing git code repositories is exactly the same
Remove section calling out using AI to initialize a dictionary by bdukes · Pull Request #48675 · dotnet/docs

Summary I could not come up with any reason that this content was useful to anyone. Internal previews 📄 File 🔗 Preview link docs/csharp/programming-guide/classes-and-structs/how-to-initial...

GitHub

@jenniferplusplus

A great example for "initializing things with AI" is the Microsoft Learn website itself, which is translated with AI.

This leads to the following product categories (at least in german):

  • Fenster (literally "Window")
  • Azurblau (Azure blue)
  • .NETTO (.NET is intended, but NETTO is a german supermarket chain. Without the dot, of course)
  • Leistungsstarke Anwendung (literally "Powerful Application", they mean Power Apps)
@wakame net also translates to netto without the supermarket chain involved, i.e. "net weight" translates to "Nettogewicht"
@wakame @jenniferplusplus
The PowerShell documentation has a couple more, like
- Zwietracht (discord)
- Pufferzeit (slack)
- Stapelüberlauf (stack overflow)
@jenniferplusplus Considering Microsoft's obsession with getting rid of humans in the SDLC, I've ditched C#/.Net development in favour of learning Go(lang). Granted, Google is also on the AI train, but at least Golang is simple enough for them to be taken out of the equation, with minimal pain, if they go full steam ahead with "We don't want humans using our programming language".
@jenniferplusplus what the - and I cannot stress this point enough - actual fuck is that garbage!
Divide strings using String.Split - C#

The Split method returns an array of strings split from a set of delimiters. It's an easy way to extract substrings from a string.

@dazfuller hilariously, that sample prompt has the syntax wrong
@dazfuller
@jenniferplusplus Microsoft really just fed their entire documentation into an AI, told it to add a helpful AI tip in the footer (with matching header tip!) to every page and then pushed it straight into production without ever once passing a pair of human eyeballs
@rolenthedeep @jenniferplusplus most of the prompts I’ve seen have left me wondering “but why would you though” as well

@rolenthedeep @dazfuller
I thought so too, but apparently no! Someone artisanally selected a half dozen teaching articles, and fed them into what was probably an ordinary chatbot session, and then likely copy-pasted the results using a mouse and keyboard into the docs. And then another someone reviewed it well enough to make one unbelievably pointless suggestion.

https://github.com/dotnet/docs/pull/44580

Thus illustrating the glorious AI-powered future our technofeudal overlords have planned for us

Update ms.custom value to the new value and add addl. highlights by anandmeg · Pull Request #44580 · dotnet/docs

Internal previews 📄 File 🔗 Preview link docs/csharp/how-to/concatenate-multiple-strings.md How to concatenate multiple strings (C# Guide) docs/csharp/how-to/parse-strings-using-split.md Ho...

GitHub
@jenniferplusplus @rolenthedeep for one brief moment Bill held our futures in his hands. In the years to come historians will look back at this time and wonder what might have been, what golden path of enlightenment we might have trodden, but for Bill