Having the following generic class that would contain either string, int, float, long as the type:
public class MyData
Just use an ArrayList and forget the MyData type.
ArrayList myStuff = getStuff();
float x = myStuff.OfType().First();
SomeMethod(x);
string s = myStuff.OfType().First();
SomeMethod(s);
The problem with MyData is that you're expecting the compiler to check a type that is only known at runtime. Compilers check types that are known at compile time.