我试图使用但使用它自己的错误。在这种情况下,如何处理/释放字符串文件?
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