Я хочу напечатать значения из метода GetStudentInformation() с помощью метода PrintStudentDetails (строка first, string last, string birthday). Пожалуйста, просмотрите приведенный ниже код:Как напечатать несколько значений в методе 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
, любая помощь или руководство будут высоко оценены.
С уважением
использовать свойства вместо локальной переменной –