Archive for the ‘Advanced CSharp’ Category

Stackalloc in CSharp

misc_vol4_006 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.

Read the rest of this entry »

Republished by Blog Post Promoter

Making values nullable

A04C0009 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

Read the rest of this entry »

Republished by Blog Post Promoter

Advanced CSharp – yield

tran-land-05 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:

Read the rest of this entry »

Republished by Blog Post Promoter

&& vs & and | vs ||… What’s the difference?

color-01 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

Read the rest of this entry »

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.

Read the rest of this entry »

Republished by Blog Post Promoter

Bear