Reputation: 92
I am a programming beginner and I have a code snippet like below
public class MainActivity : Activity, Android.Hardware.ISensorEventListener
{
private SensorManager _senMan;
float lightSensorValue;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SetContentView (Resource.Layout.Main);
Button button = FindViewById<Button> (Resource.Id.myButton);
_senMan = (SensorManager)GetSystemService (Context.SensorService);
Sensor sen = _senMan.GetDefaultSensor (SensorType.Light);
_senMan.RegisterListener (this, sen, Android.Hardware.SensorDelay.Game);
How do I call _senMan
is it an object or a type or any other. My another question is what are the tasks that are happening in senMan = (SensorManager)GetSystemService (Context.SensorService);
and Sensor sen = _senMan.GetDefaultSensor (SensorType.Light);
How do we call them in a professional way.
Upvotes: 0
Views: 91
Reputation: 172380
_senMan
is a variable of type SensorManager
.
_senMan = (SensorManager)GetSystemService (Context.SensorService);
is an invocation of method GetSystemService
, passing the value of Context.SensorService
as a parameter. The result of the method invocation is cast to type SensorManager
.
After executing this line of code, variable _senMan
references an object of type SensorManager
.
Sensor sen = _senMan.GetDefaultSensor (SensorType.Light);
is a short hand for
Sensor sen;
sen = _senMan.GetDefaultSensor (SensorType.Light);
The first is a variable declaration, the second an invocation of the GetDefaultSensor
method of the object referenced by variable _senMan.
Upvotes: 1