After I posted my first video about switch and if statement performance, I received some constructive criticism suggesting I may have oversimplified the problem. They’re right. I did. I presented a trivial case that was going to perform about the same regardless of the scenario. I decided to try this experiment again. This time, I […]
Once compiled, is there a significant difference between if statements and switch statements? I wanted to find out. Thanks to /u/sauce-control, I played with this example in the very awesome sharplab.io tool.
C# subreddit question time again! This time, “Which string comparison method is faster?“ I took a bit of a deep dive to see what each code path does. I decided to compare string.Equals(a, b), string.Equals(b) , ==, and !=. Which one is faster? Which one runs less code? Aside: I have a new YouTube channel […]
Another great question from the C# subreddit. Say you have a foreach loop that looks like the following. Does the function in the foreach iterator get executed each iteration, or is the result cached? There’s two parts to this question as I learned earlier.
Another great question was asked on the C# subreddit about integer vs. floating point division in C#. In the post, the commenter essentially asked why, if they store the result of their division in a float, does the whole calculation produce the “wrong” answer?
This morning I saw a great post on the C# Subreddit – “What is the difference of using auto-properties over properties in C#?” At the start of my career, I was confused about when to use each, and why properties were any better than public fields.