I want to make a program that asks for 3 numbers and returns the largest and smallest. I want to do it with arrays and a for to save conditionals but it tells me that the numbers variable has not been assigned.
using System;
using System.ComponentModel;
namespace TresNombres
{
class Program
{
static void Main(string[] args)
{
int[] numbers;
Console.WriteLine("Insert first number: ");
numbers[0] = (Console.ReadLine());
Console.WriteLine("Insert second number: ");
numbers[1] = int.Parse(Console.ReadLine());
Console.WriteLine("Insert third number: ");
numbers[2] = int.Parse(Console.ReadLine());
}
}
}
You can use Linq to use its methods and know what is the largest and smallest number.
Both options are valid, as one of them says, you have to initialize the array for example
int[] numbers = new int[3]; //3 es el tamaño del arreglo que puedes
to choose.