我已经获得了要更改的代码,我已经添加了一个包含初始学生信息的结构,它运行良好,代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Program
{
class Student
{
public struct student_data
{
public string forename;
public string surname;
public string prog_title;
public string prog_code;
public int id_number;
public float averageGrade;
}
static void populateStruct(out student_data student, string fname, string surname, string prog_title, string prog_code, int id_number)
{
student = new student_data();
student.forename = fname;
student.surname = surname;
student.prog_title = prog_title;
student.prog_code = prog_code;
student.id_number = id_number;
student.averageGrade = 0.0F;
}
static void Main(string[] args)
{
student_data[] students = new student_data[4];
populateStruct(out students[0], "Mark", "Anders", "Comp", "CIS2117", 0);
printStudent(students[0]);
populateStruct(out students[1], "Tom", "Jones", "Comp", "CIS2117", 1);
printStudent(students[1]);
populateStruct(out students[2], "Tim", "Jones", "Comp", "CIS2117", 2);
printStudent(students[2]);
populateStruct(out students[3], "Tim", "Bones", "Comp", "CIS2117", 3);
printStudent(students[3]);
}
void printAllStudent(student_data student)
{
for (int i = 0; i <= 3; i++)
{
Console.WriteLine(i);
}
}
static void printStudent(student_data student)
{
Console.WriteLine("Name: " + student.forename + " " + student.surname);
Console.WriteLine("Id: " + student.id_number);
Console.WriteLine("AV grade: " + student.averageGrade);
Console.WriteLine("Course Title: " + student.prog_title);
Console.WriteLine("Course Code: " + student.prog_code);
}
}
}
但是我的任务是添加另一个结构来保存我已经完成的 module_data,我还创建了一个新方法来填充 module_data 数组。但是当我运行程序时,只出现一个错误,什么也没发生?
它的目的是在控制台屏幕中写入数组中的所有元素,但不会构建并产生此错误:
'错误 1 找不到类型或命名空间名称'module_data'(您是否缺少 using 指令或程序集引用?)'
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace Program
{
class Student
{
public struct student_data
{
public string forename;
public string surname;
public string prog_title;
public string prog_code;
public int id_number;
public float averageGrade;
}
public struct module_data
{
public string module_code;
public string module_title;
public int module_mark;
}
static void populateStruct(out student_data student, string fname, string surname, string prog_title, string prog_code, int id_number)
{
student = new student_data();
student.forename = fname;
student.surname = surname;
student.prog_title = prog_title;
student.prog_code = prog_code;
student.id_number = id_number;
student.averageGrade = 0.0F;
}
static void populateModule(out module_data module, string mcode, string mname, int (score)
{
module = new module_data();
module.module_code = mcode;
module.module_title = mname;
module.module_mark = score;
}
static void Main(string[] args)
{
{
student_data[] students = new student_data[5];
populateStruct(out students[0], "Mark", "Anderson", "Comp", "CIS2117", 0);
printStudent(students[0]);
populateStruct(out students[1], "Tom", "Jones", "Comp", "CIS2117", 1);
printStudent(students[1]);
populateStruct(out students[2], "Tim", "Jones", "Comp", "CIS2117", 2);
printStudent(students[2]);
populateStruct(out students[3], "Tim", "Bones", "Comp", "CIS2117", 3);
printStudent(students[3]);
}
{
module_data[] modules = new module_data[4];
populateStruct(out modules[0], "7", "App Dev", "56", 0);
printStudent(modules[0]);
populateStruct(out modules[1], "7", "App Dev", "56", 1);
printStudent(module[1]);
populateStruct(out modules[2], "7", "App Dev", "56", 2);
printStudent(modules[2]);
populateStruct(out modules[3], "7", "App Dev", "56", 3);
printStudent(modules[3]);
Console.ReadKey();
}
}
void printAllStudent(student_data student)
{
for (int i = 0; i <= 3; i++)
{
Console.WriteLine(i);
}
}
static void printStudent(student_data student)
{
Console.WriteLine("Name: " + student.forename + " " + student.surname);
Console.WriteLine("Id: " + student.id_number);
Console.WriteLine("AV grade: " + student.averageGrade);
Console.WriteLine("Course Title: " + student.prog_title);
Console.WriteLine("Course Code: " + student.prog_code);
Console.WriteLine("Module Code: " + modules.mcode);
Console.WriteLine("Module Name: " + modules.mname);
Console.WriteLine("Score: " + modules.score);
}
}
}
事实上,我不确定我哪里出错了,任何帮助或建议将不胜感激。