passing enum value as an argument

J

Jon Skeet [C# MVP]

Madestro said:
Understandable. I should not expect you to remember and be more clear on my
answers.

It's not a case of not remembering, so much as you did nothing to
indicate that you intended any other posts to assume that Option Strict
would be off in any code you referred to.
Actually you would have to declare the SAME type for each constant, and
indeed you would have an Enum, and you WOULD have to use the same type on the
function that receives them so you really DON'T loose type safety.

In that case, you just didn't explain yourself clearly in the first
place. I thought you meant getting rid of the enum entirely and *just*
having three variables, eg of type Int32.

If you're just suggesting creating three variables of the same type as
the enum but within the class which wishes to use them, that would
indeed still be type safe - but much less convenient than the compiler
inferring it for you.
You could not be more right. I actually missread the documentation. The
limit is in the value size. For example, if you have an Enum defined as
integer, then you could still use other values so long as they are within the
range of an integer.
Totally my fault, I take it back.
Goodo.


The compiler may infer the type, but not the value. The value has to be
resolved by a fully qualified name. The compiler cannot possibly resolve that.

Yes it can - by seeing what type is expected! What is to stop the
compiler from seeing that the expected type for a parameter, or
assignment, or whatever, is the enum, and looking up the expression as
a member of the enum?

It certainly wouldn't be unambiguous all the time, but it doesn't need
to be.

In C# it would present some interesting "purity" discussions in the
same way that people sometimes propose overloading by return type - I
don't know if the same would be true in VB.NET. However, whether it's
"pure" or not doesn't affect whether it's *possible*.
I am not sure what code you refer to.

The code you took back, which you said would fail due to the range of
the enum.
I turned Option Strict OFF to test this, which is why the function had no
return type.
JuanEnum is just a typo when copying back to here. I don't copy and paste.

Why don't you copy and paste? It makes life much easier for people who
want to try your code, because it means they can try the *actual* code
that you wrote.
Yes, the code will not fail. This relates to my first answer in this posting.

Indeed.
 

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

Top