c# - How to save a file in a list box into a .txt file? -
this question has answer here:
how save file in list box .txt file?
return string.format("{0} = {1}", jaialainumber, "₱" + bet.tostring()); how save file on .txt file?
here's code of program. ): ^_^ .
public partial class frmjaialai : form { list<jaialai> source; public frmjaialai() { initializecomponent(); } private void frmjaialai_load(object sender, eventargs e) { source = new list<jaialai>(); } private void btnadd_click(object sender, eventargs e) { int bet; if (string.isnullorempty(txtjaialainumber.text) || !int32.tryparse(txtbet.text, out bet)) { messagebox.show("must required field.", "entry error"); return; } var existingproduct = source.where(x => x.jaialainumber == txtjaialainumber.text).singleordefault(); if (existingproduct != null) { existingproduct.bet += bet; } else source.add(new jaialai { bet = bet, jaialainumber = txtjaialainumber.text }); lstjaialainumberslist.datasource = null; lstjaialainumberslist.datasource = source; txtjaialainumber.text = ""; } public class jaialai { public string jaialainumber { get; set; } public int bet { get; set; } public override string tostring() { return string.format("{0} = {1}", jaialainumber, "₱" + bet.tostring()); } }
if understood correct, want write list<jaialai>
file. in case can use file.writealllines
.
file.writealllines("file-path", source.select(x => x.tostring()));
the first parameter path of file. second parameter ienumerable<string>
contains lines.
select
method calls tostring
method items strings can written file. can change lambda write other stuff per record file.
Comments
Post a Comment