Question Details

No question body available.

Tags

c# templates console-application

Answers (4)

May 20, 2026 Score: 0 Rep: 1 Quality: Low Completeness: 60%

The easiest way to handle this is by keeping your data models in a separate class and using a simple while loop for your menu navigation in the main program.

Here is a complete starter template using a simple "Car Application" to show you how to structure the core logic, separate the classes, and build a basic menu loop:

1. The Data Model (Car.cs) Keep this strictly for data and parsing.

using System;
using System.Collections.Generic;
using System.IO;

namespace CarApp { internal class Car { public int Id; public string Brand; public string Model; public int ManufactureYear; public string Color; public int SoldUnits; public int AverageSold;

public int Id1 { get => Id; set => Id = value; } public string Brand1 { get => Brand; set => Brand = value; } public string Model1 { get => Model; set => Model = value; } public int ManufactureYear1 { get => ManufactureYear; set => ManufactureYear = value; } public string Color1 { get => Color; set => Color = value; } public int SoldUnits1 { get => SoldUnits; set => SoldUnits = value; } public int AverageSold1 { get => AverageSold; set => AverageSold = value; }

public Car(int id, string brand, string model, int manufactureYear, string color, int soldUnits, int averageSold) { Id1 = id; Brand1 = brand; Model1 = model; ManufactureYear1 = manufactureYear; Color1 = color; SoldUnits1 = soldUnits; AverageSold1 = averageSold; }

public Car(string line) { string[] data = line.Split(';'); Id1 = int.Parse(data[0]); Brand1 = data[1]; Model1 = data[2]; ManufactureYear1 = int.Parse(data[3]); Color1 = data[4]; SoldUnits1 = int.Parse(data[5]); AverageSold1 = int.Parse(data[5]); }

public static List ReadFromFile(string fileName) { List carList = new List(); string[] lines = File.ReadAllLines(fileName);

for (int i = 1; i < lines.Length; i++) { Car c = new Car(lines[i]); carList.Add(c); } return carList; } } }
May 20, 2026 Score: 0 Rep: 1 Quality: Low Completeness: 60%

2. Main Program & Menu Loop (Program.cs) This handles the logic and the console UI.

using System;
using System.Collections.Generic;
using System.Linq;

namespace CarApp { internal class Program { static void Main(string[] args) { List cars = Car.ReadFromFile("autok.csv"); Console.WriteLine($"Task 5: {cars.Count} cars found in the list");

double totalSales = 0; foreach (Car car in cars) { totalSales += car.SoldUnits1; } double averageSales = totalSales / cars.Count; Console.WriteLine($"Task 6: The average number of sold cars is: {averageSales:F2} ");

Console.WriteLine("Task 7: Cars manufactured in the last 5 years (2019 or later):"); foreach (Car car in cars) { if (car.ManufactureYear1 >= 2019) { Console.WriteLine($"\t- {car.Brand1} {car.Model1}: {car.ManufactureYear1}"); } }

Console.WriteLine($"Task 8: List of most successful brands based on sold units:"); foreach (Car car in cars.OrderByDescending(c => c.SoldUnits)) { Console.WriteLine($"\t-{car.Model1}: {car.SoldUnits1}"); }

// MAIN LOOP & MENU NAVIGATION bool isRunning = true; while (isRunning) { Console.WriteLine("\n--- Main Menu ---"); Console.WriteLine("1. Search for a car model"); Console.WriteLine("2. Exit"); Console.Write("Choose an option: ");

string menuChoice = Console.ReadLine();

if (menuChoice == "1") { Console.Write("Please enter a car model: "); string input = Console.ReadLine(); bool isModelFound = false;

foreach (Car car in cars) { if (car.Model1 == input) { isModelFound = true; break; } }

if (isModelFound) { Console.WriteLine("The requested model is found in the list!"); } else { Console.WriteLine("The requested model is not found."); } } else if (menuChoice == "2") { isRunning = false; } else { Console.WriteLine("Invalid option."); } } } } }
May 20, 2026 Score: 0 Rep: 16,535 Quality: Low Completeness: 30%

I read that as a TUI (Text-based User Interface) Application. There is a subtle difference between CLI and TUI. Anyway, in either case:

Apart from trying and failing as much as you can, I'd also recommend to at some time in, have a look into Spectre Console.

May 20, 2026 Score: 0 Rep: 16,535 Quality: Low Completeness: 0%

Why those properties? It doesn't make sense.