using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MethodsExceptions2
{
class Program
{
static void Main(string[] args)
{
GetStudentInformation();
PrintStudentDetails(firstName, lastName,birthDay);
Console.ReadKey();
}
static void GetStudentInformation()
{
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(string first, string last, string birthday)
{
Console.WriteLine("{0} {1} was born on: {2}", first, last, birthday);
}
}
}
如何在我的方法調用中輸入這些值?當我運行該程序時,該線在變量點中空白。我試圖用getStudentInfo
方法獲取用戶輸入,然後將其存儲在變量中,並將其輸入到printStudentInfo
方法中,以格式化並將其寫入控制檯。如何在調用方法時使用局部變量?
你發佈的代碼甚至無法編譯,所以我不知道你的意思是什麼_「當我運行該程序時,該行出現空白_」。你如何運行一個不能編譯的程序?最有可能的是,你的問題是幾百甚至上千個「我不知道局部變量和類變量之間的區別」的現有問題的重複,但是不可能確定地知道,因爲你的代碼例子不會做你說的那樣。 –