📜  创建一个包含 3 个订单的列表 c# 代码示例

📅  最后修改于: 2022-03-11 14:49:07.194000             🧑  作者: Mango

代码示例1
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; }

        }
    }
}