record class for a student and professor in csharp

To record class for a student and professor in C#, we can create two separate classes - one for the student and one for the professor. Here's an example implementation:

main.cs
// Student class
public class Student
{
    public string Name { get; set; }
    public int RollNumber { get; set; }
    public string Branch { get; set; }
    
    public Student(string name, int rollNumber, string branch)
    {
        Name = name;
        RollNumber = rollNumber;
        Branch = branch;
    }
}

// Professor class
public class Professor
{
    public string Name { get; set; }
    public int EmployeeID { get; set; }
    public string Department { get; set; }
    
    public Professor(string name, int employeeID, string department)
    {
        Name = name;
        EmployeeID = employeeID;
        Department = department;
    }
}

// Usage
var student = new Student("John Doe", 1234, "CSE");
var professor = new Professor("Jane Smith", 5678, "ECE");

// Accessing properties
Console.WriteLine(student.Name); // "John Doe"
Console.WriteLine(professor.Department); // "ECE"
899 chars
38 lines

In the above code, we have created two separate classes - Student and Professor - that hold information about a student and a professor, respectively. We have used constructor to initialize their properties: Name, RollNumber, and Branch for the Student class, and Name, EmployeeID, and Department for the Professor class.

By creating separate classes, we can conveniently store and manipulate information about students and professors in our code.

gistlibby LogSnag