Visual C++ .NET/Language Basics/Bitwise Operator

Материал из .Net Framework эксперт
Версия от 15:06, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

The bitwise or operator (|) combines the flag values

<source lang="csharp">

  1. include "stdafx.h"

using namespace System; [ Flags ] enum class FontFormat {

   None = 0, 
   BOLD = 1,  
   ITALIC = 2,  // in binary, each represents one bit position
   UNDERLINE = 4,
   STRIKETHROUGH = 8,
   RED = 16,
   FLASHING = 32,
   BOLD_ITALIC = BOLD | ITALIC  // combination of two values

}; ref class Font {

  public:
     property String^ Name;
     Font(String^ s) { Name = s; }

};

static void SetFont(Font^ font, FontFormat format) {

       if (safe_cast<int>(format) & safe_cast<int>(FontFormat::BOLD))
       {
       }
       if (safe_cast<int>(format) & safe_cast<int>(FontFormat::ITALIC))
       {
       }

}; int main() {

  SetFont(gcnew Font("Times New Roman"),FontFormat::BOLD | FontFormat::RED );

}

 </source>