【发布时间】:2015-04-16 14:40:15
【问题描述】:
我是编程新手,但遇到了 C# 问题。我想创建一个控制台程序,用户填写一些个人信息,控制台打印这些信息。我正在尝试使用 ref,但我无法将用户的答案(来自方法 GetStudentInfo)与打印方法 PrintStudentDetails 联系起来。
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
GetStudentInfo();
{
string first = "";
string last = "";
string birthday = "";
PrintStudentDetails(ref first, ref last, ref birthday);
}
GetTeacherInfo();
GetCourseInfo();
GetProgramInfo();
GetDegreeInfo();
}
//student information
static void GetStudentInfo()
{
Console.WriteLine("Enter the student's first name: ");
string firstName = Console.ReadLine();
Console.WriteLine("Enter the student's last name: ");
string lastName = Console.ReadLine();
Console.WriteLine("Enter the student's birthday: ");
string birthDay = Console.ReadLine();
}
static void PrintStudentDetails(ref string first, ref string last, ref string birthday)
{
first = "test";
last = "test";
birthday = "test";
Console.WriteLine("{0} {1} was born on: {2}", first, last, birthday);
Console.ReadLine();
}
}
}
【问题讨论】:
-
这段代码甚至无法编译。
-
只返回一个带有名字/生日的小类?
-
您具体遇到了什么错误?
-
我要控制台写:
-
我想让控制台写 Enter the student's first name:..i.e."A"., , 然后 Enter the student last name..."B".. , 输入学生的生日.. “C”..然后打印用户填写的内容。例如:“A B出生于:C”但我无法连接这些变量。现在我得到“测试测试哇出生于:测试”。 (我用这个来测试它)