C# 我需要将VB.net代码转换为C

C# 我需要将VB.net代码转换为C,c#,vb.net,C#,Vb.net,我需要把这段代码转换成c。我在第八行有问题。 公共类数据库 Public Function GetCourses(StudentID As Integer) As List(Of Course) Dim xEntity As New MyLearningEntities Dim xList As New List(Of Course) Dim xStudent As Student xStudent = (From x In xEntity.Students.

我需要把这段代码转换成c。我在第八行有问题。 公共类数据库

Public Function GetCourses(StudentID As Integer) As List(Of Course)

    Dim xEntity As New MyLearningEntities
    Dim xList As New List(Of Course)
    Dim xStudent As Student

    xStudent = (From x In xEntity.Students.Include("Courses") Select x Where x.StudentID = StudentID).FirstOrDefault

    If xStudent IsNot Nothing Then
        Return xStudent.Courses.ToList
    Else
        Return xList
    End If

End Function
您可以使用它将C转换为VB.Net,反之亦然

public List<Course> GetCourses(int StudentID)
{
    MyLearningEntities xEntity = new MyLearningEntities();
    List<Course> xList = new List<Course>();
    Student xStudent = default(Student);

    xStudent = (from x in xEntity.Students.Include("Courses") where x.StudentID == StudentID select x).FirstOrDefault();

    if (xStudent != null)
        return xStudent.Courses.ToList;
    else
        return xList;
}

请至少发布您的尝试。