|
Which is not a with statement.
|
|
|
|
|
And what is a with statement
|
|
|
|
|
Something C# doesn't have. And which I find useless in lesser languages.
|
|
|
|
|
I'd agree - the scope should logically be limited to the if block.
It seems strange that it wasn't really ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Needs to apply to an else if present?
|
|
|
|
|
Nope - because if it isn't that class, it should be at best null and thus unusable in the else
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Which maybe I want! I can use null better'n anybody! (OK, probably not.)
But what if the syntax allowed the use of the null-coalescing operator as well! Way hey!
|
|
|
|
|
We could call it something like B# and just copy and paste VB.NET, best language without the VB name stigma
Oh wait we don’t want something easy that can do the same job better do we
KISS principle
|
|
|
|
|
It does the null test, declares the new variable, assigns the value and completes the if in one statement. Think of it like the very old C way of doing a for loop:
int i;
...
for (i = 0; i < 10; i++) ... As opposed to the simpler version that was added in C99:
for (int i = 0; i < 10; i++) ... People complained that that was a kludge back then as well!
I was a sceptic, but once you are used to it you probably won't go back.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I agree, yes, that's good, though I don't use C99 either.
On the other hand, I notice that there is no similar syntax for while .
|
|
|
|
|
While is more of a "general purpose" loop construct, most commonly used with things that have been already constructed, like file pointers, linked lists, strings I think. It's less likely that you'd need the declarative part since a while loop doesn't have an initialisation phase like a for loop does.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
But it could! Except then it might just be roughly equivalent to a foreach anyway.
|
|
|
|
|
Which they added to C++ anyway ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You can't keep anything nice. (I've only ever dabbled in C++ .)
I may need to look at D again.
|
|
|
|
|
I really like ?? since they made it possible to throw.
something = myParameter ?? throw new ArgumentNullException(...)
also handy in if statements.
Optional arguments: better than 100 overloads, but as with everything use with care.
(): If indeed value tuples - better than what we had (no more Item1, Item2)
?[]: Never used it, but I use ?. all the time -and it would be strange if ?[] wasn't available as well.
Discards: Handy when needed - do not use them a lot, but when you do they make it clear right away.
Switch expressions: Why oh why.... where they not added earlier. No more crappy switch statements full of returns or variable assignments - and a compiler warning when I am missing a state. I need to figure out how to use them nicely with enums though - I want a catch all that throws if not a defined enum value, but still want a warning if a new enum value is added and I do not handle it
And nullable in general is of course the best thing since sliced bre... no, wait - I can just eat the bread without slicing it! Just too bad it is a bit crippled as we still need to call legacy code and the required keyword isn't coming before next version.
|
|
|
|
|
lmoelleb wrote: I need to figure out how to use them nicely with enums though - I want a catch all that throws if not a defined enum value, but still want a warning if a new enum value is added and I do not handle it Once you figure it out... write a tip
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpful answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
lmoelleb wrote: Switch expressions: Why oh why.... where they not added earlier. Yes, exactly!
|
|
|
|
|
Maybe you would prefer VB 6.0?
Everything on your list is stuff that I use every day (except the ?[] - hardly ever have to specifically index something.
|
|
|
|
|
Never hate.
I don't use any features of C# newer than v3.
The other week I found that I was using a Dictionary Initializer (which is a v6 feature), so I reverted it to a Collection Initializer (which is a v3 feature).
I use the ?? operator (the null-coalescing operator, a C# 2 feature) occasionally, such as when interpreting a command line.
|
|
|
|
|
Then you wont like this valid c# syntax:
if (jsonReader.TokenType is JsonTokenType.EndObject or JsonTokenType.EndArray)
{
}
Old syntax:
if (jsonReader.TokenType == JsonTokenType.EndObject || jsonReader.TokenType == JsonTokenType.EndArray)
{
}
Graeme
"I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee
|
|
|
|
|
Yeah, still just trying to attract VB developers.
|
|
|
|
|
PIEBALDconsult wrote: Yeah, still just trying to attract VB developers.
I am seeing a lot of very old VB features creeping in. Probably for the Python crowd.
Graeme
"I fear not the man who has practiced ten thousand kicks one time, but I fear the man that has practiced one kick ten thousand times!" - Bruce Lee
|
|
|
|
|
Just like many here I use them daily.
Especially ?? and ?.
Sure as hell beats if (x != null && x.Y != null && x.Y.Z != null)...
Discards are useful when you don't need the variable (for example, when doing a TryParse, but only want to validate and not directly use the value).
Tuples are great and also beat having to write one-off classes that you'll never use again.
Are you sure you hate the features or that you hate having to keep up and not understanding them?
|
|
|
|
|
Sander Rossel wrote: Are you sure you hate the features or that you hate having to keep up and not understanding them?
That may be the case. It does seem to get harder to constantly update your skillset, but every time I've done it so far it's been well worth it in the long run.
The last big jump update was abandoning C++ (where feature creep is even worse than in C#) in favour of C#. And I have never regretted it: the speed of development and the clarity of the code is so much better - and that impacts the reliability and maintainability of the code as well.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|