[問題] 怎麼樣把int變數寫入文字檔?

看板C_Sharp作者 (吳小正)時間14年前 (2009/11/02 17:08), 編輯推噓2(201)
留言3則, 2人參與, 最新討論串1/1
我用了這個方法: Random r1 = new Random(unchecked((int)DateTime.Now.Ticks)); int a = r1.Next(29) + 66; string pathans = "\\My Documents\\mrwu\\Test\\ans.txt"; try { if (File.Exists(pathans)) { File.Delete(pathans); } using (FileStream fs = File.Create(pathans)) { 錯誤>> Byte[] info = new UTF8Encoding(true).GetBytes(a.tostring); fs.Write(info, 0, info.Length); } } 會再那一行出錯 1.最符合的多載方法 'System.Text.Encoding.GetBytes(char[])' 有一些無效的引數 2.無法從 '方法群組' 轉換為 'char[]' 請問該如何把int變數儲存在txt檔裡面呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.21.235.230

11/02 17:19, , 1F
a.tostring() 這樣呢?
11/02 17:19, 1F

11/02 17:24, , 2F
可以了耶\(^▽^)/
11/02 17:24, 2F

11/02 21:31, , 3F
說一下好了,.tostring是動作.後面要()起來,
11/02 21:31, 3F
文章代碼(AID): #1Axg5xd4 (C_Sharp)