I am trying to compare if string that user inputs exists in list and if it does I would like to remove it from list.
I am getting an Error:
Argument 1: cannot convert from 'project.MainClass.Artical' to 'string'
I am aware that I am getting it because I am trying to compare string with list.
I have struct:
struct Artical {
public string name;
public float price;
public double weight;
}
And method:
static void DeleteArtical()
{
Artical k = new Artical();
Console.WriteLine("Enter name you want to delete: ");
k.name = Console.ReadLine();
List < Artical > articals = new List < Artical > ();
using(StreamWriter sw = File.AppendText((@ "../../dat.txt"))) {
if (articals.Exists(x => string.Equals(x, k.name, StringComparison.OrdinalIgnoreCase))) {
Console.WriteLine("Done !!");
artikli.Remove(k);
}
}
}
x is underlined and gives me error that I mentioned above.
Articalobject to a string value. change it to =>x.name, k.name