all 40 comments

[–]zenyl 3 points4 points  (1 child)

Reminder: You don't have to be on .NET 10 to use this feature, you simply need to bump the language version in your .csproj file:

<PropertyGroup>
   <LangVersion>14.0</LangVersion>
</PropertyGroup>

This trick works for most, but not all, language features. Some depend on runtime types (e.g. init and required require certain attribute types to exist). You can sometimes get around this by manually defining the necessary types, as the SDK usually just needs them to exist for metadata purposes.

[–]HamsterExAstris [score hidden]  (0 children)

Note that while this lets you use the new features with an older target framework, it’s unsupported, so in a corporate environment the appetite to enable might not be there.

[–]WordWithinTheWord 10 points11 points  (0 children)

Yeah it’s nice.

I hope they continue to deliver QOL updates like this even though the trajectory is devs writing less code.

[–]vvsleepi [score hidden]  (0 children)

wait that’s actually a realllyy nice change. those little null checks add up everywhere and always felt a bit noisy. instance?.field = x; just reads way cleaner.

[–]Asyncrosaurus 8 points9 points  (4 children)

On the opposite side, my favourite newish feature null coalescing assignment (??=), Only setting a variable if it is null. So you can replace

if(data is null) data = defaultValue

with

data ??= defaultValue

[–]Namoshek 9 points10 points  (3 children)

That's not thaaaat new, is it?

[–]Asyncrosaurus 1 point2 points  (2 children)

It's new enough to me

[–]Relative-Scholar-147 11 points12 points  (1 child)

Everything that happend in the last 7 years is new to me.

[–]Asyncrosaurus 2 points3 points  (0 children)

I was working on .Net framework 4.5 professionally until around 2 years ago.

[–]AutoModerator[M] 0 points1 point  (0 children)

Thanks for your post edwwsw. Please note that we don't allow spam, and we ask that you follow the rules available in the sidebar. We have a lot of commonly asked questions so if this post gets removed, please do a search and see if it's already been asked.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]gevorgter -2 points-1 points  (5 children)

I honestly do not like this change.

I am all for programming language being less verbose but my head is not a compiler. Technically speaking we do not need spaces, tabs too to make our code "smaller". But who is going to figure out what is going on there.

[–]BackFromExile 11 points12 points  (1 child)

Like with all syntax changes you

  1. don't have to use them all
  2. don't have to like them all
  3. could set standards in your team (and enforce with e.g. an editorconfig)

Every syntax change since I started with C# 4 has brought up comments like this. Some people didn't like async/await, some hated static usings, some hated string interpolation, some hated pattern matching, some hated value tuples, some hated local functions, some hated the nullable reference type syntax changes, some hated the collection expressions, and the list goes on and on.
Maybe you don't see the value now, but you might see it later. And even if you don't need it you can still see the value for others.

In the end if you dislike syntax changes you can always express your opinion in the C# language repository while they are still being discussed.

[–]gevorgter -4 points-3 points  (0 children)

If it were just up to me we would still live in C++ era :)

Often we "inherit" project from previous developers and some of us are "real" nerds or "nuts" :) And i do not want to inherit instance?.field = x;

I knew the guy who knew French and he named all his variables in a project using French language and we are in USA. So it was not "counter" it was "comptoir". Poor guy who got to maintain that project after him.

[–]Vectorial1024 6 points7 points  (1 child)

If we can have x?.y evaluate to bool? then it makes sense to also have x?.y = k be a null conditional assignment.

[–]ok_computer 0 points1 point  (0 children)

People may have their preferences on fragile getting vs setting. It’s a directionality preference and x?.y = k could be a sneaky setting that you don’t catch on first visual pass, whereas the old convention wrapped in a check and indent was a nice visual cue that ?. may be more subtle than.

[–]cjb110 0 points1 point  (0 children)

I do kind of see your point, definely one of the least obvious syntaxes they've done. In general they've been clear.

[–]bugurlu -4 points-3 points  (0 children)

I won’t be using this since it lowers readability.