我試圖使用但使用它自己的錯誤。在這種情況下,如何處理/釋放字符串文件?
public void Save(string path , bool Locked , PictureBox pb)
{
string fn;
string t = Path.GetFileNameWithoutExtension(wo_name);
if (File.Exists(path + "\\" + "DATABASE" + "\\" + t + "\\" + wo_name))
{
using (string f = Path.Combine(path + "\\" + "DATABASE" + "\\" + t + "\\" + wo_name))
{
File.Delete(f);
}
fn = path + "\\" + "DATABASE" + "\\" + t + "\\" + wo_name;
}
else
{
fn = path + "\\" + "DATABASE" + "\\" + wo_name + "\\" + wo_name + ".txt";
}
OptionsFile setting_file = new OptionsFile(fn);
setting_file.SetKey("File Name", fn);
setting_file.SetKey("Version", version);
setting_file.SetKey("Button Lock", Locked.ToString());
setting_file.SetKey("picturebox.Width", pb.Width.ToString());
setting_file.SetKey("picturebox.Height", pb.Height.ToString());
setting_file.SetListFloatKey("Coordinates_X", woc.Point_X);
setting_file.SetListFloatKey("Coordinates_Y", woc.Point_Y);
setting_file.SetListIntKey("ConnectionStart", connectionStart);
setting_file.SetListIntKey("ConnectionEnd", connectionEnd);
}
在此保存功能上面我做:
using (string f = Path.Combine(path + "\\" + "DATABASE" + "\\" + t + "\\" + wo_name))
{
File.Delete(f);
}
只是有串F = .... ....路徑和Fiel.Delete 我只是說收到使用但在使用即時得到錯誤:「字符串」:類型using語句中使用必須是隱式轉換爲「System.IDisposable的」
配置字符串沒有意義,字符串只是消耗內存。垃圾收集器已經處理了這個問題。不要在這裏使用*。 – 2012-07-15 16:09:20