Wednesday, December 29, 2004

&& operator (C#)

Here is a post which in context to my previous post
Got this Tip from Developer Shed

This is regarding the usage of AndAlso and OrElse operators in VB.NET. These new boolean operators are introduced in VB.NET to make the compatibility of VB.NET code to C# and managed C++. This is due to the fact that && (And Operator in C#) has default behavior of AndAlso and || (OR operator in C#) has default behavior of OrElse. Here's an example:
bool Function1()
{
System.out.print("In function 1");
return false; //note this function returns false
}
bool Function2()
{
System.out.print("In function 2");
return true;
}
//so in C# && operator will not evaluate the result of Function2
public static void main (string[] args ) {
if ( Function1() && Function2() )
{
//this code never runs
System.out.print("IN the evaluation of main function");
}
}


Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?

© Copyright 2005, Rohan Thomas
Disclaimer
This Blog contains findings that are self-explored and expressions that are self-evoked. They are by no meanss representions of my employer's view.