我想通過PrintStudentDetails(字符串優先,字符串最後,字符串生日)方法從GetStudentInformation()方法打印值。請查看下面的代碼:如何在C#方法中打印多個值?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Module3_HomeWork
{
class Program
{
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 birthdate: ");
DateTime birthdate = Convert.ToDateTime(Console.ReadLine());
Console.WriteLine("Enter the student's address line 1: ");
string add1 = Console.ReadLine();
Console.WriteLine("Enter the student's address line 2: ");
string add2 = Console.ReadLine();
Console.WriteLine("Enter the student's city: ");
string city = Console.ReadLine();
Console.WriteLine("Enter the student's state: ");
string state = Console.ReadLine();
Console.WriteLine("Enter the student's zip code: ");
int zip = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the student's country: ");
string country = Console.ReadLine();
}
static void PrintStudentDetails(string first, string last, string birthday)
{
Console.WriteLine("{0} {1} was born on: {2}", first, last, birthday);
}
static void Main(string[] args)
{
GetStudentInformation();
PrintStudentDetails(first, last, birthday);
}
public static string first { get; set; }
public static string last { get; set; }
public static string birthday { get; set; }
}
}
如何使用只有方法而不是類打印值?我研究了它,發現了大約out
和ref
,任何幫助或指導將不勝感激。
問候
使用屬性而不是局部變量 –