Tuesday, April 10, 2007

Parameter Scope in C#

By scope, here, I mean 'value' type or 'reference' type.

The parameters are passed almost as in VB.net, by default a parameter is passed as 'value' type (ByVal in VB.net). In C# we don't use any specifier to indicate a 'value' type parameter.

For reference types we have specifiers 'ref' and 'out' with a subtle difference between both, which is, all 'ref' parameters must be initialized before being passed as an argument while 'out' parameters need not, whereas, all 'out' parameters must be assigned a value before the method ends. Properties cannot be passed as reference type parameters.

A method can be overloaded by chaging parameter type from value to reference and vice versa. (note that a change by 'ref' to 'out' or vice versa will not overload a method)

For more on this and sample code check this on MSDN online.

Sunday, April 1, 2007

More Differences ...

In my previous post, I had mentioned about the quick difference reference page. Today I was looking for comparison options for a byte value in vb and did a search on Google for "comparing Byte value VB.net" and what I got was what I have been looking earlier with most significant keywords. Can you guess that? It gave me a list of sites that have quick reference guides or cheat sheets for C# and VB.net comparison. At times it makes me feel that after all what I am using is just a machine!

For your reference - some of the useful links from the list -
Complete Comparison for VB.NET and C#
VB.NET & C# comparision
C# and VB.NET Comparison Cheat Sheet