title: Checking FileAttributes enumeration
body: <p>New to C# and I don't really understand how the below code is determining if the file is read-only or not.  In particular, how does the (attributes &amp; FileAttributes.ReadOnly) evaluate to something that does or doesn't == FileAttributes.ReadOnly.</p>
  
  <p>I'm guessing the &amp; is doing some sort of bitwise AND??  I just don't follow how this works.  Can anyone provide an explanation?</p>
  
  <pre><code>using System;
  using System.IO;
  
  namespace ConsoleApplication
  {
      class Program
      {
          static void Main(string[] args)
          {
              FileAttributes attributes = File.GetAttributes("c:/Temp/testfile.txt");
              if ((attributes &amp; FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
              {
                  Console.WriteLine("read-only file");
              }
              else
              {
                  Console.WriteLine("not read-only file");
              }
          }
      }
  }
  </code></pre>