title: Append Enum Flags to a Parameter in a Loop (Bitwise Appending)
body: <p>In C#, I am trying to "add" values to a parameter that accepts enumerated flags.  I can do it on one line with a bitwise operator "|", but I can't seem append to the parameter in a loop.</p>
  
  <p>I have the following Enum specified as Flags.</p>
  
  <pre><code>[Flags]
  public enum ProtectionOptions
  {
    NoPrevention = 0,
    PreventEverything = 1,
    PreventCopying = 2,
    PreventPrinting = 4,
    PrintOnlyLowResolution = 8
  }
  </code></pre>
  
  <p>Now, I can easily use the following code to add flag values to the parameter:</p>
  
  <pre><code>myObj.Protection = ProtectionOptions.PreventEverything | ProtectionOptions.PrintOnlyLowResolution;
  </code></pre>
  
  <p>But, what I want to do, is to get a list of protection options from a CSV string (from the Web.Config), loop through them and add them to my myObj.ProtectionOptions property.  I don't know how to do this in a loop without using the bitwise OR "|" operator.  Here is what I am wanting to do:</p>
  
  <pre><code>string protectionOptionsString = "NoPrevention, PreventPrinting";
  string[] protectionOptions = protectionOptionsString.Split(',');
  foreach (string protectionOption in protectionOptions)
  {
    myObj.Protection += (ProtectionOptions) Enum.Parse(typeof (ProtectionOptions), protectionOption.Trim());
  }
  </code></pre>
  
  <p>Conceptually, this is what I want, but I can't "+=" the values in the loop to the parameter.</p>