小编Zan*_*ane的帖子

无法理解代码段

我正在做一些基本的C#练习来学习C#.网站也提供了问题的解决方案,但我无法理解代码.

问题:编写一个C#程序来检查整数是否在100或200之间.

示例输出: 输入一个25 False的整数

方案:

public class Exercise22
{
    static void Main(string[] args)
    {
        Console.WriteLine("\nInput an integer:");
        int x = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine(result(x));
    }
    public static bool result(int n) 
    { 
        //Can't understand the code below - 
        //why is the "<=10" and "return false" used 

        if (Math.Abs(n - 100) <= 10 || Math.Abs(n - 200) <= 10)
            return true;
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

c#

-4
推荐指数
1
解决办法
77
查看次数

标签 统计

c# ×1