I have an input string which could be int,string,float or any of the data type.
Now I want to do some thing like:
string stringType= "Int";
Type dataType = Type.GetType(stringType);
string someValue = 20;
int newValue = (dataType)someValue ;
Edit:
I will receive both type and value as string and need to cast them run time.
public void StoreWorkData(List<TypeAndvalue> workDataPropertyDetails)
{
foreach (var property in workDataPropertyDetails)
{
string stringType = property.dataType;
//Want to create the type in run time
Type dataType = Type.GetType(stringType);
//Assign the value to type created above
dataType newValue = (dataType)property.Value;
}
}
switchstatement.Convertclass, anyway.object(which may be simply the reality of what you're trying to do here).