Does this method follow the rules of objective programming? If not, how can I change it?static void SaveStudentData(Student[] student){    StreamWriter File1 = new StreamWriter(First.csv, false, Encoding.Default);    StreamWriter File2 = new StreamWriter(Fourth.csv, false, Encoding.Default);    for (int i = 0; i < Count; i++)    {        if (student[i].Year == 1)        {            File1.WriteLine({0};{1};{2};{3};{4};{5};{6}, student[i].FName, student[i].LName, student[i].BDate.ToString(yyyy/MM/dd), student[i].StudentID, student[i].Year, student[i].PhoneNumber, student[i].IsFreshman);        }        else if (student[i].Year == 4)        {            File2.WriteLine({0};{1};{2};{3};{4};{5};{6}, student[i].FName, student[i].LName, student[i].BDate.ToString(yyyy/MM/dd), student[i].StudentID, student[i].Year, student[i].PhoneNumber, student[i].IsFreshman);        }    }    File1.Close();    File2.Close();}
Write object data to CSV files
c#;csv
Here's a possible solution - note there are always many ways to solve a problem. The main points I'm trying to demonstrate here are:Your concerns are kept separate. There are data elements, data formatting, I/O and business logic.Classes can be mostly independent. For instance, you can create a different formatting class that implements IStudentFormatter and inject it into the I/O class.That being said, here is the implementation:public interface IStudentFormatter{    string AsCsv(Student student);}public sealed class StudentToCsv : IStudentFormatter{    public string AsCsv(Student student)    {        if (student == null)        {            throw new ArgumentNullException(student);        }        return string.Format(            {0};{1};{2};{3};{4};{5};{6},            student.FName,            student.LName,            student.BDate.ToString(yyyy/MM/dd),            student.StudentID,            student.Year,            student.PhoneNumber,            student.IsFreshman);    }}public static class StudentBusinessLogic{    private const int FirstYear = 1;    private const int FourthYear = 4;    public static IEnumerable<Student> FirstYears(this IEnumerable<Student> students)    {        if (students == null)        {            throw new ArgumentNullException(students);        }        return students.Where(student => (student != null) && (student.Year == FirstYear));    }    public static IEnumerable<Student> FourthYears(this IEnumerable<Student> students)    {        if (students == null)        {            throw new ArgumentNullException(students);        }        return students.Where(student => (student != null) && (student.Year == FourthYear));    }}public sealed class StudentWriter : StreamWriter{    private readonly IStudentFormatter _StudentToCsv;    public StudentWriter(string path, bool append, Encoding encoding, IStudentFormatter studentToCsv) : base(path, append, encoding)    {        if (studentToCsv == null)        {            throw new ArgumentNullException(studentToCsv);        }        this._StudentToCsv = studentToCsv;    }    public void WriteStudent(Student student)    {        if (student == null)        {            throw new ArgumentNullException(student);        }        this.WriteLine(this._StudentToCsv.AsCsv(student));    }    public void WriteStudents(IEnumerable<Student> students)    {        if (students == null)        {            throw new ArgumentNullException(students);        }        foreach (var student in students)        {            this.WriteStudent(student);        }    }}You'd call these as such:static void SaveStudentData(IEnumerable<Student> students){    var studentToCsv = new StudentToCsv();    using (var file1 = new StudentWriter(First.csv, false, Encoding.Default, studentToCsv))    {        file1.WriteStudents(students.FirstYears());    }    using (var file2 = new StudentWriter(Fourth.csv, false, Encoding.Default, studentToCsv))    {        file2.WriteStudents(students.FourthYears());    }}