Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert short to VariantType (extract VariantType from short)

Tags:

c#

.net

vb.net

I need convert short to VariantType

My try (works not correct)

VariantType vt = (VariantType)vt;

So how can I convert short to VariantType?

(vb.net tag because VariantType is from Microsoft.VisualBasic)

like image 277
cnd Avatar asked Oct 21 '22 03:10

cnd


1 Answers

Your code should be fine:

The following works perfectly:

short num = 4;
VariantType  vt = (VariantType)num;
Console.WriteLine(vt);

And outputs "Single". This means that whatever problem you are having is not with the rough line of code you are using.

That having been said the actual line you are using (ie VariantType vt = (VariantType)vt; is not going to work because the vt on the right hand side of the equation is invalid since it is unassigned (since you haven't finished declaring it). You should get a "Use of unassigned local vairable 'vt'" when you attempt to compile that.

I'm assuming that the line is a mistake but if not you should explain what you are actually trying to do with that line.

like image 63
Chris Avatar answered Oct 23 '22 18:10

Chris