问题遇到的现象和发生背景
将对象初始化之后可以输入但输出结果不正确
问题相关代码
using System;
namespace _5
{
class Program
{
static void Main(string[] args)
{
Citizen s = new Citizen();
s.Input();
s.Print();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace _5
{
class Citizen
{
public string name;
public string Name
{
get
{
return name;
}
}
public string gender;
public string Gender
{
get
{
return gender;
}
}
public string age;
public string Age
{
get
{
return age;
}
}
public string birthplace;
public string BirthPlace
{
get
{
return birthplace;
}
}
public string id;
public string Id
{
get
{
return id;
}
}
public string familyaddress;
public string FamilyAddress
{
get
{
return familyaddress;
}
}
public Citizen()
{
name = "David";
gender = "Male";
age = "20";
birthplace = "Nanyang,Henan";
id = "1000";
familyaddress = "0000";
}
public void Input()
{
Console.WriteLine("Please input your name:");
string a = Console.ReadLine();
Console.WriteLine("Please input your gender:");
string b = Console.ReadLine();
Console.WriteLine("Please input your age:");
string c = Console.ReadLine();
Console.WriteLine("Please input your birthplace:");
string d = Console.ReadLine();
Console.WriteLine("Please input your id:");
string e = Console.ReadLine();
Console.WriteLine("Please input your familyaddress:");
string f = Console.ReadLine();
}
public void Print()
{
Console.WriteLine("Your name is:{0}","a");
Console.WriteLine();
Console.WriteLine("Your gender is:{0}","b");
Console.WriteLine();
Console.WriteLine("Your age is:{0}","c");
Console.WriteLine();
Console.WriteLine("Your birthplace is:{0}","d");
Console.WriteLine();
Console.WriteLine("Your id is:{0}","e");
Console.WriteLine();
Console.WriteLine("Your familyaddress is:{0}","f");
Console.WriteLine();
}
}
}
运行结果及报错内容
Please input your name:
1
Please input your gender:
2
Please input your age:
3
Please input your birthplace:
4
Please input your id:
5
Please input your familyaddress:
6
Your name is:a
Your gender is:b
Your age is:c
Your birthplace is:d
Your id is:e
Your familyaddress is:f
我想要达到的结果
在主程序中调用s.Print 输出s. Input 中输入的值