得到以下代码,给出了预期'
的第一个错误试图获取并打印学生数据。不确定我是否需要使这些方法像返回类型或其他东西。欢迎任何建议,谢谢。
namespace studentInfo
{
class Program
{
static void Main(string[] args)
{
getUserInformation();
printStudentDetails(string firstName, string lastName, string birthday);
}
static void getUserInformation()
{
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 your bithdate");
//DateTime birthdate = Convert.ToDateTime(Console.ReadLine());
string birthday = Console.ReadLine();
}
static void printStudentDetails(string firstName, string lastName, string birthday)
{
Console.WriteLine("{0} {1} was born on: {2}", firstName, lastName, birthday);
Console.ReadLine();
}
}
}
答案 0 :(得分:5)
您正在调用方法:
#include <QApplication>
#include <QHBoxLayout>
#include <QSlider>
#include <QSpinBox>
int main(int argc, char *argv[]){
QApplication app(argc, argv);
QWidget *window = new QWidget;
window->setWindowTitle("select your age");
QSlider *slider = new QSlider(Qt::Horizontal);
QSpinBox *spin = new QSpinBox;
slider->setRange(0, 130);
spin->setRange(0, 130);
QObject::connect( spin, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)) );
QObject::connect( slider, SIGNAL(valueChanged(int)), spin, SLOT(setValue(int)) );
spin->setValue(30);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget(spin);
layout->addWidget(slider);
window->setLayout(layout);
window->show();
return app.exec();
}
应该是:
printStudentDetails(string firstName, string lastName, string birthday);
在将vars传递给方法之前,您还必须定义vars,firstName,lastName,birthday。
答案 1 :(得分:2)
你做错了队友!
您只需要变量来调用方法..您不需要其数据类型。
所以应该是这样的: -
printStudentDetails(firstName, lastName, birthday);
如果你想使用像这样的变量,那么将它们全局声明为: -
public static dynamic firstName;
public static dynamic lastName;
public static dynamic birthday;
static void Main(string[] args)
{
getUserInformation();
printStudentDetails(firstName, lastName, birthday);
}
static void getUserInformation()
{
Console.WriteLine("Enter the student's first name: ");
firstName = Console.ReadLine();
Console.WriteLine("Enter the student's last name");
lastName = Console.ReadLine();
Console.WriteLine("Enter your bithdate");
birthday = Console.ReadLine();
}
static void printStudentDetails(string firstName, string lastName, string birthday)
{
Console.WriteLine("{0} {1} was born on: {2}", firstName, lastName, birthday);
Console.ReadLine();
}