How to save information from TextBoxes and I want to get advise about the best way how to Implement info record.
I have the main Form1. There're ListBox1 with products names and TextBox1. When user is choosing any product from ListBox1 in TextBox1 is appeared info about this product.
Also when user click on the button "Add product" Form2 opens. There (Form2) user input info about new product in TextBox1-4. And after when user click "Ok" the entered info is saved.
My question is: how best to save info from TextBox1-4 (Form2) - in an array, list, use a class?
In my opinion the best way to save this information is using a class of Product
, then also having a List<Product>
in another class.
public class Product
{
public string Name { get; set; }
public string Company { get; set; }
public double Price { get; set; }
public double Discount { get; set; }
public Product(string name, string company, double price, double discount)
{
Name = name;
Company = company;
Price = price;
Discount = discount;
}
}
Some other class:
public List<Product> Products = new List<Product>();
If you need to save this when the application closes, you can use a database or simply use JSON. Link to JSON serialization: newtonsoft
Don't forget to add the NuGet package 'Newtonsoft.Json': Right click class -> Manage NuGet Packages -> Browse -> Install Newtonsoft.Json
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.