Which of the following can be generic?
classes
methods
properties
operator overloads
structs
enumerations
Extend the Vector class in Ch12Ex01 such that the * operator returns the dot product of two vectors.
Note | The dot product of two vectors is defined as the product of their magnitudes multiplied by the cosine of the angle between them. |
What is wrong with the following code? Fix it.
public class Instantiator<T> { public T instance; public Instantiator() { instance = new T(); } }
What is wrong with the following code? Fix it.
public class StringGetter<T> { public string GetString<T>(T item) { return item.ToString(); } }
Create a generic class called ShortCollection<T> that implements IList<T> and consists of a collection of items with a maximum size. This maximum size should be an integer that can be supplied to the constructor of ShortCollection<T>, or defaults to 10. The constructor should also be able to take an initial list of items via a List<T> parameter. The class should function exactly like Collection<T>, but throw an exception of type IndexOutOfRangeException if an attempt is made to add too many items to the collection, or if the List<T> passed to the constructor contains too many items.