Click here to Skip to main content
15,917,481 members
Home / Discussions / C#
   

C#

 
GeneralRe: Activating a child form Pin
electriac5-Dec-09 4:56
electriac5-Dec-09 4:56 
Questionget all from keyboard Pin
sasabunetic4-Dec-09 12:12
sasabunetic4-Dec-09 12:12 
AnswerRe: get all from keyboard Pin
Ravi Bhavnani4-Dec-09 12:54
professionalRavi Bhavnani4-Dec-09 12:54 
AnswerRe: get all from keyboard Pin
Luc Pattyn4-Dec-09 13:28
sitebuilderLuc Pattyn4-Dec-09 13:28 
AnswerRe: get all from keyboard Pin
Dave Kreskowiak4-Dec-09 17:03
mveDave Kreskowiak4-Dec-09 17:03 
Questiondatagridview Pin
farokhian4-Dec-09 11:04
farokhian4-Dec-09 11:04 
AnswerRe: datagridview Pin
Abhishek Sur4-Dec-09 12:00
professionalAbhishek Sur4-Dec-09 12:00 
GeneralDid you know that '&' can be a logical AND operator? [modified] Pin
Rajasekharan Vengalil4-Dec-09 9:16
Rajasekharan Vengalil4-Dec-09 9:16 
I almost lost some money today on a bet with a colleague arguing that the following Java code was just plain invalid.
if( this_thing == DING & that_thing == DONG ) {
   thenGoDoTheOtherThing();
}
Fortunately, he did not take me up on the bet! Turns out, for both Java and C#, when the & operator is used in this context the compiler stops treating it as the bitwise AND operator. Instead it treats it like the logical AND operator (&&) except that it applies a slightly modified evaluation rule - where && stops evaluation as soon as it encounters the first expression that evaluates to false, & goes ahead and evaluates all the expressions regardless of what each component expression evaluates to. The logical AND still works as one might expect, just that all the component expressions are always evaluated. Here's an example:
class Program
{
    static void Main(string[] args)
    {
        if (Eval1() & Eval2())
            Console.WriteLine("Eval1() and Eval2() returned true.");
        else
            Console.WriteLine("Eval1() and/or Eval2() returned false.");
    }

    static bool Eval1()
    {
        Console.WriteLine("Eval1");
        return false;
    }

    static bool Eval2()
    {
        Console.WriteLine("Eval2");
        return true;
    }
}
And here's the output you get.
Eval1
Eval2
Eval1() and/or Eval2() returned false.
Guess you learn something new everyday! I am not sure that using this feature is such a great idea though. Thoughts?


modified on Friday, December 4, 2009 3:31 PM

GeneralRe: Did you know that '&' can be a logical AND operator? Pin
harold aptroot4-Dec-09 9:28
harold aptroot4-Dec-09 9:28 
GeneralRe: Did you know that '&' can be a logical AND operator? Pin
Rajasekharan Vengalil4-Dec-09 10:20
Rajasekharan Vengalil4-Dec-09 10:20 
GeneralRe: Did you know that '&' can be a logical AND operator? Pin
OriginalGriff4-Dec-09 9:29
mveOriginalGriff4-Dec-09 9:29 
GeneralRe: Did you know that '&' can be a logical AND operator? Pin
Rajasekharan Vengalil4-Dec-09 10:17
Rajasekharan Vengalil4-Dec-09 10:17 
GeneralRe: Did you know that '&' can be a logical AND operator? Pin
Luc Pattyn4-Dec-09 10:16
sitebuilderLuc Pattyn4-Dec-09 10:16 
GeneralRe: Did you know that '&' can be a logical AND operator? Pin
harold aptroot4-Dec-09 11:06
harold aptroot4-Dec-09 11:06 
GeneralRe: Did you know that '&' can be a logical AND operator? Pin
Luc Pattyn4-Dec-09 11:12
sitebuilderLuc Pattyn4-Dec-09 11:12 
GeneralRe: Did you know that '&' can be a logical AND operator? Pin
harold aptroot4-Dec-09 11:14
harold aptroot4-Dec-09 11:14 
GeneralRe: Did you know that '&' can be a logical AND operator? Pin
Luc Pattyn4-Dec-09 11:16
sitebuilderLuc Pattyn4-Dec-09 11:16 
GeneralRe: Did you know that '&' can be a logical AND operator? Pin
Abhinav S4-Dec-09 21:58
Abhinav S4-Dec-09 21:58 
QuestionVisual Studio addin - code color Pin
LimitedAtonement4-Dec-09 8:33
LimitedAtonement4-Dec-09 8:33 
AnswerRe: Visual Studio addin - code color Pin
LimitedAtonement4-Dec-09 9:04
LimitedAtonement4-Dec-09 9:04 
QuestionHow to make MouseHover and Tab selected on a tab control with images only Pin
sushantkaura4-Dec-09 8:27
sushantkaura4-Dec-09 8:27 
QuestionWinForms - DataGridView AutoResizeColumns not working. Pin
Sir Dot Net4-Dec-09 6:20
Sir Dot Net4-Dec-09 6:20 
QuestionHow to combine two datatables into single datatable Pin
K V Sekhar4-Dec-09 6:10
K V Sekhar4-Dec-09 6:10 
AnswerRe: How to combine two datatables into single datatable Pin
PIEBALDconsult4-Dec-09 6:54
mvePIEBALDconsult4-Dec-09 6:54 
AnswerRe: How to combine two datatables into single datatable Pin
Shameel4-Dec-09 7:01
professionalShameel4-Dec-09 7:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.