C# 如何获得用户的输入并提供反馈

C# 如何获得用户的输入并提供反馈,c#,input,output,console-application,C#,Input,Output,Console Application,我是一名编码新手——刚刚起步。构建是成功的,但我想添加输入-输出以获得消费者响应,以检查它是否确实有效。多谢各位 using System; namespace LeapYear { public static class Leap { static void Main(string[] args) { Console.WriteLine("Enter a year "); Console.Rea

我是一名编码新手——刚刚起步。构建是成功的,但我想添加输入-输出以获得消费者响应,以检查它是否确实有效。多谢各位

using System;

namespace LeapYear
{
    public static class Leap
    {
        static void Main(string[] args)

        {
            Console.WriteLine("Enter a year ");
            Console.ReadLine();
        }

        public static bool IsLeapYear(int year)
            { 

            if (year % 4 == 0 && year % 100 != 0 || year % 400 ==0)

            {
                return true;
            }

            return false;
        }

    }
}
给你:

using System;

public class Program
{
    public static void Main()
    {
        Console.WriteLine("Enter a year ");

        //Console.ReadLine returns the entered data as a string
        var yearString = Console.ReadLine();

        //Convert the string to an int
        int year = Int32.Parse(yearString);

        //Now we can call your function, passing the year variable and recording the bool value passed back
        var isLeapYearAnswer = IsLeapYear(year);

        //Print the answer to the console
        Console.WriteLine(isLeapYearAnswer);
    }

    public static bool IsLeapYear(int year)
    { 
        if (year % 4 == 0 && year % 100 != 0 || year % 400 ==0)
            {
                return true;
            }
        else
        {
            return false;
        }
    }
}

这里有一个

副本供参考:Dotnet framework已经有了一个ISLEAppear的方法