A function to return a sign

前端 未结 8 1391
春和景丽
春和景丽 2021-01-17 08:40

I know this will really turn out to be simple, but my brain is just not working. I need a function in C# that will return -1 if the integer passed to the function has a nega

8条回答
  •  半阙折子戏
    2021-01-17 08:53

    public int SignFunction(int number) {
      return (number > 0) ? 
                 1 : (number < 0) ? 
                        -1 : number;
    }
    

提交回复
热议问题