Make a function that takes 2 integer and lists out all the numbers from the 1st number until the 2nd number
using System;
namespace ConsoleApp1
{
class Program
{
public static void List(int x, int y)
{
Console.WriteLine("List:");
for (int i = x; i <= y; i++)
{
Console.WriteLine(i);
}
}
static void Main(string[] args)
{
int x, y;
Console.Write("Enter X: ");
string str = Console.ReadLine();
if (!int.TryParse(str, out x))
Console.WriteLine("Bad number.");
Console.Write("Enter Y: ");
str = Console.ReadLine();
if (!int.TryParse(str, out y))
Console.WriteLine("Bad number.");
List(x, y);
}
}
}
Comments
Leave a comment