我正在尝试创建一个创建学生对象的多类程序,然后允许您更改其中一个学生对象的未声明专业的值。
这是我的代码:
StudentApp.cs
:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PA04CoddR
{
class StudentApp
{
public void Main()
{
DisplayTitle();
Student firstStudent = new Student("Robert", "Codd");
DisplayInfo(firstStudent);
Student secondStudent = new Student("Alexander", "Clemens", "FIN");
DisplayInfo(secondStudent);
GetMajor(firstStudent);
DisplayInfo(firstStudent);
TerminateProgram();
}
public void DisplayTitle()
{
Console.WriteLine("Programming Assignment 4 - Creating a Class - Robert S. Codd");
Console.WriteLine();
Console.WriteLine("____________________________________________________________");
}
public void DisplayInfo(Student newStudent)
{
Console.WriteLine("Frist Name: " + newStudent.GetFirstName);
Console.WriteLine("Last Name: " + newStudent.GetLastName);
Console.WriteLine("Major: " + newStudent.GetMajor);
}
public void GetMajor(Student newStudent)
{
Console.WriteLine("\tHello {0} {1}", newStudent.GetFirstName, newStudent.GetLastName);
Console.WriteLine("\tPlease enter your major: ");
string majorIn = Console.ReadLine();
Console.WriteLine();
newStudent.SetMajor(majorIn);
}
public void TerminateProgram()
{
Console.WriteLine("___________________________________________________________");
Console.WriteLine("PRESS ANY KEY TO TERMINATE...");
Console.Read();
}
}
}
Student.CS
:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PA04CoddR
{
class Student
{
private string firstName;
private string lastName;
private string major;
public Student()
{
}
public Student(string firstName, string lastName)
{
firstName = GetFirstName;
lastName = GetLastName;
major = "Undeclared";
}
public Student(string firstName, string lastName, string major)
{
firstName = GetFirstName;
lastName = GetLastName;
major = GetMajor;
}
public string GetFirstName
{
get
{
return firstName;
}
set
{
firstName = value;
}
}
public string GetLastName
{
get
{
return lastName;
}
set
{
lastName = value;
}
}
public string GetMajor
{
get
{
return major;
}
set
{
major = value;
}
}
public string SetMajor(string majorIn)
{
major = majorIn;
return majorIn;
}
}
}
我没有在 IDE 中列出或给出任何错误,但是一旦我尝试编译程序,它就会返回错误:“不包含适合入口点的静态‘main’方法”
我对这里和其他在线资源进行了一些研究,发现了一些似乎很有希望解决我的问题的方法,比如将 main 方法更改为 static,但是当我尝试我的 main 方法中的每一件事都返回一个语法错误时:“一个非静态字段、方法或属性需要对象引用”
任何帮助都将不胜感激,我是一名学习程序员,所以我确信这是相当简单的事情,我只是不完全理解这些概念。