注意在末尾添加逗号
var objs=new object[]{new People(),new People(),new People(),};
foreach (var item in objs)
{
Console.WriteLine(item.GetHashCode());
}
Car car = new Car() { Name = "W", Numbers = 10, };
Car[]cars = new Car[]{
new Car(){Name="Gan", Numbers=10,},
new Car(){Name="Quan",Numbers=20,},
new Car(){Name="Fu", Numbers=30,},
};
foreach (var item in cars)
{
//if (item.Name=="Gan")
//{
// continue;
//}
if (item.Name == "Gan")
{
break;
}
Console.WriteLine(item.Name);
}
//string strName = "gan,quan,fu";
//string[] names = strName.Split(new string[] { "," }, StringSplitOptions.None);
//foreach (string item in names)
//{
// Console.WriteLine(item);
//}
string strName = "gan,,fu";
string[] names = strName.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
foreach (string item in names)
{
Console.WriteLine(item);
}
//输出gan
// fu