你可以使用一個結構:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
struct Person{
public static FirstName;
public static LastName;
public static Birthday;
}
class Program
{
static void Main(string[] args)
{
Person person = ClientsDetails();
Print(person.FirstName, person.LastName, person.Birthday);
Console.ReadKey();
}
public static Person ClientsDetails()
{
Person returnValue = new Person();
Console.Write("Client's first name: ");
returnValue.FirstName = Console.ReadLine();
Console.Write("Client's last name: ");
returnValue.LastName = Console.ReadLine();
Console.Write("Client's birthdate: ");
returnValue.Birthday = Console.ReadLine();
return returnValue;
}
public static void Print(string first, string last, string birthday)
{
Console.WriteLine(String.Format("Client : {0} {1} was born on: {2}", first, last, birthday));
}
}
}
或數組:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string person = ClientsDetails();
Print(person[0], person[1], person[2]);
Console.ReadKey();
}
public static string[] ClientsDetails()
{
string[] returnValue = new string[3];
Console.Write("Client's first name: ");
returnValue[0] = Console.ReadLine();
Console.Write("Client's last name: ");
returnValue[1] = Console.ReadLine();
Console.Write("Client's birthdate: ");
returnValue[3] = Console.ReadLine();
return returnValue;
}
public static void Print(string first, string last, string birthday)
{
Console.WriteLine(String.Format("Client : {0} {1} was born on: {2}", first, last, birthday));
}
}
}
或引用(按引用傳遞):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string firstName, lastName, birthday;
ClientsDetails(ref firstName, ref lastName, ref birthday);
Print(firstName, lastName, birthday);
Console.ReadKey();
}
public static void ClientsDetails(ref string firstName, ref string lastName, ref string birthday)
{
Console.Write("Client's first name: ");
firstName = Console.ReadLine();
Console.Write("Client's last name: ");
lastName = Console.ReadLine();
Console.Write("Client's birthdate: ");
birthday = Console.ReadLine();
}
public static void Print(string first, string last, string birthday)
{
Console.WriteLine(String.Format("Client : {0} {1} was born on: {2}", first, last, birthday));
}
}
}
你可以多學習首先關於C#,它看起來像一個家庭作業r而不是一個特定的問題。 – Prisoner
您看起來像是閱讀課堂資料以及[Ask]或[faq] – Plutonix
Hello @Alex,我已經與Bob Tabor合作。感謝您的回覆 – Khalil