C# C私有布尔方法

C# C私有布尔方法,c#,boolean,C#,Boolean,我需要帮助添加一个返回整型布尔值的私有方法。 如果参数小于50,则应返回值false,否则返回 我目前正在试验c语言,使用了if-else语句,但需要使用get、set private static bool AmHungry if size < 50; { return false; } else { return true; } 我尝试过使用get set访问器,但如何定义需要满足的值来决定布尔答案?要定义任何值,需要将其保存到另一个变量中。为了使用它,您可以调用该变

我需要帮助添加一个返回整型布尔值的私有方法。 如果参数小于50,则应返回值false,否则返回

我目前正在试验c语言,使用了if-else语句,但需要使用get、set

private static bool AmHungry
if size < 50;
{
    return false;
}
else
{
    return true;
}

我尝试过使用get set访问器,但如何定义需要满足的值来决定布尔答案?

要定义任何值,需要将其保存到另一个变量中。为了使用它,您可以调用该变量

public static int HungerThreshold { get; set; }    // Using this creates anthe imlicit field and simple access at compile time
publis static bool AmHungry
{
    get { return size < HungerThreshold; } // Forget not that compaison operators return bool, and can thus be returned directly instead of using an if/else
}
也不要忘记方法总是需要和{},属性总是需要{}