私はWindowsPhone7アプリに取り組んでいますが、ディレクトリを作成する前にディレクトリが存在するかどうかを確認する必要があるかどうか、および作成する/しないことの長所/短所について、誰かが決定的な答えを持っているかどうか疑問に思いました。 。私が知る限り、コードをステップスルーすることから、次の2つのコードブロックは同じように機能します。
using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
//ensure directory exists
String sDirectory = System.IO.Path.GetDirectoryName(sPath);
if (!appStorage.DirectoryExists(sDirectory))
{
appStorage.CreateDirectory(sDirectory);
}
}
と
using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
//ensure directory exists
String sDirectory = System.IO.Path.GetDirectoryName(sPath);
appStorage.CreateDirectory(sDirectory);
}
コードの2番目のブロックを使用しても安全ですか?ディレクトリがすでに存在する場合は例外をスローしないようであり、ディレクトリの内容をそのままにしておくようにも見えました。