Skip to content
  • View menu
  • View sidebar
CG LOGO

Chris Green

Complex concepts explained simply.

  • You too?!
  • Contact

Recent Posts

  • EF Core error: The certificate chain was issued by an authority that is not trusted.
  • Debugging C# Web API for first time in VS Code — fix “don’t have an extension for debugging XML” error
  • Cloning Bitbucket Repositories with GitHub Desktop: Get Authentication to Work
  • How do I change my name and email for my global git config?
  • JavaScript DeepClone function created by ChatGPT and it works

Archives

  • February 2025
  • January 2025
  • September 2023
  • October 2022
  • May 2022
  • August 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • August 2020
  • June 2020
  • April 2020
  • January 2020
  • May 2019
  • April 2019
  • March 2019
  • January 2019
  • September 2018
  • August 2018

Categories

  • .Net
  • Browser
  • Command Line
  • Development
  • Git
  • Javascript
  • Mac
  • Raspberry Pi
  • Terminal
  • Visual Studio
  • VS Code
  • Vue
  • Windows

Tag / c#

October 16, 2022 by Chris Green

C#: What happens if a foreach is applied to an empty source or if the source is null?

  • .Net
  • .net, c#, development

If the source collection of the foreach statement is empty, the body of the foreach statement isn’t executed and skipped.

If the foreach statement is applied to null, a NullReferenceException is thrown.

More Information:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/iteration-statements

Proudly powered by WordPress | Theme: editor by Array