Bonjorno, people. Could you please explain me how to perform operations inside a generic method. I want a random array of different unsigned integers. IDE doesn't allow me to multiply a Double (and others) with a generic struct. Typecasting doesn't work in any way I try. Maybe I'd better just stop "designing a bicycle" and call from the generic method one of several method for each integer type?
public static T[] getRandArray<T>(int amount) where T: struct
{
FieldInfo maxValueField =
typeof(T).GetField(
"MaxValue",
BindingFlags.Public | BindingFlags.Static
);
T maxValueOfT = (T)maxValueField.GetValue(null);
Random randNum = new Random();
T[] array = new T[amount];
for (int i = 0; i < amount; i++)
{
array[i] = (T)(randNum.NextDouble()) * maxValueOfT;
}
return array;
}