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

Friday, March 9, 2007

VB.NET and C# : quick - difference - reference

Today I came across this nice web page where the author has consolidated most of the basic differences (and equivalents) between these languages. The list is quite exhaustive and the side by side display style is wonderful. A real quick reference guide for learners like me.

[visit quick reference guide page]

Equivalent of short-circuiting using - AndAlso && OrELse

The equivalent operators for 'AndAlso' and 'OrElse' of VB.NET in C# are '&&' and '||' respectively.

If your question is what's new about it? Well, for me it was a news. As I always used 'And/Or' in VB and '&&' in C++ or Java, never really cared about the difference between both, as I considered them to be the same. When .NET added the power of 'Also and Else' to these operators in VB, I learnt a better way of comparing and evaluating logical conditions using 'AndAlso' and 'OrElse'. When I started with C#, and came across very first logical comparison, I smartly searched for equivalent of 'AndAlso and OrElse' in C# only to find that they are there since ever in C#. I felt dumbhead. :)

My source of knowledge for this equivalent.

Learn more about AndAlso in VB.NET
Learn more about OrElse in VB.NET

Friday, March 2, 2007

What this blog is about?

Hi,

I am a (seasonal) programmer and have been playing with Visual Basic since long. Though I have exposure to other programming languages as well, yet VB has been my all time love. Many a times I tried to explore Java, but instead of that always ended up creating some kind of Java IDE in VB. Well, that is how I learnt and explored VB.

When C#'s beta version was relased, I kind of played with that too and thanks to my C++ and little bit of Java learnings, it didn't take anytime to understand the language. Since then I 'know' C#, have been reading about it here and there, but never actually developed any application using C#.

Recently in my job, I had to start on an application that's in C# and extend it's functionality as per requirements. I thought it would be very easy, just like vb, and it wasn't tough either, but, every now and then I came across so many things for which I kept on asking - whats C# equivalent for '[something]' in VB?. Have been googling all around and got to know many things that I thought is good to make a note of in my diary forever so that it may also help in future.

This blog is my diary, with notes on C# equivalents for VB commands, which I have been looking for. May be it helps someone else too.

Happy Reading!