Can one search for a Needle in a Hay Stack in C#?
No.
Needle FindNeedleInHayStack(Needle needle) {
return Stack<Hay>.Search(needle);
}
Stack is a Generic class, and where the Type is Hay, it would not be possible to add an object of Type Needle unless both inherited fom the same base class. If both inherited from object, it would be a Stack of objects (Stack<object>) and therefore could quite easily have no Hay in it at all, or have more Needles than Hay.
In the case of the Stack<T> (its generic notation), the Search function would either have to throw an exception or return null when faced with an object of a Type other than the Type of the Class.
To search a Stack of Hay for an object of type Needle would be completely pointless.
C# thoughts
(1) | by madkat on January 9th, 2008
loading
