public static void CopyFile(string from, string into)
{
using (var fromFile = File.Open(from, FileMode.Open, FileAccess.Read))
using (var toFile = File.Open(into, FileMode.Create, FileAccess.Write))
{
// ... Perform actual file copy
// Both FileStream objects are disposed at the end of the enclosing scope,
// in this case, the method declaration.
}
}
public static void CopyFile(string from, string into)
{
using scoped var fromFile = File.Open(from, FileMode.Open, FileAccess.Read);
using scoped var toFile = File.Open(into, FileMode.Create, FileAccess.Write);
// ... Perform actual file copy
// Both FileStream objects are disposed at the end of the enclosing scope,
// in this case, the method declaration.
}