zoukankan      html  css  js  c++  java
  • C#从列表中取元素的某个字段组成新的列表

    using System;
    using System.Collections.Generic;
    using System.Linq;
    
    namespace CSharpDemo
    {
        class Program
        {
            static void Main(string[] args)
            {
                List<TestClass> MyList = new List<TestClass>();
                MyList.Add(new TestClass("AAA"));
                MyList.Add(new TestClass("BBB"));
                MyList.Add(new TestClass("CCC"));
    
                var items = from n in MyList select n.Name;
    
                foreach (var item in items)
                {
                    Console.WriteLine(item);
                }
    
                var value = string.Join(",", items);
                Console.WriteLine(value);
    
                Console.Write("请按任意键继续. . .");
                Console.ReadKey(true);
            }
    
            public class TestClass
            {
                public string Name;
    
                public TestClass(string name)
                {
                    Name = name;
                }
            }
        }
    }
  • 相关阅读:
    3-2
    3-1
    2-11
    2-10
    2-7
    2-9
    springboot 使用undertow代替tomcat容器提高吞吐量
    springboot—JVM性能参数调优
    springbootDay3
    springboot_Mybaits_PageHelper
  • 原文地址:https://www.cnblogs.com/wzwyc/p/7372368.html
Copyright © 2011-2022 走看看