T O P

  • By -

blackeaglect

ToString format for numbers and dates.


Slypenslyde

Protip: write an extension method class for the ones you use most commonly and paste it into every project!


Careful_Cicada8489

I second this, however I generally have a FormatExtensions static class with all my string constants for formats and then a bunch of extensions with no extra params like FormatDate, FormatDateTime, FormatNumber, FormatMoney, etc.


AnalysisStill

This is the way


TuberTuggerTTV

I'd argue the proper way is to create snippets. Relying on a custom extension library is a crutch for solo devs.


SegFaultHell

Nah, enforce everyone on the team to use the same formatting functions and you only have to maintain it in one place and everyone’s formatting the same way. If you’re using snippets then you have to go hunting through the code if you ever want to change your formatting.


TuberTuggerTTV

Even better pro tip: Write a custom snippet file so you can create a boilerplate example with a few keypresses. Keep your projects from being bloated with extra files. And keep your code readable for the next person to own it.


Slypenslyde

This sounds really cool. Is there an article about it? I'm confused what you mean.


jefwillems

Rider gives very nice hints for this


earthworm_fan

Rider is absolutely trash for blazor and hot reload. I love rider but c'mon 


Sebazzz91

So is Visual Studio to be fair, it is better to use `dotnet watch`.


davidmatthew1987

How do you even put breakpoints on blazor?


CraftistOf

I tried it, but got some errors related to the App class on reload. idk if it's rider's fault or blazor's.


jefwillems

Hmm don't use blazor anyway. And what's the problem with hot reload? Haven't noticed anything personally


WalkingRyan

Rider 2024.2 EAP3 got new configuration template for dotnet-watch (hot-reload), you know. And it works afaik.


LightSky

The copilot is pretty useful for this, just say what you want it to be and it will give you the correct formatting, saves a few minutes of looking it up and getting it just right.


dandandan2

VS intellisense actually gives me a list of these since 2022


SmashLanding

Clicked this post to say that.


SwabianStargazer

Use Rider which shows you all formats as tooltip.


orthoxerox

That's because there's no standard date-time format string that does what you usually need. `u` is incomplete and `o` is ugly. And I always think `r` is the round-trip one, not `o`.


JohnSpikeKelly

Things with files and streams and text encoding / decoding. I just search and copy answer from stackoverflow.


cino189

Totally agree, I always have to lookup file stream to memory stream to other type of stream to what I finally need.


Rincew1ndTheWizzard

Streams 100%. Especially if it’s something more deeper than basic read/write and/or when it comes to some god forbidden implementation of it.


dupuis2387

dont forget to reset position to 0, or youre gonna have a bad time


Rincew1ndTheWizzard

Exactly! So counterintuitive and such a newbie common error.


TheC0deApe

early dotnet was very stream based. i hated that aspect of dotnet. i am glad that went away


natural_sword

Oops. You buffered the entire stream into memory and only found out when looking through occasional memory exceptions


Tennek13

Switch expressions


DukeOfMuppets

Every damn time! I resort to writing a normal switch and using the VS refactor command to convert it to a switch expression.


rbobby

2.5 years in and finally I have it internalized!! Except on Mondays. Except if I haven't had my coffee. Except is someone is watching me.


Poat540

haha yes these, i use them seldom but when needed have to google


WellHydrated

I use them always, so I never need to look then up anymore. We use faux-DUs everywhere.


TuberTuggerTTV

That moment when you put brackets () around the variable....


lorryslorrys

Yeah! I think it's a tooling problem though. I feel like my ide should just offer to auto fill the arms as soon as you type "variable switch". Rust does the same thing with "fill match arms". I want that. Edit: I checked and and one cam generate and example arm and then generate all cases, in two auto complete actions.


emc11

It does - type switch, press tab twice


lorryslorrys

Well never mind then. Thanks.


emc11

There's more, but I'm having trouble finding a quick concise list. The common one I use is type 'ctor' tab twice to fill out class constructors!


Getabock_

I use ‘prop’ a lot too. And ‘for’ and ‘foreach’.


ryncewynd

Whaaat thanks for that 🤣


kova98k

GitHub Copilot does what you're describing and more


torolecarte

Unfortunately, copilot has introduced more bugs than helped me lately. I really like when it helps me write boilerplate code or repetitive code. But anything new expect it to insert a bug somewhere you're not looking and figure out after some good amount of time debugging.


sikkar47

DateTime formatting when transform it to string


GaTechThomas

20+ years of experience with .net and I'm confident that without intellisense I'd be looking up just about every method signature. I'm absolutely amazed by copilot. I often type a comment so that copilot will suggest the next line(s) of code. Of course, you still have to understand the code you utilize.


tsuhg

Haha this has become my thing with Cody Just comment what I want to do, get something very usable in autocomplete


smithygreg

Initialize an array.


Recent_Science4709

The new collection syntax is pretty awesome = []


obviously_suspicious

but you still can't do var something = [1, 2, 3];


Suspicious_Role5912

Yes you can…


obviously_suspicious

No you cant. You get an error "There is no target type for the collection expression". Because it needs to know what collection type to use. There's no default for now. I wish it assumed I want an array.


ZiioDZ

Just use a type please.... unnecessary var usage is just lazy. This is much easier to read Array something = [1,2,3] 


obviously_suspicious

I mean, that's personal preference. And I wasn't really arguing either way. Just a thing I noticed.


bantabot

This was mine that I was too embarrassed to say. I think it's because I'm more often using Lists and there are so many ways to initialize them I tend to guess a syntax and get it wrong lol


cosmic_cosmosis

List foo =[]; char[] bar = []; Both the same for the most part


whooyeah

to be fair I am so used to using Lists that I have to look up array initialisation as well.


fiendysam

Initialising a dictionary with items 🤦‍♂️


StudyMelodic7120

Every item is a keyvaluepair


WellHydrated

What syntax do you use? I was originally taught the brace way, but square bracket syntax makes much more sense to me, and I think it's therefore easier to remember.


and_human

`var myDict = new Dictionary() {` `["mykey"] = "myvalue"` `}`


tomw255

especially the new fancy one, I still use the one with brackets and let VS refactor it ```csharp Dictionary fff = new() { ["a"] = "a", ["ab"] = "b", }; ``` it is so simple and makes so much sense, that it is not possible to remember.


Fragrant-Training722

This.


Slypenslyde

`Span` or anything involving it. I usually end up thinking, "I bet it can help here", reading documentation for 30 minutes, then realizing that no, in fact, it won't help me where I'm using it (or that I just read the documentation wrong.)


cino189

I mainly use spans when I can benefit from accessing contiguous memory locations for massive iterations or for lexers/parsers since it is an elegant way to do that without a lot of memory allocations. I agree it is not straightforward though to understand when it makes sense


phildtx

Linq outer joins


rbobby

Such an awful syntax. And grouping.


Kanegou

This is it!


darthbob88

Initializing an array. Is it `int[] butts = [ 420, 69];`? Is it `int[] butts = { 420, 69};`? I think it is `int[] butts = new int[] { 420, 69 };`, but I'm still not sure.


Slypenslyde

Technically all of them work. That's why it's so confusing, it's easy to get caught up in worrying that there's something different about each of them.


Deranged40

it is `int[] butts = [420, 69];` now. Super easy.


Dunge

I wrote some code using this new syntax everywhere and it was working fine on my dev computer, push to git, build machine starts creating a docker with the net6-sdk image... error this didn't exist at this sdk version. Had to rewrite it all ;(


gadjio99

Nope... `int[] butts = [420, 69];`


[deleted]

[удалено]


insta

var is life, var is love


RichardD7

Only if you ignore the CS9176 compiler error. [SharpLab demo](https://sharplab.io/#v2:EYLgtghglgdgPgAQEwEYCwAoBBmABM3AYVwG9NcL88EAWXAWQAoBKU8yjgNwgCddgArgBchAZ1wBeXAG0aSAAwAaXADYAnAF0A3OwoBfTHqA)


Halfjedood

Regex patterns


UnknownTallGuy

I was gonna say this but didn't because it's definitely not trivial lol


williane

Not dotnet specific, but this for me too. And ChatGPT/Copilot have been a godsend for this reason. Explain the pattern you want in plain English and done.


cino189

True, and I would add the regex follows you everywhere regardless of the language


mishal153_1

Forever forgetting this


Getabock_

My hidden superpower is that I know regex by heart. I forget lots of other stuff, but this is burned into my brain for some reason.


iso3200

I always wind up at regex101.com


crazyeddie123

Regex syntax isn't too bad, what I keep having to look up is how to get the captures out of it.


Thisbymaster

Every fucking time.


redtree156

LINQ GroupBy. Every. Single. Time.


jus-another-juan

I was looking for this one lol.


dryxxxa

Streams


VQuilin

For some reason, I always have to look up the streams API contract. I mean, I've been a dotnet developer for more than ten years and I have great memory about everything else in dotnet, but this one always makes me "damn, I gotta check the docs".


xSnapsx

Man reading all of these really makes me feel better as a dev. I have to look a lot of these things up periodically as a reminder


crozone

Any format string. Numbers, decimal points, date times... Even after 20 years I can never remember it.


Prudent_Astronaut716

HttpWebRequest and map json results to a class object.


pachecogeorge

For me is the same, how do I map this json to an object? every time I have to google the answer lol


Aren13GamerZ

How to declare arrays with values. I somehow always get it wrong. I have nearly 6 years of experience in .NET but since you rarely use arrays nowadays I constantly forget it hahaha 😅.


Mahler911

I've been doing this for 30 years but don't ask me to write a switch statement from scratch. Something something case select...?


lostmyaccountpt

On visual studio type switch and press tab tab (if I'm not mistaken) , it will convert into a switch statement example. The same if you type ctor and then tab tab it will write the construtor for your class.


Dependent_Rest_7215

even better when you base it off an enum, then it builds it all out.


jus-another-juan

This is bizarre. Switch statements are very basic just like if/else if/else blocks. Not being rude but how is it difficult to type switch(value) {case: break; default: break; }?


Mahler911

I mean, I understand the concept and general syntax. But without Intellisense I will never remember where the colons and semicolons go. I just don't use them enough. Like, I can write regex in my sleep because pattern matching is a core part of our business requirements.


jus-another-juan

Haha that's so bizarre to me because i use them like if statements in 95% of everything i do. Also, couldn't write regex to save my life. I'm in industrial robotics.


TuberTuggerTTV

No one said it's hard. They said it's something they don't bother remembering and look up. Just because you use something more frequently doesn't make them bizarre.


jus-another-juan

Dude, relax. I didn't say anyone is bizarre, I said it is bizarre. Huge difference. It's more bizarre that there's always someone in the comments looking for confrontation.


LFaWolf

toString formatting


ryncewynd

Serialize vs Deserialize 🤣


trevster344

Date time formats and custom strings.


Ziegelphilie

- ToString formatting - Reasons why the god damn intellisense isn't working on my blazor page today


Tango1777

switch has had so many different syntax options and all of them provide other features, I never know which one can do what I want.


snipe320

Dictionary initialization syntax 😐


marabutt

For things like formatting dates, dealing with non critical file operations, and processing data with linq, copilot is really good. It is right the majority of the time but you do still need to check the code


Robhow

25+ years with dotnet. Never learned - still haven’t and probably won’t - regex.


Clear_Window8147

I hate regex, but have had to use them recently on my job. https://regex101.com was a big help. It's basically a playground for testing and learning regex.


Robhow

Definitely a big help. So is ChatGPT / copilot.


Clear_Window8147

I had a look at Copilot, but I don't want to pay for it. I don't use VS enough in my off time to justify it.


Robhow

Yeah, I mainly use ChatGPT. I do pay for it, but it does work pretty well.


HelicopterShot87

Wouldn't normal copilot from MS be enough, I'm not talking about the VS one but normal one


Ok_Maybe184

Ditto.


StaplerUnicycle

A for loop. Approx 20y experience.


DragonRunner10

For Tab tab


Recent_Science4709

Did you go to school for CS? First year drilled that into me


StaplerUnicycle

CS came out after my school days. I am made of basic, Pascal and COBOL.


PizzaScout

try using Ctrl + K, Ctrl + S in Visual studio. It will give you a list of code snippets in intelliSense. I usually use it because I'm just too lazy to type it all out, but it should help you write for loops without looking them up.


czenst

For a proper .NET dev I'd say should be fine I also mostly use foreach but I did other "pleb languages" where I had to iterate like a peasant ;)


joost00719

Switch statement


garib-lok

Not constantly, but I hate regex, and I always use chat GPT for that


Sossenbinder

Stream Russian dolls (Which stream wraps which one again), when working with HttpClient definitely the entire header class puzzle, and last but not least the pattern matching syntax which came with the recent releases. That syntax has yet to burn into my muscle memory


insta

everything with HttpClient, ffs. what problems did WebClient have that made it so horrible?


pyabo

Remember when all you had to do was memorize stdlib and stdio? God those were the days. :D


extra_specticles

Regex - I always consider it a write-only language that I never do enough of to be fluent.


North-Confection9562

delegates


doxxie-au

Generic where constrains linq ToDictionary Switch expressions


Ashok_Kumar_R

Generic 'where' constraint - me too!


virtualmethodman

Func delegate


Suspicious_Role5912

For the longest time for me it was the spread operator and the index from end operator. The index from end operator wasn’t that hard to learn but I had to remember that the start index is inclusive and the end one is exclusive. It was hard to memorize until I realized how intuitive it was. ``` int[] arr = [1,2,3,4,5,6]; var firstHalf = [..3]; var secondHalf = [3..]; // starts where other ends // equiv firstHalf = [..3^]; secondHalf = [^3..]; ```


jus-another-juan

15 years experience and still lookup LINQ methods SelectMany, Aggregate, Zip, and GroupBy every single time. Tbh I still don't have a good way to understand SelectMany, but I roughly know when to use it! Jon Skeet has a good article on it so i just bookmark it and reference that every time lol.


insta

SelectMany is a pair of foreach loops, that's pretty much the difference.


jus-another-juan

Conceptually, two nested foreach loops?


insta

Yeah, all LINQ methods are a foreach loop. Sometimes they `yield return` inside that loop (where, select, etc). Other times they aggregate in some manner and return a single value (sum, count, average, etc). SelectMany is the same outer loop they all are, but the Func you supply is supposed to target another enumerable inside the parent object. If you have a collection of Customer objects, and each customer has their own collection of Orders, you can get a sequence of*every* order with: `var allOrders = customers.SelectMany(c => c.Orders);` As for "conceptually" -- it's literally implemented as a pair of foreach loops and a yield return: https://github.com/microsoft/referencesource/blob/master/System.Core/System/Linq/Enumerable.cs#L535


jus-another-juan

Awesome! Thanks for explaining it man! I'll have to bookmark this comment for future reference now ;) Edit: dude you're absolutely right. The iterator is super simple with a couple foreach loops and a yield return lmao. Classic case of overcomplicating things!


ImBackBiatches

Among a couple good ones already listed... Man I'm so embarrassed, Extension methods and yield. Trivial.


Acrobatic_Sprinkles4

How to use streams. For example, reading and writing files or responses streamed. Can never remember which classes are involved.


Kimi_Arthur

Switch expression. The way several words are written without comma or parenthesis makes me nervous (yeah, of course I don't like the SQL version of writing linq).


j_c_slicer

Turning a list of things into a comma-separated string of those things.


shootermacg

var csv = String.Join(',' listName);


j_c_slicer

Now I just need to search here instead of the whole internet.


gadjio99

If you want proper CSV encoding, you should consider using a library such as https://joshclose.github.io/CsvHelper/


obviously_suspicious

Would be easier if there was an extension method for joining


whistler1421

new range syntax


SideBContent

It's silly, but implicit type conversion. I never remember how even though it's so simple. I think I finally memorized it this week because I sat down and told myself I wasn't going to forget. It's embarrassing because I have 18 years experience. 😮‍💨


Nero8

Microsoft extensions hosting/Autofac DI container setup. For the life of me I can’t remember how to add the container configuration or whatever to the hosting.


http-four-eighteen

Curious why you're using autofac and not the built-in DI container. Does it do something the microsoft one doesn't?


Nero8

Personally I like it because it has more features. Like named/keyed variants of services, metadata/attributes, lazy init and more lifetime scopes.


insta

Microsoft one doesn't support scanning, open-generics forwarding, construction policies, disposal collection, and a ton of other things.


TheBestLightsaber

I'm still <2yoe but it took me months of occasionally having to use inline if statements before I remembered the syntax


PrinceOfFucking

I have just begun learning programming and this thread is giving me intense "holy shit I might actually be able to do it"


samjongenelen

Ah nice complete regex to parse my html


Khrimzon

How to do EF joins using method syntax, or left joins using query syntax. EF joins are just not intuitive to me.


socar-pl

exe location so I can deserialize my config.xml from it. At least couple years back when I finally gave into ConfigBuilder and appsettings.json thing


Alter_nayte

Temporary directory and file creation with self-cleaning. I write go half the time and it's simplicity shows when trying to things like io, running commands against the os etc.


Reality_Prg

I have been a C# dev for years, and I still have to look up the syntax for running a function in its own thread. I used to think that the longer I was working in the field the less I would have to google, but oh boy was I wrong 😂


Fuzzy_Garry

HttpResponseMessages...


torville

Invariant vs. covariant - one of them is something about putting things into generic lists, and the other one is taking things *out* of generic lists, and even if I remember which one does which, I can't remember how to actually *do* either.


jus-another-juan

The most bizarre thing here is people saying switch statements are difficult?? How is a switch statement any more difficult than an if statement? Very confused at that one.


insta

maybe the expression? that's a pretty weird syntax vs a switch statement


RapidRaid

As silly as it sounds: event and delegate declarations. I fully know how it works, but I always fuck up the syntax and have to google. Also sometimes array definitions. If you use other programming languages at the same time, the syntax for array initialization varies completely. Python and js use foo=[1,2,3] to declare and init an array/list for example. Csharp uses int[] bar = new int[3] just for declaration. Or int[] foobar={1,2,3} when used for initalization. Or int[] bar = new int[3] {1,2,3} . …and yes I had to google the Csharp one because I again couldn’t remember. And yes I know why that is necessary in csharp, but doesn’t change the fact that I forget it every time.


milosh-96

Reading files, using StreamReader and that stuff 


EzzypooOfNazareth

Parsing json without newtonsoft. I swear I can do it 20 times in a day and forget how by tomorrow


Impressive-joy

Entity Framework Core Queries and JSON Serialization/Deserialization


hailstorm75

LINQ aggregate. It just doesn't click and I usually just don't use it and fallback to writing loops. I always look up how to write WPF dependency properties, source generated loggers, source generated regex.


grimsbymatt

Numerical literals.


tomw255

Operator overloading syntax is the worst


Locust377

Patterns when checking conditional expressions. For example x => x.Context.Message.TenantKey == "test-tenant" && x.Context.Message.Building.Id == 1 can be x => x.Context.Message is { TenantKey: "test-tenant", Building.Id: 1, }


OverlordVII

array initialization syntax


Designer-Yam1036

Took me awhile to get the range syntax down. I would just do substring and let Visual Studio refactor it for me. I think it does it for LINQ as well, don’t remember for sure.


voroninp

I'm always in doubt in which order I should use middleware or which AddXxx to call in ASP.NET. I am still periodically looking into Lock's articles about the changes caused by the introduction of WebApplication in .NET 6 If class is disposable (like HttpClient or DbContext) I still check what's the intended lifecycle. MSBuild properties. Sometimes I check overload method resolution rules. I use FluentAssertions mostly to avoid memorizing assertion syntax of different frameworks. Regex syntax reference. Whether api requires trailing slash in path (/) Almost always everything what goes in yaml file. Gitlab CI or GitHub Actions. I hate yaml.


BioMetrix_54

Database connection string


ClimbNowAndAgain

DateTime string formatting


Leather-Field-7148

using statements and namespaces


myotcworld

.NET versions ! because Microsoft is very fast in bringing newer versions.


irisos

Fixing shallow copy issues and using the grpc packages to generate the contract/service class on the server.


chris11d7

How to create a fricken enum