Archive for the ‘Advanced CSharp’ Category
Stackalloc in CSharp
In the last few weeks we’ve looked at several keywords from the CSharp language that allow us to deal with memory management directly. Stackalloc is another keyword from that list.
Before we look at this keyword, we need to review how .NET deals with memory allocation.
Republished by Blog Post Promoter
Making values nullable
First, a little history lesson.
When .NET was first released, we had value types and object types. The difference between the two is that you do not have to set aside memory for a value type because the memory is placed on the stack. So ints, doubles, and structures are all value types.
However, even though the value type is treated differently, it is still ultimately inherited from the Object type. This is good because it allows us to create a method
Republished by Blog Post Promoter
Advanced CSharp – yield
Have you ever had a situation arise where you want to create a function that returns a collection of results and you want the results to be listed in a for each loop?
Sure you have. And I bet I know what your code looked like too:
Republished by Blog Post Promoter
&& vs & and | vs ||… What’s the difference?
It seems like such a trivial thing to be talking about but not knowing the difference between the two operators can make a huge difference between working code and code that only seems to work.
Let me illustrate:
bool b = false; bool c = true; if(b & c) // do something if(b && c) // do something
Republished by Blog Post Promoter
CSharp’s Property Shortcuts
There are a lot of nice shortcuts in the CSharp language that most of us never use. But if you take the time to learn them, you can be as productive as a student I had who had learned all the keyboard shortcuts to windows so that he never had to take his hands off the keyboard.
It was just a bit frustrating as an instructor because every time he sat down to do an exercise he’d be asking, “what’s the keyboard shortcut for this step?” I have to admit, though, he was definitely faster than anyone else who had ever taken the class.
prop and propg are two such shortcuts.
Republished by Blog Post Promoter