I want to write a function which will return FontStyle and take string as Parameter
FontStyle f = function ("Italic"); // FontStyles.Italic
I don't want to write Switch case or if else statements to do the same.
Can it be done for case insensitive strings?
FontStyle f = function ("italic");
FontStyle f = function ("itAlic");
should return same.
In C# it is just an enumeration. So you can convert it like this:
FontStyle f = (FontStyle)Enum.Parse(typeof(FontStyle), "Italic", true);
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