error

list class

create list

I did the installer, but here is such an error, I am suffering for the second day and I have no idea how I can convert it to a string for output, since the usual methods do not work. Might be a stupid mistake, but I hope for a quick answer
I tried to convert in the usual ways (string) or ToString() but for some reason it doesn’t work, maybe I didn’t write it correctly, I googled nothing about this
all code
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
namespace visualnstaller
{
/// <summary>
/// Логика взаимодействия для MainWindow.xaml
/// </summary>
///
public class Part
{
public string PartName { get; set; }
public string PartReq { get; set; }
}
public class GetRequest
{
HttpWebRequest request;
string _addres;
public string Response { get; set; }
public GetRequest(string address)
{
_addres = address;
}
public void Run()
{
request = (HttpWebRequest)WebRequest.Create(_addres);
request.Method = "Get";
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var stream = response.GetResponseStream();
if (stream != null) Response = new StreamReader(stream).ReadToEnd();
}
catch (Exception)
{
}
}
}
public class Download
{
public Download(string name, string req)
{
using (WebClient wc = new WebClient())
{
var completed = new AutoResetEvent(false);
wc.DownloadProgressChanged += (s, e) =>
{
ProgressBar progress = new ProgressBar();
progress.Value = e.ProgressPercentage;
};
wc.DownloadFileAsync(new Uri(req), name);
wc.DownloadFileCompleted += (s, e) =>
{
completed.Set();
};
completed.WaitOne();
}
}
}
public partial class MainWindow : Window
{
public List<Part> numbers = new List<Part>();
public MainWindow()
{
InitializeComponent();
/* request */
var request = new GetRequest("https://gist.githubusercontent.com/MrKuBu/a24ddd8a331b0b54f6cc25b577d2fd9d/raw/154a1f194967d1a248b4627b9565586dc8bc2d1b/Example%2520file%2520downloader");
request.Run();
var response = request.Response;
var json = JObject.Parse(response);
foreach (var item in json)
{
CheckBox checkBox2 = new CheckBox { IsChecked = false };
ItemsControl ic = new ItemsControl();
ic.Items.Add(item.Key);
Programm.Items.Add(ic);
changeCheckBox(checkBox2, (string)item.Value, item.Key);
}
}
void changeCheckBox(CheckBox item, string itemValue, string itemName)
{
item.Checked += Item_Checked;
item.Unchecked += Item_Uncheked;
ProgrammCheckBox.Items.Add(item);
void Item_Checked(object sender, RoutedEventArgs e)
{
numbers.Add(new Part {PartName = itemName, PartReq = itemValue });
MessageBox.Show(numbers.Find(x => x.PartName.Contains(itemName)));
}
void Item_Uncheked(object sender, RoutedEventArgs e)
{
numbers.Remove(new Part() {PartName = itemName, PartReq = itemValue });
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
}
}
>Solution :
Find returns a single item of the generic type. I don’t know how you expect to display the item, when MessageBox.Show takes a string as the first argument. Maybe you want to format the object to display the properties?
var part = numbers.Find(x => x.PartName.Contains(itemName));
MessageBox.Show($"Name: {part.PartName}, Req: {part.PartReq}");