I have a confusion here in understanding the relationship between object fs and object sw in the following line of code.
StreamWriter sw = new StreamWriter(fs);
The confusion is in understanding whether,
1> Is sw just pointing to the object fs 2> when fs is passed as parameter to StreamWriter constructor which members are initialized to the contents of object fs.
Please explain the mechanism in detail how FileStream class and StreamWriter class are accomplishing the task through object references fs and sw.
using System;
using System.IO;
class File_Write
{
public void Write_Data()
{
int empid = 12;
string empname = "sean";
FileStream fs = new FileStream("E:\\Files_Demo\\File_Write.txt", FileMode.Create,
FileAccess.Write, FileShare.None);
StreamWriter sw = new StreamWriter(fs)
{
sw.WriteLine("Good Morning");
sw.WriteLine("Provide_EmployeeDetails");
sw.WriteLine("Employee Id={0}", empid);
Console.WriteLine("Written to file...Success");
Console.Read();
}
}