View Single Post
  #4 (permalink)  
Old February 16th, 2015, 05:33 PM
mmorgan30 mmorgan30 is offline
Friend of Wrox
 
Join Date: Feb 2014
Posts: 136
Thanks: 1
Thanked 10 Times in 10 Posts
Default

The method although defined in a manor to be generic is not the proper use of generics. Had you taken a look and read the link l supplied you might have realized it, an yes you could have implemented your code using a object as the type parameter and you have accomplished the same thing.


A true sln for a generic method would have been something like

Code:
public int Search<T>(T value)
{
     var rVal = -1;

      for( int i = 0; genericArray.Length; i++ )
      {
            if( genericArray[I].CompareTo(value) == 0 )
                 rVal = i;
       }

      return rVal;
}

Where of course the genericArray is define a generic like T[] genericArray

You did define the your method with generic notation but you did not implement any generic about you class. Which is where you get the 5 point.

Try read the link that posted.