Visual C++ .NET/Data Type/boolean

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Boolean Fundamental Type in Action

 
#include "stdafx.h"
using namespace System;

void main()
{
    bool a = 18757;   // will give a warning but set to true
    bool b = 0;       // false
    bool c = true;    // obviously true
    bool d = false;   // obviously false
    Console::WriteLine( a );
    Console::WriteLine( b );
    Console::WriteLine( c );
    Console::WriteLine( d );
}


Boolean Literal and casting

 
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
Int32 main(void)
{
    Boolean a = 18757;   // will give a warning but set to true
    Boolean b = 0;       // false
    Boolean c = true;    
    Boolean d = false;  
    Console::WriteLine( a );
    Console::WriteLine( b );
    Console::WriteLine( c );
    Console::WriteLine( d );
    return 0;
}


Boolean Literal and toString

 
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
Int32 main(void)
{
    // This is kind of neat. Boolean literals are objects too!
    Console::WriteLine ( true.ToString () );
    Console::WriteLine ( false.ToString () );
    return 0;
}


Boolean literals are objects too

 
#include "stdafx.h"
using namespace System;
void main()
{
    Console::WriteLine ( true.ToString () );
    Console::WriteLine ( false.ToString () );
}


Boolean Literals in Action

 
#include "stdafx.h"
using namespace System;
void main()
{
    bool isTrue = true;
    bool isFalse = false;
    Console::WriteLine ( isTrue );
    Console::WriteLine ( isFalse );

}