Come on let’s talk .. ..

I was reading a book last night and noticed plenty of codes in that book were using ‘ref’ in the methods. Mmm.. plenty in the sense almost all of them except where the example methods have some value type parameters.

Here’s a simple example, (a screen shot of the page)


Then I thought we all know that reference types are passed to methods as reference (though the pointer is passed as a copy), there is no any specific need to have the ‘ref’ keyword. (Please correct me if I’m wrong)

Unless you can save few bytes of memory for the new pointer in the stack. 🙂 which will be kicked out immediately after the code/methods returns.

I have already made a post on ‘ref’ and ‘out’ keywords. (See here) These two keywords are really very interesting bits of C#.