Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6862253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:38:19+00:00 2026-05-27T02:38:19+00:00

In C#, I am trying to add values to a parameter that accepts enumerated

  • 0

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.

I have the following Enum specified as Flags.

[Flags]
public enum ProtectionOptions
{
  NoPrevention = 0,
  PreventEverything = 1,
  PreventCopying = 2,
  PreventPrinting = 4,
  PrintOnlyLowResolution = 8
}

Now, I can easily use the following code to add flag values to the parameter:

myObj.Protection = ProtectionOptions.PreventEverything | ProtectionOptions.PrintOnlyLowResolution;

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:

string protectionOptionsString = "NoPrevention, PreventPrinting";
string[] protectionOptions = protectionOptionsString.Split(',');
foreach (string protectionOption in protectionOptions)
{
  myObj.Protection += (ProtectionOptions) Enum.Parse(typeof (ProtectionOptions), protectionOption.Trim());
}

Conceptually, this is what I want, but I can’t “+=” the values in the loop to the parameter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:38:21+00:00Added an answer on May 27, 2026 at 2:38 am

    You don’t need to split. Enum.Parse is capable of parsing multiple values if you use the [Flags] attribute on the enum definition, which you did. Just parse and use the |= operator to "add" the flags.

    string protectionOptionsString = "NoPrevention, PreventPrinting";
    myObj.Protection |= (ProtectionOptions)Enum.Parse(typeof(ProtectionOptions), protectionOptionsString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to add an onclick handler to my tabs, and can't seem to get
I'm trying add a tab to my web page that looks like this: Using
trying to add an ExpiresDefault ExpiresByType to content on my website so that way
I'm trying to make a registration page but PHP is telling me that I
I'm trying to learn object relational mapping and made my own method that accepts
I am trying to add value to CoreData from .plist and get from coreData
I'm trying to add a value to the header for a URL request. Something
I am trying to add a key value pair and having trouble adding the
I'm trying to add some additional key/value pairs to an NSMutableDictionary, using: Tag *tag1
I'm trying to add an extra class tag if an element / value is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.