zoukankan      html  css  js  c++  java
  • C# 遍历类为元素的列表

    using System;
    using System.Windows.Forms;
    using ClassLibrary2;
    using System.Collections.Generic;
    
    namespace messageshow
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                Adda();
            }
    
            private void listView1_SelectedIndexChanged(object sender, EventArgs e)
            {
            }
    
            
            
    
    
            public void Adda()
            {
    
                Class1 class1 = new Class1
                {
                    Text = "a",
                    Project = "b",
                    Object = "c",
                    Location = "d",
                    wRONGTYPE = Value.WRONGTYPE.WARNING
                };
    
                Class1 class2 = new Class1
                {
                    Text = "文本",
                    Project = "项目",
                    Object = "对象",
                    Location = "位置",
                    wRONGTYPE = Value.WRONGTYPE.WARNING
                };
    
    
                List<Class1> class1s = new List<Class1>
                {
                    class1,
                    class2
                };
    
                Value.Collection.Add(Value.WRONGTYPE.WARNING, class1s);
    
    
    
                // li.Text = "1";
                foreach (Class1 u in Value.Collection[Value.WRONGTYPE.WARNING])
                {
                    string[] sub = new string[]
                    {
                        "",
                        u.Text,
                       u.Project,
                        u.Object,
                        u.Location };
                    
                ListViewItem li;
                li = new ListViewItem(sub);
                    // 
                    this.listView3.Items.Add(li);
                }
                    
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ClassLibrary2
    {
        public static class Value
        {
            public enum WRONGTYPE
            {
                WRONG, WARNING
            }
    
            public static Dictionary<WRONGTYPE, List<Class1>> Collection = new Dictionary<WRONGTYPE, List<Class1>>();
            
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ClassLibrary2
    {
        public class Class1
        {
            public string Text;
            public string Project;
            public string Object;
            public string Location;
            public Value.WRONGTYPE wRONGTYPE;
        }
    }
  • 相关阅读:
    Redis与Memcached的incr/decr差异对比
    Linux sudo用法与配置
    Docker 常用命令
    Linux之间配置SSH互信(SSH免密码登录)
    SVN服务器搭建
    shell中参数的传递
    【代码更新】IIC协议建模——读写EEPROM
    串口完整项目之串口收发字符串
    串口发送模块——1字节数据发送
    状态机设计——从简单的按键消抖开始
  • 原文地址:https://www.cnblogs.com/yoyolm2014/p/9437959.html
Copyright © 2011-2022 走看看