如果变量path
为空editor.Text
且不为空,则应显示 SaveFileDialog。
现在,到底为什么这该死的东西失败了???
我已经尝试了许多不同的代码变体,结果相同:失败:
if(path.Length >= 1) // path contains a path. Save changes instead of creating NEW file.
{
File.WriteAllText(path, content);
}
else
{
// no path defined. Create new file and write to it.
using(SaveFileDialog saver = new SaveFileDialog())
{
if(saver.ShowDialog() == DialogButtons.OK)
{
File.WriteAllText(saver.Filename, content);
}
}
}
在代码文件的顶部,我有:
路径 = 字符串。空;
那么,即使在尝试了以下所有变体之后,为什么每次都失败呢?
if(path.Length > 1) // path contains a path. Save changes instead of creating NEW file.
{
File.WriteAllText(path, content);
}
else
{
// no path defined. Create new file and write to it.
using(SaveFileDialog saver = new SaveFileDialog())
{
if(saver.ShowDialog() == DialogButtons.OK)
{
File.WriteAllText(saver.Filename, content);
}
}
}
和
if(String.IsNullOrEmpty(path)) // path contains a path. Save changes instead of creating NEW file.
{
File.WriteAllText(path, content);
}
else
{
// no path defined. Create new file and write to it.
using(SaveFileDialog saver = new SaveFileDialog())
{
if(saver.ShowDialog() == DialogButtons.OK)
{
File.WriteAllText(saver.Filename, content);
}
}
}
和
if(String.IsNullOrWhiteSpace(path)) // path contains a path. Save changes instead of creating NEW file.
{
File.WriteAllText(path, content);
}
else
{
// no path defined. Create new file and write to it.
using(SaveFileDialog saver = new SaveFileDialog())
{
if(saver.ShowDialog() == DialogButtons.OK)
{
File.WriteAllText(saver.Filename, content);
}
}
}
这让我很生气。这怎么可能失败?
设置断点表明肯定path
是/ 。 null
""