C # traverse struct and enumerate

Source: Internet
Author: User

C # traverse struct

            Type type = typeof(Color);            PropertyInfo[] fields = type.GetProperties();            //FieldInfo[] fields =type.GetFields(System.Reflection.BindingFlags.Public|System.Reflection.BindingFlags.Static);            int i = 30;            panel1.Controls.Clear();            foreach (PropertyInfo f in fields)            {                if (f.ToString().IndexOf(".Color ") > 0)                {                    Button btn = new Button();                    btn.BackColor = Color.FromName(f.Name);                    btn.Text = f.Name;                    btn.Location = new Point((i % 10) * 125, 10 + (i / 10) * 30);                    //btn.AutoSize = true;                    btn.Width = 120;                    i++;                    panel1.Controls.Add(btn);                }            }

C # traversal Enumeration

The enum class can be used for getnames and getvalues. For example, the windowstate enumeration foreach (string s in Enum. getnames (this. windowstate. getType () label1.text + = (S + "\ r \ n"); foreach (int I in Enum. getvalues (this. windowstate. getType () label1.text + = (I. tostring () + "\ r \ n ");

Sometimes the enumerated value cannot be obtained through getvalues. Because the enumerated values are of the int type, you can obtain the following values:

(INT) enum. getnames (this. windowstate. GetType () [0];

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.