检查用户输入是否=已定义的字符串

时间:2016-06-11 12:20:35

标签: c# login

我正在创建登录终端并且我有一个登录字符串,所以我想检查用户是否正确打印字符串的名称,执行以下操作,以下是代码:

Console.WriteLine("--------------------");
Console.WriteLine("---LOGIN TERMINAL---");
Console.WriteLine("--------------------");
System.Threading.Thread.Sleep(1000);
Console.WriteLine("/Log In");
Console.WriteLine("/Create New User");
Console.WriteLine("/Delete User");

userInput = Convert.ToString(Console.ReadLine());
if(userInput = LogIn)
{

}

2 个答案:

答案 0 :(得分:0)

= operator是一个赋值运算符。您需要使用== operator这是相等运算符。

if(userInput == LogIn)
{

}

如果此LogIn不是变量,而是string,则需要使用双引号,例如;

if(userInput == "LogIn")
{

}

答案 1 :(得分:0)

这应该有所帮助:

# The following 6 lines aren't needed for your solution, but if you wanted to take advantage of 'warning', 'danger', and 'ok' status classes (changes background color and flashes), just feed your send_event with 'status: [one of the three status names] 
  if data.status
    # clear existing "status-*" classes
      $(@get('node')).attr 'class', (i,c) ->
        c.replace /\bstatus-\S+/g, ''
      # add new class
      $(@get('node')).addClass "status-#{data.status}"

  @accessor 'difference', ->
    if @get('last')
      last = parseInt(@get('last'))
      current = parseInt(@get('current'))
      if last != 0
        diff = Math.abs(Math.round((current - last) / last * 100))
        "#{diff}%"
    else
      ""
  # Picks the direction of the arrow based on whether the current value is higher or lower than the last
  @accessor 'arrow', ->
    if @get('last')
      if parseInt(@get('current')) > parseInt(@get('last')) then 'icon-arrow-up' else 'icon-arrow-down'