.NET Questions (CLOSED)Questions and Answers on any aspect of .NET. Now closed. |
||
|
This discussion group is now closed.
Have a question about .NET development? Try stackoverflow.com, a worldwide community of great developers asking and answering questions 24 hours a day. The archives of .NET Questions contain years of Q&A. Even older .NET Questions are still online, too. |
C# Newbie here,
Given the following: if ((MyString.Length >= 3) & (MyString.Substring(0,3) == "HEL")) apps crash with an ArgumentOutOfRange exception if MyString is less than three characters long. In other languages I've used, shortcutting would evaluate the left side, determine that MyString.Length < 3, and never evaluate the right side. Is there any way to duplicate this behavior in C#?
Try...
if ((MyString.Length >= 3) && (MyString.Substring(0, 3) == "HEL"))
N Thursday, November 20, 2008
& is the bitwise and operator.
&& is the boolean and operator. They two two very different things. The second one is the one you want and shortcuts as you expect. |
|
Powered by FogBugz


