What's New in C# 14: Null-Conditional Assignments
blog.ivankahl.com
What's New in C# 14: Null-Conditional Assignments
1–10 of 174 posts
Re: What's New in C# 14: Null-Conditional Assignments
#2Re: What's New in C# 14: Null-Conditional Assignments
#3Isn't this more confusing? Because it skip the code if the value is null and I don't think it is normal to follow the flow assuming nothing has happened.
Re: What's New in C# 14: Null-Conditional Assignments
#4Re: What's New in C# 14: Null-Conditional Assignments
#5I feel like this is another step in the race to add every conceivable feature to a language, for the sake of it.
Re: What's New in C# 14: Null-Conditional Assignments
#6Isn't this more confusing? Because it skip the code if the value is null and I don't think it is normal to follow the flow assuming nothing has happened.
I think it is for situations where the programmer wants to check a child property but the parent object may be null. If the parent is expected to be null sometimes, the syntax lets the programmer express "try to get this value, but if we can't then move on" without the boilerplate of explicitly checking null (which may be a better pattern in some cases).
It's sort of like saying:
- Get the value if you can, else move on. We know it might not be there and it's not a big deal.
v.s.
- The value may not be there, explicitly check and handle it because it should not be null.
Re: What's New in C# 14: Null-Conditional Assignments
#7Re: What's New in C# 14: Null-Conditional Assignments
#8Isn't this more confusing? Because it skip the code if the value is null and I don't think it is normal to follow the flow assuming nothing has happened.
Re: What's New in C# 14: Null-Conditional Assignments
#9I’d rather be explicit. If the value is null then it should be explicitly handled. I feel like this is another step in the race to add every conceivable feature to a language, for the sake of it.
Re: What's New in C# 14: Null-Conditional Assignments
#10Isn't this more confusing? Because it skip the code if the value is null and I don't think it is normal to follow the flow assuming nothing has happened.
> If config?.Settings is null, the assignment is skipped.
If the right hand expression has side effects, are they run? I guess they do, and that would make the code more predictable.