技术:熟练String 类的Format()方法
代码:
class Program { static void Main(string[] args) { string name; int sex; string age; int height; string xuexing; string star; string favfood; Console.WriteLine("请输入你的姓名:"); name=Console.ReadLine(); Console.WriteLine("请输入你的姓别(1代表男,2代表女):"); sex =int.Parse( Console.ReadLine()); if (sex ==1) { Console.WriteLine("男"); } else if (sex == 2) { Console.WriteLine("女"); } else { Console.WriteLine("请重新输入:"); sex = int.Parse(Console.ReadLine()); } Console.WriteLine("请输入你的出生年月:"); age=Console.ReadLine(); Console.WriteLine("请输入你的身高(cm):"); height = int.Parse(Console.ReadLine()); Console.WriteLine("请输入你的血型:"); xuexing = Console.ReadLine(); Console.WriteLine("请输入你的星座:"); star = Console.ReadLine(); Console.WriteLine("请输入你最爱的食物:"); favfood = Console.ReadLine(); string record = string.Format("这是你的个人档案:\n姓名:{0}\n性别:{1}\n出生年月:{2}\n身高:{3}\n血型:{4}\n星座{5}\n最喜欢的食物{6}\n", name,sex,age,height,xuexing,star,favfood); Console.WriteLine(record); Console.ReadLine(); } }