【发布时间】:2016-10-19 11:01:01
【问题描述】:
您好,我正在尝试在输出中显示列表,但在打印列表项时遇到问题。这是我的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace educationsystem
{
public class student
{
public string name { get;set;}
public string lastname {get;set;}
public long phone {get;set;}
}
class Program
{
static void Main(string[] args)
{
List<student> Students = new List<student>();
Students.Add(new student {
name = "mahta",
lastname = "sahabi",
phone = 3244
});
Students.Add(new student {
name = "niki",
lastname = "fard",
phone = 5411
});
Students.Add(new student {
name = "hana",
lastname = "alipoor",
phone = 6121
});
foreach(student students in students)
Console.WriteLine(name+" "+lastname+" "+phone);
Console.ReadKey();
}
}
}
我希望输出像 第3244章 尼基法德 5411 . . . 我该怎么办?
【问题讨论】:
-
您在打印输出时没有引用“学生”,只是引用它的属性。此外,您还写了“foreach(学生中的学生)”。这是一个错字吗?实际上应该是“学生中的学生”?