The Convert class will help: value = (T)Convert.ChangeType(rawValue, typeof(T))
On Sat, Jun 4, 2011 at 10:40 AM, Greg Keogh <[email protected]> wrote: > Folks, in the tiny sample below I want to parse some text and set the > generic value, which will be int, double or long. The highlighted > statements show what I want to do, but how is it done in a generic way? > > > > Greg > > > > > > public class DemoClass<T> where T : struct > > { > > private T value; > > > > public void FromText(string rawValue) > > { > > value = double.Parse(rawValue); > > value = int.Parse(rawValue); > > } > > } > > > > >
