- Home /
Can't figure out where to put 'new' when using c#
Hello, I'm trying to use c#, but the following line
float x = ((SpriteRenderer)holeObject.GetComponent(SpriteRenderer)).sprite.bounds.size.x;
generates the error
error CS0119: Expression denotes a
type', where a
variable',value' or
method group' was expected
I have read that in c# you need to use the 'new' statement, but I cant figure out where, or why the error is occouring.
Thank you.
Answer by Landern · May 29, 2014 at 04:16 PM
use typeof:
float x = ((SpriteRenderer)holeObject.GetComponent(typeof(SpriteRenderer))).sprite.bounds.size.x;
or generics:
float x = ((SpriteRenderer)holeObject.GetComponent<SpriteRenderer>()).sprite.bounds.size.x;
Thank you very much! Do you know why the error occurred?
Your answer
![](https://koobas.hobune.stream/wayback/20220613150201im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
C# variable Error Message CS0219 variable not assigned 2 Answers
Calling a variable in C#? 1 Answer
Powerup only spawning twice (MissingReferenceException Error) 2 Answers