Reputation: 83
Im having problems with a menu I made for a small app I am doing for a school project.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Teste_Menu
{
class Program
{
static void Main(string[] args)
{
List<Modelo> ListaModelo = new List<Modelo>();
ListaModelo.Add(new Modelo("Honda", "Civic", 180, 29000));
ListaModelo.Add(new Modelo("Honda", "Jazz", 100, 15000));
ListaModelo.Add(new Modelo("Honda", "HRV", 115, 22500));
}
static void Menu()
{
string escolha;
do
{
Console.Clear();
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("\n");
Console.WriteLine(" ==================================================================================================== ");
Console.WriteLine(" =========================================== Cars ================================================= ");
Console.WriteLine(" ==================================================================================================== \n\n");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(" Consultar Lista de Carros -----------------------------------------------> (1)\n ");
escolha = Console.ReadLine();
switch (escolha)
{
case "1": ListaModelo();
break;
}
Console.ReadLine();
}
while (escolha != "2");
}
static void ListaModelo()
{
{
var ListaModelo = new List<int>(Enumerable.Range(0, 50));
ListaModelo.ForEach(Console.WriteLine);
}
}
}
}
When I execute it shows no Erros but doesn't give any output.What am I doing wrong here? It just shows - "Press any key to continue"
Upvotes: 0
Views: 32
Reputation: 83
static void Main(string[] args){
List<Modelo> ListaModelo = new List<Modelo>();
ListaModelo.Add(new Modelo("Honda", "Civic", 180, 29000));
ListaModelo.Add(new Modelo("Honda", "Jazz", 100, 15000));
ListaModelo.Add(new Modelo("Honda", "HRV", 115, 22500));
Menu();
}
you didn't call the menu function that's why it didn't gives any output. If still no output, try to pass your list.
Upvotes: 1
Reputation: 61369
Your Main
method simply creates a list and adds items to it; the rest of your code never runs. The end of Main
hits and the program exits (as all C# programs do when the end of Main
is reached) You need to actually invoke the Menu
method:
static void Main(string[] args)
{
...
Menu();
}
You might also consider passing in the list of cars, because its not going to be available to any other methods where you have it right now either.
Upvotes: 1