close
class Program
{
static void Main(string[] args)
{
List<Cat> Cats = new List<Cat>
{
new Cat(){Name="aaa",Age=18},
new Cat(){Name="bbb",Age=11},
null
};
foreach (Cat c in Cats)
{
if (c != null)
{
Console.WriteLine(c.Name);
}
else
{
Console.WriteLine("null");
}
}
Console.ReadLine();
}
}
class Cat
{
public int Age { get; set; }
public string Name { get; set; }
}
結果:
全站熱搜
留言列表