I am trying to finish a practical question from a book about generics, but the question does not make sense to me. Here it is.
Create two classes with the same functionality. Use generics for the first class and pass the second class to object types. Create a for loop that uses a class and an object-based class to determine what works best.
I'm not sure what this means by going over to types of objects. Here is my code so far
class Person<T> {
T var1;
public Person(T yer) {
var1 = yer;
}
public T Value { get { return var1; } }
}
class Human {
int var1;
public Human(int yer) {
var1 = yer;
}
public int Value { get { return var1; } }
}
My main looping program
for (int i = 0; i < 1000000; i++) {
Person<int> me = new Person<int>(1);
int hey = me.Value;
}
for (int i = 0; i < 1000000; i++) {
Human per = new Human(1);
object her = (object)per.Value;
}
I don’t know if I will do it right. Help me please: -)
source
share