小编Nic*_*tti的帖子

我可以在 Ruby case 语句中使用两个变量之间的比较吗?

我正在尝试这段代码,但每次都得到 nil (这是 Black Jack 游戏的简单版本):是因为我在 case 语句中比较两个变量吗?

def end_game_message(player_score, bank_score)
  message = ""
  case player_score
  when player_score == 21
    message = "Black Jack!"
  when player_score > bank_score
    message = "You win!"
  when player_score > 21
    message = "You lose!"
  when player_score < bank_score
    message = "You lose"
  when player_score == bank_score
    message = "Push"
  end
  message
end

puts end_game_message(21, 15)
Run Code Online (Sandbox Code Playgroud)

预先感谢您的任何帮助!

ruby

0
推荐指数
1
解决办法
767
查看次数

有没有办法将相同类型的参数分组,使代码整洁?

假设我有这个方法:

public void UpdateEmployee ( String empFirst, String empLast, String empAddress, 
String empType, String empPhoneNo, String empSalary, DateTime? dob, String empDepartment)

Run Code Online (Sandbox Code Playgroud)

有没有办法不在参数中一直重复 String 类型?

谢谢

c#

0
推荐指数
1
解决办法
87
查看次数

标签 统计

c# ×1

ruby ×1