Using
Directory _dir = Directory.CreateDirectory(path);
So how to store the object of directory in a variable so then I have to check whether the directory at specified path exists or not as?
if(!_dir.exists())
{
_dir.CreateDirectory(path);
}
Is it allowed in C#?
Directory.CreateDirectorywill actually check if the directory exists before attempting to create it, so there's really no reason to check if it exists before calling it. However you can always use theDirectoryInfoclass, whichDirectory.CreateDirectoryreturns, to do what you want.