I want to go through all the properties of a type and want to check whether a property type is not a string, how can I do it ?
My class is:
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; } }
the code I am using to check for type is:
foreach (var property in typeof(MarkerInfo).GetProperties()) { if (property.PropertyType is typeof(string)) }
But this code is not working, any idea how to do that ?
You can call isdigit() on each character of the string, and if it's true for all characters you have an integer, otherwise it's some alphanumeric string. You can also call strtol to parse the string as an integer. The second argument returns a pointer to the first non-numeric character in the string.
Use the typeof operator to check if a variable is a string, e.g. if (typeof variable === 'string') . If the typeof operator returns "string" , then the variable is a string. In all other cases the variable isn't a string. Copied!
The C language does not have a specific "String" data type, the way some other languages such as C++ and Java do. Instead C stores strings of characters as arrays of chars, terminated by a null byte.
The C language does not provide an inbuilt data type for strings but it has an access specifier “%s” which can be used to directly print and read strings. You can see in the above program that string can also be read using a single scanf statement.
if (property.PropertyType == typeof(string))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With