简体   繁体   中英

How to write in text file from messagebox

I have the following code, that write for n times c[resultwithindex.Index] and resultwithindex.result in message box. Now, I want to write all c[resultwithindex.Index] which are in messagebox in text file or array. BTW, I tried by adding Genre.Write(sb1.ToString()); which did not work.

Thanks in advance

var sb1 = new StringBuilder();
foreach (var resultwithindex in results.Select((r, index) => new { result = r, Index = index }).OrderByDescending(r => r.result).Take(n))
{
   sb1.AppendFormat(CultureInfo.InvariantCulture, "{0}: {1}", c[resultwithindex.Index], resultwithindex.result);
   sb1.AppendLine();
}
MessageBox.Show(sb1.ToString());

You can try : System.IO.File.WriteAllText("path", sb1.ToString());

http://msdn.microsoft.com/fr-fr/library/ms143375(v=vs.110).aspx

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM