comparing two enums variables from two different enum classes.

i have two enum clasess
   NoAccess = 0,
   ReadOnly = 1,
   ViewAll = 2,

  InboxAccess =0,

Now i am trying to comapre is like
if (enum2.InboxAccess == enum1.NoAccess)

But this code is throwing an error
Operator '==' cannot be applied to operands of type 'System.Enum' and enum1.NoAccess
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dirk HaestProject managerCommented:
Can you try this:

if ((int)enum2.InboxAccess == (int)enum1.NoAccess)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
First, as the name suggests ENUMS are not classes, they are enumerations.
They are words, which can also be accesed sequentially by ints an Dhaest suggests, that makes programming more linguistical and undestandable. It really makes no much sense comparing to enums for equality as semanticaly they probably mean things completely different. But if you would like to do so, casting as is above suggested should do the deal.
It is not at all possible to compate two different Enums and you should never do with integer comparison.then will always true for following,

   InboxAccess= NoAccess  =0
   OfferAccess = ReadOnly  =1
   OrderAccess =    ViewAll = 2

so, it will change the indent of enumaration. you should do it like
create variables for enum1 and compare . no need of enum2.

 enum1  InboxAccess =enum1.ViewAll   ;
 //enum variable always intialized with first value automatically.change if needed
 enum1   OfferAccess ;
 enum1   OrderAccess;

//let user to assign the rights from UI/Data base...


if (InboxAccess =enum1.ViewAll ) {//code to veiwall rights}
else if (InboxAccess =enum1.ReadOnly  ) {//code to ReadOnly  rights}
else (InboxAccess =enum1.NoAccess  ) {//code to restrict rights}

do the same for OfferAccess and OrderAccess.use switch-case for better readablity
What you are trying to do is very bad code style.
First, code you are writing makes no sense. What you are trying to compare? Enum is a list of names (you never should take care of underlying value). Underlying int value could be changed over time (e.g. someone decide to order names alphabetically).

If you have two objects - one of type Enum1 and other of type Enum2 (also very bad naming - consider names like AccessType), and you want two conditions at same time, you should do following:
if ( (e1 == Enum1.NoAccess) && (e2 == Enum2.InboxAccess))
pankajsinghpolarisAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.