bitwise [OR]

  • Thread starter Thread starter David
  • Start date Start date
D

David

hi, I have a question.
I have a method written by ASP, and I need to convert to c# asp.net:

[ASP]
call method1 ( 32 or 2 )

this method's parameter is using the bitwise Or operator.
but when I convert to c#:
[c#]
method1 ( 32 | 2 );

I got this error msg after compelie:
Cannot covert 'int' to 'SdfComponentToolkit.SdfOpenFlags'

SdfComponentToolkit is a Map tools, made by Autodesk.

Thanks, David.
 
Hi David,

Your method is expecting a parameter of type
'SdfComponentToolkit.SdfOpenFlags' and not an int.
VB does conversion automatically unless otherwise requested in Option Strict
thing while C# is always strict on casts.
So, you have two options: either cast result to
'SdfComponentToolkit.SdfOpenFlags' like
method1((SdfComponentToolkit.SdfOpenFlags)(32 | 2))
or use flags directly (which is a way beter and more readable route)
method1 (someFlag | otherFlag)

However, why are you calling something with fixed value "32 or 2" is
puzzling me. Why don't you just pass a correct flag?
 
David said:
hi, I have a question.
I have a method written by ASP, and I need to convert to c# asp.net:

[ASP]
call method1 ( 32 or 2 )

this method's parameter is using the bitwise Or operator.
but when I convert to c#:
[c#]
method1 ( 32 | 2 );

I got this error msg after compelie:
Cannot covert 'int' to 'SdfComponentToolkit.SdfOpenFlags'

SdfComponentToolkit is a Map tools, made by Autodesk.

Thanks, David.

Cast the bitwise or'd value to an SdfOpenFlags enum value (which is what the
method requires by the sound of it). ASP was doing the type conversion
sliently behind the scenes.

method1 ( (SdfOpenFlags )(32 | 2) );

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top