How to check if a type is a string in C #?

I want to view all the properties of a type and want to check if the property type is not a string, how can I do this?

My class:

 public class MarkerInfo
    {
        public string Name { get; set; }
        public byte[] Color { get; set; }
        public TypeId Type { get; set; }
        public bool IsGUIVisible { get; set; }

        public MarkerInfo()
        {
            Color = new byte[4]; // A, R, G, B
            IsGUIVisible = true;
        }
    }

and the code that I use for type checking is:

 foreach (var property in typeof(MarkerInfo).GetProperties())
            {               

                if (property.PropertyType is typeof(string))              
            }

But this code does not work, any idea how to do this?

+5
source share
3 answers
if (property.PropertyType == typeof(string))
+19
source

use ==, not isor is String(leave type)

+2
source

Use the following instead:

    foreach (var property in typeof(MarkerInfo).GetProperties())
    {               
        if (property.PropertyType == typeof(string))              
    }
+2
source

All Articles