|
BillWoodruff wrote: the result of 'yield return null' and 'yield break' are the same
But they're not though.
static IEnumerable<string> YieldReturnNull()
{
yield return null;
}
static IEnumerable<string> YieldBreak()
{
yield break;
}
static void Main()
{
Console.WriteLine("Yield return null:");
foreach (string item in YieldReturnNull())
{
Console.WriteLine("Item: {0}", item);
}
Console.WriteLine();
Console.WriteLine("Yield break:");
foreach (string item in YieldBreak())
{
Console.WriteLine("Item: {0}", item);
}
Console.WriteLine();
} Yielding | C# Online Compiler | .NET Fiddle[^]
Output:
Yield return null:
Item:
Yield break: yield return null; creates an enumerator which returns a single item. yield break; creates an enumerator which doesn't return any items.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
@RichardDeeming
Hi Richard, Thanks for (as always) enlightening !
I will respond to this in depth with a post on the C# forum ... in a few days ... that I hope might spark a "best practices" discussion. I went back and searched my code for the last year for instances of 'yield break' ... I have been using it, along with the 'other.'
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
I return nulls a lot. I think twice before I don't check for nulls. Still I do that less often than some people.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
i've totally stopped returning NULL. i'm writing Go. it uses 'nil' instead.
|
|
|
|
|
Mission accomplished!
TTFN - Kent
|
|
|
|
|
The author of that article should read up a good book on Functional Programming to learn better options to what he described.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
Lol, returning a default value, like in his example a connection string to the wrong database, yeah right
modified 20-Oct-19 21:02pm.
|
|
|
|
|
With its well-thought-out rebuild of Dart 2 five years later, Google seemed to have proven its commitment to the language. Indeed, today it continues to gain traction among developers—especially Java and C# veterans. She makes a few good points
Let the punnage revenge flow over me now - like sticky mushroom gravy (that part wasn't a pun, I'm not a fan of gravy)
|
|
|
|
|
|
A-wow, what a square, don't you dig the scene?
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
This is going to be possibly insensitive but was that author ALWAYS a she? If I get a hand slap about this so be it.
|
|
|
|
|
What would you do differently at work if you were the boss? I'm really surprised that's not 100%
|
|
|
|
|
Not me. Have had the same laptop for 6 years. If I get a faster machine, I "might" become more productive. Then my boss would expect that all the time. Keep the expectations low and use technology as the scapegoat. Win-win.
|
|
|
|
|
OK, that makes perfect sense. I sit corrected.
TTFN - Kent
|
|
|
|
|
Let your workplace be upgraded. You might always blame the IT, they can slow you down even more than old technology.
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.
|
|
|
|
|
You are a fan of Wally, aren't you?
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
Every week, I politely ask "Where the F**K is my helicopter?!?", but no-one ever has an acceptable answer.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
IBM X-Force Red, which is a team of veteran hackers at IBM Security with the primary aim of uncovering potential vulnerabilities in networks to help safeguard against them, announced today that it had discovered a potential weak point in network security that hackers can exploit to infiltrate the network and subsequently gain access to the devices and the data on it. Beware of IBM security "researchers" bearing gifts
|
|
|
|
|
Just the name "X-Force Red" tells you that they're a wunch of bankers who are pretty much giggling, drooling, and m@sturbating their way through their "discoveries".
A good kick in the bollocks for each of them. It's the only viable solution.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
I just wonder... why the hell are those guys not used in the QA doing those discoveries before shipping the product
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.
|
|
|
|
|
For decades, the dream of motorists all over the world has been a car that could run on frothy buckets of cheap, garbage fish like tilapia or something. Even more shocking
OK, not completely on topic for the news, but you never know when you might need this information.
|
|
|
|
|
Theoretically, a diesel-type engine can be produced that runs on ambient air -- we certainly have the technology for it.
I wonder why no-one has ever made an effort to prototype this.
I wanna be a eunuchs developer! Pass me a bread knife!
|
|
|
|
|
Mark_Wallace wrote: I wonder why no-one has ever made an effort to prototype this. Because as far as there are people getting immensely rich with oil, the rest of the technologies will probably have to wait their turn
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.
|
|
|
|
|
Realizing the article is tongue-in-cheek, I do want to point out that the author completely ignored how much it would cost to keep 7200 eels alive and zapping. Far more than keeping the most gas-guzzling vehicle going, I suspect. - Or any other method to keep your electric car going.
Brent
|
|
|
|
|
I'm sure his next article will try putting a windmill on the roof. That way, the wind generated by driving will charge the car so you can drive farther. Perpetual motion!
TTFN - Kent
|
|
|
|