📜  连续数字 c# 代码示例

📅  最后修改于: 2022-03-11 14:48:43.578000             🧑  作者: Mango

代码示例1
namespace ConsoleApp7
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter numbers separate by hypen : ");
            var name = Console.ReadLine();
            var numarray = name.Split('-');
            for (var i = 0;i<=numarray.Length-1;i++ )
            {
                if (i>1 && (Convert.ToInt32(numarray[i]) != Convert.ToInt32(numarray[i - 1])+1))
                {
                    Console.WriteLine("Not Consecutive");
                    break;
                }
                if (i == numarray.Length-1)
                {
                    Console.WriteLine("Consecutive");
                }

            }
        }
    }
}