Sometimes, we may need to convert from one type to another at Runtime, but where we don’t know the type in advance, in these situations we can use the Convert. ChangeType method
public void ConvertChangeType_Example()
{
Type targetType, convertedType;
object convertedValue, initialValue;
initialValue = "99";
targetType = typeof(int);
convertedValue = Convert.ChangeType(initialValue, targetType);
convertedType = convertedValue.GetType();
targetType = typeof(double);
convertedValue = Convert.ChangeType(initialValue, targetType);
convertedType = convertedValue.GetType();
}
I was very pleased to discover this website. I wanted to thank you for ones time due to this wonderful read!! I definitely loved every little bit of it and I have you saved as a favorite to check out new information on your blog.
It’s perfect time to make some plans for the longer term
and it is time to be happy. I’ve read this publish and if I may I want to counsel you some attention-grabbing
things or advice. Perhaps you can write subsequent articles regarding this article.
I desire to read more issues about it!