当前位置:编程学习 > C#/ASP.NET >>

下面程序出现了一个错误,各位CSDN路过的朋友能否帮我看一下,我将以为数不多的分数相送。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication
{
    public static class GlobalMembers
    {
        static int Main()
        {
            string i = new string(new char[15]);
            sbyte k;
            string l = new string(new char[15]);
            string m = new string(new char[15]);
            sbyte j;
            string n = new string(new char[15]);
            string s = new string(new char[15]);
            cin >> i >> j >> k;
            cin >> l >> m;
            cin >> n >> s;            
            CPeople a = new CPeople(ref i, j, k);
            a.print();
            CStudent b = new CStudent(ref i, j, k, ref l, ref m);
            b.print();
            CTeather c = new CTeather(ref i, j, k, ref n, ref s);
            c.print();
            return 0;
        }
    }

    public class CPeople
    {
        protected string name = new string(new char[15]);
        protected sbyte sex;
        protected int age;
        public CPeople(ref string a, sbyte b, int c)
        {
            name = a;
            sex = b;
            age = c;
        }
        public void print()
        {
            Console.Write("People:");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
        }
    }
    public class CStudent : CPeople
    {
        protected string xh = new string(new char[20]);
        protected string rxsj = new string(new char[20]);
        public CStudent(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            xh = d;
            rxsj = e;
        }
        public new void print()
        {
            Console.Write("Student: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("No.: ");
            Console.Write(xh);
            Console.Write("\n");
            Console.Write("Score: ");
            Console.Write(rxsj);
            Console.Write("\n");
        }
    }
    public class CTeather : CPeople
    {
        protected string Position = new string(new char[10]);
        protected string Department = new string(new char[10]);
        public CTeather(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            Position = d;
            Department = e;
        }
        public new void print()
        {
            Console.Write("Student: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("Position: ");
            Console.Write(Position);
            Console.Write("\n");
            Console.Write("Department: ");
            Console.Write(Department);
            Console.Write("\n");
        }
    }      
        public new void print()
        {
           
            Console.Write("Name: ");
            Console.Write(base.name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(base.sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(base.age);
            Console.Write("\n");
            Console.Write("No.: ");
            Console.Write(xh);
            Console.Write("\n");
            Console.Write("Score: ");
            Console.Write(rxsj);
            Console.Write("\n");
            Console.Write("Position: ");
            Console.Write(Position);
            Console.Write("\n");
            Console.Write("Department: ");
            Console.Write(Department);
            Console.Write("\n");
        }
    }

--------------------编程问答-------------------- --------------------编程问答-------------------- 贴了一大段代码  你还指望别人帮你运行起来调试?
--------------------编程问答-------------------- 最后一个void提示出错了。错误1   应输入 class、delegate、enum、interface 或 struct --------------------编程问答-------------------- 最后一个void提示出错了。错误1   应输入 class、delegate、enum、interface 或 struct --------------------编程问答--------------------
引用 2 楼 keinshen 的回复:
贴了一大段代码  你还指望别人帮你运行起来调试?
何解? --------------------编程问答-------------------- 看了代码 我就懒得看了 但是 既然有"应输入 class、delegate、enum、interface 或 struct" 这个错误..


我目测的话 应该是多了一个}或者少了一个} --------------------编程问答--------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication
{
    public static class GlobalMembers
    {
        static int Main()
        {
            string i = new string(new char[15]);
            sbyte k;
            string l = new string(new char[15]);
            string m = new string(new char[15]);
            sbyte j;
            string n = new string(new char[15]);
            string s = new string(new char[15]);
            cin >> i >> j >> k;
            cin >> l >> m;
            cin >> n >> s;
            CPeople a = new CPeople(ref i, j, k);
            a.print();
            CStudent b = new CStudent(ref i, j, k, ref l, ref m);
            b.print();
            CTeather c = new CTeather(ref i, j, k, ref n, ref s);
            c.print();
            return 0;
        }
    }

    public class CPeople
    {
        protected string name = new string(new char[15]);
        protected sbyte sex;
        protected int age;
        public CPeople(ref string a, sbyte b, int c)
        {
            name = a;
            sex = b;
            age = c;
        }
        public void print()
        {
            Console.Write("People:");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
        }
    }
    public class CStudent : CPeople
    {
        protected string xh = new string(new char[20]);
        protected string rxsj = new string(new char[20]);
        public CStudent(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            xh = d;
            rxsj = e;
        }
        public new void print()
        {
            Console.Write("Student: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("No.: ");
            Console.Write(xh);
            Console.Write("\n");
            Console.Write("Score: ");
            Console.Write(rxsj);
            Console.Write("\n");
        }
    }
    public class CTeather : CPeople
    {
        protected string Position = new string(new char[10]);
        protected string Department = new string(new char[10]);
        public CTeather(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            Position = d;
            Department = e;
        }
        public new void print()
        {
            Console.Write("Student: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("Position: ");
            Console.Write(Position);
            Console.Write("\n");
            Console.Write("Department: ");
            Console.Write(Department);
            Console.Write("\n");
        }

        public new void print()
        {

            Console.Write("Name: ");
            Console.Write(base.name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(base.sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(base.age);
            Console.Write("\n");
            Console.Write("No.: ");
            Console.Write(xh);
            Console.Write("\n");
            Console.Write("Score: ");
            Console.Write(rxsj);
            Console.Write("\n");
            Console.Write("Position: ");
            Console.Write(Position);
            Console.Write("\n");
            Console.Write("Department: ");
            Console.Write(Department);
            Console.Write("\n");
        }
    }
}



运行下 是不是你想要的. --------------------编程问答--------------------
引用 7 楼 diaodiaop 的回复:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication
{
    public static class GlobalMembers
    {
        static int Main()
        {
            string i = new string(new char[15]);
            sbyte k;
            string l = new string(new char[15]);
            string m = new string(new char[15]);
            sbyte j;
            string n = new string(new char[15]);
            string s = new string(new char[15]);
            cin >> i >> j >> k;
            cin >> l >> m;
            cin >> n >> s;
            CPeople a = new CPeople(ref i, j, k);
            a.print();
            CStudent b = new CStudent(ref i, j, k, ref l, ref m);
            b.print();
            CTeather c = new CTeather(ref i, j, k, ref n, ref s);
            c.print();
            return 0;
        }
    }

    public class CPeople
    {
        protected string name = new string(new char[15]);
        protected sbyte sex;
        protected int age;
        public CPeople(ref string a, sbyte b, int c)
        {
            name = a;
            sex = b;
            age = c;
        }
        public void print()
        {
            Console.Write("People:");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
        }
    }
    public class CStudent : CPeople
    {
        protected string xh = new string(new char[20]);
        protected string rxsj = new string(new char[20]);
        public CStudent(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            xh = d;
            rxsj = e;
        }
        public new void print()
        {
            Console.Write("Student: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("No.: ");
            Console.Write(xh);
            Console.Write("\n");
            Console.Write("Score: ");
            Console.Write(rxsj);
            Console.Write("\n");
        }
    }
    public class CTeather : CPeople
    {
        protected string Position = new string(new char[10]);
        protected string Department = new string(new char[10]);
        public CTeather(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            Position = d;
            Department = e;
        }
        public new void print()
        {
            Console.Write("Student: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("Position: ");
            Console.Write(Position);
            Console.Write("\n");
            Console.Write("Department: ");
            Console.Write(Department);
            Console.Write("\n");
        }

        public new void print()
        {

            Console.Write("Name: ");
            Console.Write(base.name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(base.sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(base.age);
            Console.Write("\n");
            Console.Write("No.: ");
            Console.Write(xh);
            Console.Write("\n");
            Console.Write("Score: ");
            Console.Write(rxsj);
            Console.Write("\n");
            Console.Write("Position: ");
            Console.Write(Position);
            Console.Write("\n");
            Console.Write("Department: ");
            Console.Write(Department);
            Console.Write("\n");
        }
    }
}



运行下 是不是你想要的.
提示出现了一个错误:错误 1 类型“ConsoleApplication.CTeather”已定义了一个名为“print”的具有相同参数类型的成员 --------------------编程问答-------------------- 如此人性化的错误提示信息,你居然还要来发帖问,你是汉语不过关,还是怎么的? --------------------编程问答--------------------
引用 9 楼 yeqi3000 的回复:
如此人性化的错误提示信息,你居然还要来发帖问,你是汉语不过关,还是怎么的?
C#初学者,如何修改,能否指点一下? --------------------编程问答--------------------
引用 楼主 u012211930 的回复:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication
{
    public static class GlobalMembers
    {
        static int Main()
        {
            string i = new string(new char[15]);
            sbyte k;
            string l = new string(new char[15]);
            string m = new string(new char[15]);
            sbyte j;
            string n = new string(new char[15]);
            string s = new string(new char[15]);
            cin >> i >> j >> k;
            cin >> l >> m;
            cin >> n >> s;            
            CPeople a = new CPeople(ref i, j, k);
            a.print();
            CStudent b = new CStudent(ref i, j, k, ref l, ref m);
            b.print();
            CTeather c = new CTeather(ref i, j, k, ref n, ref s);
            c.print();
            return 0;
        }
    }

    public class CPeople
    {
        protected string name = new string(new char[15]);
        protected sbyte sex;
        protected int age;
        public CPeople(ref string a, sbyte b, int c)
        {
            name = a;
            sex = b;
            age = c;
        }
        public void print()
        {
            Console.Write("People:");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
        }
    }
    public class CStudent : CPeople
    {
        protected string xh = new string(new char[20]);
        protected string rxsj = new string(new char[20]);
        public CStudent(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            xh = d;
            rxsj = e;
        }
        public new void print()
        {
            Console.Write("Student: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("No.: ");
            Console.Write(xh);
            Console.Write("\n");
            Console.Write("Score: ");
            Console.Write(rxsj);
            Console.Write("\n");
        }
    }
    public class CTeather : CPeople
    {
        protected string Position = new string(new char[10]);
        protected string Department = new string(new char[10]);
        public CTeather(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            Position = d;
            Department = e;
        }
        public new void print()
        {
            Console.Write("Student: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("Position: ");
            Console.Write(Position);
            Console.Write("\n");
            Console.Write("Department: ");
            Console.Write(Department);
            Console.Write("\n");
        }
    }      
        public new void print()
        {
           
            Console.Write("Name: ");
            Console.Write(base.name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(base.sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(base.age);
            Console.Write("\n");
            Console.Write("No.: ");
            Console.Write(xh);
            Console.Write("\n");
            Console.Write("Score: ");
            Console.Write(rxsj);
            Console.Write("\n");
            Console.Write("Position: ");
            Console.Write(Position);
            Console.Write("\n");
            Console.Write("Department: ");
            Console.Write(Department);
            Console.Write("\n");
        }
    }


方法和类是平行级别 --------------------编程问答-------------------- namespace ConsoleApplication1
{
    public static class GlobalMembers
    {
        static int Main()
        {
            string i = new string(new char[15]);
            sbyte k;
            string l = new string(new char[15]);
            string m = new string(new char[15]);
            sbyte j;
            string n = new string(new char[15]);
            string s = new string(new char[15]);
            cin >> i >> j >> k;
            cin >> l >> m;
            cin >> n >> s;
            CPeople a = new CPeople(ref i, j, k);
            a.print();
            CStudent b = new CStudent(ref i, j, k, ref l, ref m);
            b.print();
            CTeather c = new CTeather(ref i, j, k, ref n, ref s);
            c.print();
            return 0;
        }
    }

    public class CPeople
    {
        protected string name = new string(new char[15]);
        protected sbyte sex;
        protected int age;
        public CPeople(ref string a, sbyte b, int c)
        {
            name = a;
            sex = b;
            age = c;
        }
        public void print()
        {
            Console.Write("Name:");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
        }
    }


    public class CStudent : CPeople
    {
        protected string xh = new string(new char[20]);
        protected string rxsj = new string(new char[20]);
        public CStudent(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            xh = d;
            rxsj = e;
        }
        public new void print()
        {
            Console.Write("Student: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("No.: ");
            Console.Write(xh);
            Console.Write("\n");
            Console.Write("Score: ");
            Console.Write(rxsj);
            Console.Write("\n");
        }
    }


    public class CTeather : CPeople
    {
        protected string Position = new string(new char[10]);
        protected string Department = new string(new char[10]);
        public CTeather(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            Position = d;
            Department = e;
        }
        public new void print()
        {
            Console.Write("Teacher: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("Position: ");
            Console.Write(Position);
            Console.Write("\n");
            Console.Write("Department: ");
            Console.Write(Department);
            Console.Write("\n");
        }
    }

}

LZ是想要这样的吗 --------------------编程问答--------------------
引用 11 楼 rui_china 的回复:
Quote: 引用 楼主 u012211930 的回复:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication
{
    public static class GlobalMembers
    {
        static int Main()
        {
            string i = new string(new char[15]);
            sbyte k;
            string l = new string(new char[15]);
            string m = new string(new char[15]);
            sbyte j;
            string n = new string(new char[15]);
            string s = new string(new char[15]);
            cin >> i >> j >> k;
            cin >> l >> m;
            cin >> n >> s;            
            CPeople a = new CPeople(ref i, j, k);
            a.print();
            CStudent b = new CStudent(ref i, j, k, ref l, ref m);
            b.print();
            CTeather c = new CTeather(ref i, j, k, ref n, ref s);
            c.print();
            return 0;
        }
    }

    public class CPeople
    {
        protected string name = new string(new char[15]);
        protected sbyte sex;
        protected int age;
        public CPeople(ref string a, sbyte b, int c)
        {
            name = a;
            sex = b;
            age = c;
        }
        public void print()
        {
            Console.Write("People:");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
        }
    }
    public class CStudent : CPeople
    {
        protected string xh = new string(new char[20]);
        protected string rxsj = new string(new char[20]);
        public CStudent(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            xh = d;
            rxsj = e;
        }
        public new void print()
        {
            Console.Write("Student: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("No.: ");
            Console.Write(xh);
            Console.Write("\n");
            Console.Write("Score: ");
            Console.Write(rxsj);
            Console.Write("\n");
        }
    }
    public class CTeather : CPeople
    {
        protected string Position = new string(new char[10]);
        protected string Department = new string(new char[10]);
        public CTeather(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            Position = d;
            Department = e;
        }
        public new void print()
        {
            Console.Write("Student: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("Position: ");
            Console.Write(Position);
            Console.Write("\n");
            Console.Write("Department: ");
            Console.Write(Department);
            Console.Write("\n");
        }
    }      
        public new void print()
        {
           
            Console.Write("Name: ");
            Console.Write(base.name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(base.sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(base.age);
            Console.Write("\n");
            Console.Write("No.: ");
            Console.Write(xh);
            Console.Write("\n");
            Console.Write("Score: ");
            Console.Write(rxsj);
            Console.Write("\n");
            Console.Write("Position: ");
            Console.Write(Position);
            Console.Write("\n");
            Console.Write("Department: ");
            Console.Write(Department);
            Console.Write("\n");
        }
    }


方法和类是平行级别
这个我也不怎么清楚。 --------------------编程问答--------------------
引用 12 楼 lasesiwen 的回复:
namespace ConsoleApplication1
{
    public static class GlobalMembers
    {
        static int Main()
        {
            string i = new string(new char[15]);
            sbyte k;
            string l = new string(new char[15]);
            string m = new string(new char[15]);
            sbyte j;
            string n = new string(new char[15]);
            string s = new string(new char[15]);
            cin >> i >> j >> k;
            cin >> l >> m;
            cin >> n >> s;
            CPeople a = new CPeople(ref i, j, k);
            a.print();
            CStudent b = new CStudent(ref i, j, k, ref l, ref m);
            b.print();
            CTeather c = new CTeather(ref i, j, k, ref n, ref s);
            c.print();
            return 0;
        }
    }

    public class CPeople
    {
        protected string name = new string(new char[15]);
        protected sbyte sex;
        protected int age;
        public CPeople(ref string a, sbyte b, int c)
        {
            name = a;
            sex = b;
            age = c;
        }
        public void print()
        {
            Console.Write("Name:");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
        }
    }


    public class CStudent : CPeople
    {
        protected string xh = new string(new char[20]);
        protected string rxsj = new string(new char[20]);
        public CStudent(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            xh = d;
            rxsj = e;
        }
        public new void print()
        {
            Console.Write("Student: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("No.: ");
            Console.Write(xh);
            Console.Write("\n");
            Console.Write("Score: ");
            Console.Write(rxsj);
            Console.Write("\n");
        }
    }


    public class CTeather : CPeople
    {
        protected string Position = new string(new char[10]);
        protected string Department = new string(new char[10]);
        public CTeather(ref string a, sbyte b, int c, ref string d, ref string e)
            : base(ref a, b, c)
        {
            CPeople(a, b, c);
            Position = d;
            Department = e;
        }
        public new void print()
        {
            Console.Write("Teacher: ");
            Console.Write("\n");
            Console.Write("Name: ");
            Console.Write(name);
            Console.Write("\n");
            Console.Write("Sex: ");
            Console.Write(sex);
            Console.Write("\n");
            Console.Write("Age: ");
            Console.Write(age);
            Console.Write("\n");
            Console.Write("Position: ");
            Console.Write(Position);
            Console.Write("\n");
            Console.Write("Department: ");
            Console.Write(Department);
            Console.Write("\n");
        }
    }

}

LZ是想要这样的吗
其实我做错了,题目是这样的:定义一个人员类Cpeople,其属性有:姓名、性别、年龄;从中派生出学生类Cstudent,添加属性:学号、入学时间和入学成绩;从Cpeople类在派生出教师类Cteacher,添加属性:职务、部门、工作时间;由Cstudent类派生出研究生类Cgraduate,添加属性:研究方向和导师,分别定义其中的构造函数和输出函数。并编写主程序进行测试。 --------------------编程问答-------------------- 两个方法名字一模一样,即使你不是}多或少的错误你那里也肯定会报错的了,你这样的要求直接把Cpeople当做一个父类,下面的再按要求派生出子类就行了 --------------------编程问答--------------------
引用 15 楼 u011130289 的回复:
两个方法名字一模一样,即使你不是}多或少的错误你那里也肯定会报错的了,你这样的要求直接把Cpeople当做一个父类,下面的再按要求派生出子类就行了
嗯,谢谢!在体会。
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,