using System;
public class Program
{
public class BigBumbo
public float SensX{ get; private set; }
public void setSensX(float value)
if (value > 0) //As long as the value supplied is greater than 0
SensX = value; //Set the variable to the value
}
else //Otherwise set the value to 1?
SensX = 1; //But is there a way to just reject the value? Only way I can think of is using a boolean to return true if the value is accepted, false otherwise?
public static void Main()
BigBumbo idiothead = new BigBumbo();
BigBumbo dumbowumbo = new BigBumbo();
idiothead.setSensX(5);
Console.WriteLine("The value of idiot head's sensx after attempting to set it to 5 is: " + idiothead.SensX.ToString());
dumbowumbo.setSensX(-1);
Console.WriteLine("The value of dumbowumbo's sensx after attempting to set it to -1 is: " + dumbowumbo.SensX.ToString());
/*
So there you go. The setter will automatically set the variable to 1 if the value supplied is less than 0, but I don't want that.
I just want it to where it REJECTS the value - not sets it regardless.
What would be proper OOP etiquette here? Is the answer to make setSensX a Boolean which returns true if the value is set (its above 0),
and false if it's below 0, and then when I call the method, check whether or not it returned true or false, and tell the user
accordingly?
*/