class Program1
    {
        struct Student
        {
            public string stuNum;
            public string stuName;
            public int stuAge;
            public int stuClass;
            public int stuGrade;
            public Student(string stuNum, string stuName, int stuAge, int stuClass, int stuGrade)
            {
                this.stuName = stuNum;
                this.stuName = stuName;
                this.stuAge = stuAge;
                this.stuClass = stuClass;
                this.stuGrade = stuGrade;
            }
            public void DoHomework();//结构中的方法
            }
       
    }
class Program
    {
        static void Main(string[] args)
        {
            Student goodStu;
            goodStu.stuNum = "20050901012";
            goodStu.stuName = "Anderson";
            goodStu.stuAge = 19;
            goodStu.stuClass = 1;
            goodStu.stuGrade = 1;
            Console.WriteLine("结构演示:");
            Console.WriteLine("三好学生:学好 -{0},姓名 -{1},年龄 -{2},班级 -{3}", goodStu.stuNum, goodStu.stuName, goodStu.Age, goodStu.stuClass);
            goodStu.DoHomework();
            Student normalStu = new Student("20050901018", "Bliss", 18, 1, 1);
            Console.WriteLine("普通学生:学好 -{0},姓名 -{1},年龄 -{2}, 班级 -{3}", normalStu.stuNum, normalStu.stuName, normalStu.stuAge, normalStu.stuClass);
            goodStu.DoHomework();
        }
    }

解决方案 »

  1.   

    VS提示:错误 1 “StructDemo.Program1.Student.DoHomework()”必须声明主体,因为它未标记为 abstract、extern 或 partial E:\C#\StructDemo\StructDemo\Program1.cs 25 25 StructDemo
      

  2.   

    C# 的问题,呵呵看起来好怀念。。
    晕,差一点看走眼了一看不知道到。用你的代码自己试了一下,结果吓一跳你的代码不是一般的错。。而且是错的很离谱
    首先把正确代码贴上来。。using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Student goodStu = new Student();
                goodStu.stuNum = "20050901012";
                goodStu.stuName = "Anderson";
                goodStu.stuAge = 19;
                goodStu.stuClass = 1;
                goodStu.stuGrade = 1;
                Console.WriteLine("结构演示:");
                Console.WriteLine("三好学生:学好 -{0},姓名 -{1},年龄 -{2},班级 -{3}", goodStu.stuNum, goodStu.stuName, goodStu.stuAge, goodStu.stuClass);
             
                Student normalStu = new Student("20050901018", "Bliss", 18, 1, 1);
                Console.WriteLine("普通学生:学好 -{0},姓名 -{1},年龄 -{2}, 班级 -{3}", normalStu.stuNum, normalStu.stuName, normalStu.stuAge, normalStu.stuClass);
                Console.Read();        }
        }
     public   class Student
        {     public string stuNum;
         public string stuName;
         public int stuAge;
         public int stuClass;
         public int stuGrade;
         public Student() { }
                public Student(string num, string name, int age, int sclass, int grade)
                {
                    stuName = num;
                    stuName = name;
                    stuAge = age;
                    stuClass = sclass;
                    stuGrade = grade;
                }            }
    }
    第一个错误:student 类。你为啥还要建一个Program1呢?建就建吧。但是你还在那个struct Student里放属性
    一个类里面能放构造函数,方法。属性,而构造函数的名称是它本身的名字。。你不能去取名字
    方法可以随便你取名字。但是就是不要去类的名字
    好好看看教材。。这些教材都有,