I'm starting out with C# (two weeks in) and I'm trying to display a variable based on user input via Console.Readline(); method. This basic app is a calculator with two steps: Step 1 is a simple calculator; Step 2 should display material information (the name and price of the material).
The issue I'm having is in step 2 of my app, where I want to display the name and price of a material based on the user input. I'm not sure if LINQ is the best, easiest method for this. So open to how to solve this so it's readable by others and makes the program work.
Program CS. file is as follows:
using System;
namespace Gutterjob
{
class Program
{
static void Main(String[] args)
{
Console.WriteLine("This is how much a gutter guard job will earn you!");
Console.WriteLine("---------");
Console.WriteLine("Step One:");
var maths = new Calculator();
maths.Main();
Thread.Sleep(1500);
Console.WriteLine("---------");
Console.WriteLine("Step Two:");
Console.WriteLine("What type of gutter material are you using?");
Console.WriteLine("Gold - [A]");
Console.WriteLine("Silver - [B]");
Console.WriteLine("Tin foil - [C]");
//Have MaterialRepo data displayed here depending on user input.
Console.ReadKey();
}
}
}
MaterialRepo.cs to house the material info
using System;
using System.Linq;
using System.Collections.Generic;
namespace Gutterjob
{
public class MaterialRepo
{
public string Id;
public string? Metal;
public string Price;
List<MaterialRepo> matList = new List<MaterialRepo>
{
new MaterialRepo {Id = "A", Metal = "Gold", Price = "$4"},
new MaterialRepo {Id = "B", Metal = "Silver", Price = "$2"},
new MaterialRepo {Id = "C", Metal = "Tin Foil", Price = "$1"},
};
}
}
I tried, but failed, to create a LINQ statement. Any help is greatly appreciated.