📅  最后修改于: 2022-03-11 14:49:07.194000             🧑  作者: Mango
using System;
using System.Collections.Generic;
namespace ConsoleApp5
{
class Program
{
static void Main(string[] args)
{
var obj = new Class1();
obj.Test();
}
}
public class Class1
{
public void Test()
{
var myList = new List();
myList.Add(new MyObject { Id = 1, Name = "ZZZ" });
myList.Add(new MyObject { Id = 2, Name = "NNN" });
myList.Add(new MyObject { Id = 3, Name = "PPP" });
myList.Add(new MyObject { Id = 4, Name = "AAA" });
foreach (var obj in myList)
{
Console.WriteLine($"{obj.Name} -> {obj.Id}");
}
}
public class MyObject
{
public int Id { get; set; }
public string Name { get; set; }
}
}
}