- Home /
How to Convert System.Object into int ?
I want to convert Object into int.
Object foo = 100;
int bar = Int32.Parse(foo);
'>>InvalidCastException: Cannot cast from source type to destination type.
How should I do?
Thank you.
Perhaps a better question is: why do you need to? A question like this suggests to me that there is an underlying problem with the architecture.
Answer by fafase · Jul 16, 2014 at 12:44 PM
Object foo = 100;
this is not possible, Object is Unity.Object, try to use object instead which is the mother class of all:
object foo = 100;
int bar = (int)foo;
I wanna use JavaScript. In JavaScript, I got this error.
var foo :object = 100;
'>> The name 'object' does not denote a valid type ('not found').
Well, I do not see any way for this to be possible in Us. You cannot explicitely cast and using as keyword is only for reference type.
There might be some ways I do not know about since I do not use Us. But this kinda tells me using C# is the right choice in the long run.
in unity script it appears the syntactic sugar for object(the sugar is referenced as System.Object in c#) is missing, so you will need to fully qualify with namespace and no sugar baby! You also don't want a conflict with UnityEngine.Object which would be the type selected if you use Object.
Example of usage:
var b : System.Object = 1000;
Then, How can I convert System.Object into int in unity script?
Your answer
Follow this Question
Related Questions
converting NavMesh to normal mesh? 0 Answers
RGB Colors as Float Values Converter 0 Answers
can i convert c sharp to javascript 2 Answers
need help converting JS to C 2 Answers
Help with converting JS to c# 1 Answer