小编DEV*_*ner的帖子

减少if语句的数量

到目前为止我有以下程序:

using System;
namespace ParkingTicket
{
    class Program
    {
        static void Main()
        {
            int speed;
            int yrInSchool;
            double fine;
            char choice = ' ';
            do
            {
                Console.Clear();
                speed = GetSpeed();
                if (speed <= 15)
                    Console.WriteLine("No speeding fine to pay.");
                else
                {
                    yrInSchool = GetYrInSchool();
                    fine = CalculateFine(speed, yrInSchool);
                    DisplayFine(fine);
                }
                choice = GetUserChoice();
            } while (choice != 'Q' && choice != 'q');
        }
        static int GetSpeed()
        {
            int speed;
            string userInput;
            try
            {
                Console.Write("Please enter the speed you were traveling: …
Run Code Online (Sandbox Code Playgroud)

c# conditional

2
推荐指数
1
解决办法
1720
查看次数

如何正确使用if语句?

由于if声明中的第一行,我无法运行它.我确信有些东西需要转换,但我不确定是什么.

我的代码:

using System;
using System.Collections.Generic;
using System.Text;

namespace xx
{
    class Program
    {
        static void Main(string[] args)
        {

           string userInput;
            Console.Write("what number do you choose: ");
            userInput = Console.ReadLine();

            if (userInput > 100)
                Console.WriteLine("I hate myself");
            else
                Console.WriteLine("I love myself");


        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c#

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

标签 统计

c# ×2

conditional ×1