C# Gotcha or /Facepalm moment?

So I was playing around with a little idea and while putting together a simple class, very hastily I might add, I accidentally did something that caused a StackOverflowException to be thrown.

This is a very simple version of a Property in C# but can you see what is wrong with this bit of code? Take a look at the returned variable name, see how it starts with a capital ‘S’? This code actually does cause a StackOverflowException. Obviously, you want to use ‘someValue’ and not ‘SomeValue’ in your get and set methods. I made this mistake because I was in a rush and using Visual Studio’s little intellisense helper I accidentally selected my newly created Property over the actual variable I needed.

On a side note, I really need to find a good code colorizer/formatter plugin for WordPress. Does anyone have any good suggestions?

Author: Scyanide

Software Engineer wanting to share his experiences.

2 thoughts on “C# Gotcha or /Facepalm moment?”

  1. I think this is where VB.Net has one of its few advantages. It picks this stuff up as a warning — in this case, “Expression recursively calls the containing property ‘[PropertyName]’.”

    1. Yeah, one would think VS would pick this up right away before you build but guess not. I wouldn’t mind having that warning though. I wonder if changing the warning level would affect this little hiccup any.

Leave a Reply