432,109 Members | 1,007 Online
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 enum MaterialColors     {         Blue=1,Red=2,Yellow=4, Purple=Blue|Red,Green=Yellow|Blue,Orange=Red|Yellow,     }     class Program     {         static void Main(string[] args)         {             int j = (int)MaterialColors.Orange;             Console.WriteLine(j.ToString());             Console.Read();         }     } Here what does the operator "|" stand for. The answer is 6, but what does the "|" operator actually do. Feb 16 '09 #1
5 Replies

 Expert 100+ P: 229 It's a bitwise OR operator: http://msdn.microsoft.com/en-us/libr...kx(VS.80).aspx Check this also: http://en.wikipedia.org/wiki/Bitwise_operation. Feb 16 '09 #2

 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

 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