By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,109 Members | 1,007 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,109 IT Pros & Developers. It's quick & easy.

What does | operator stand for Enum

100+
P: 375
Hi,
I have the following example
Expand|Select|Wrap|Line Numbers
  1. enum MaterialColors
  2.     {
  3.         Blue=1,Red=2,Yellow=4, Purple=Blue|Red,Green=Yellow|Blue,Orange=Red|Yellow,
  4.     }
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int j = (int)MaterialColors.Orange;
  10.             Console.WriteLine(j.ToString());
  11.             Console.Read();
  12.         }
  13.     }
Here what does the operator "|" stand for.
The answer is 6, but what does the "|" operator actually do.
Feb 16 '09 #1
Share this Question
Share on Google+
5 Replies


vekipeki
Expert 100+
P: 229

100+
P: 375
Oh so u mean its similar to "<<" and ">>" operator.
shift left wise and rightwise

many thanks vekipeki
Feb 16 '09 #3

100+
P: 375
But if I replace it with & operator, I get the answer as 0, I dont think its logical operator then.
Feb 16 '09 #4

vekipeki
Expert 100+
P: 229
Be sure to read this: http://en.wikipedia.org/wiki/Bitwise_operation, and compare bitwise OR to bitwise AND. Try writing your numbers (1, 2 and 4) in binary form (0001, 0010 and 0100), and then compare with the examples the article above.

Note that there is a difference between logical and bitwise operators: http://msdn.microsoft.com/en-us/libr...5d(VS.80).aspx.
Feb 16 '09 #5

100+
P: 375
thanks vekipeki. Should have replied long back. Thanks for reminding me the basics.
Feb 17 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.