-3

大家好,我在网上搜索如何在 C# 中实现这个 java 代码,但我没有运气。我创建了一个超类和一个带参数的基类,谁能帮帮我。我想在 C# 中实现这个代码。

class People
{
    public String first_name;

    public String last_name;

    public People(String fname, String lname)
    {
        this.first_name = fname;

        this.last_name = lname;
    }
}

class Student extends People
{
    Public int studentID;

    public Student(String fname,String lname,int studid)
    {
       super(fname,lname);

       this.studentID = studid;
    }

}

 Student newStud = new Student('Jessica','Doe','123);

这是我想在 C# 中实现的代码,而不是调用人员类并实例化它,我只想调用从人员类继承的学生类。我是 C# 的新手,任何人都可以帮助我解决这个问题。

4

2 回答 2

3

请检查:

abstract class People
{
    public string FirstName;
    public string LastName;

    public People(string firstName, string lastName)
    {
        FirstName = firstName;
        LastName = lastName;
    }
}

sealed class Student : People
{
    public int StudentId;

    public Student(string firstName, string lastName, int studendId)
        : base(firstName, lastName) //Calling the base class constructor
    {
        StudentId = studendId;
    }
}
于 2013-10-19T13:36:45.420 回答
1

太简单了,我想

class People
{
    public String first_name;
    public String last_name;

    public People(string fname, string lname)
    {
        this.first_name = fname;
        this.last_name = lname;
    }
}

class Student : People
{
    public int studentID;
    public Student(string fname, string lname, int studid): base(fname,lname)
    {
        this.studentID = studid;
    }
}
于 2013-10-19T13:37:23.137 回答