Hi All,
I just started learning generics and we were asked to create a generic method in a class that accepts an array and an individual object of the same type. The method should remove duplicates in the array and replace the duplicate with a with a default or elimination value represented by the second parameter. We then have to create an application that will implement this using 3 different types that have different lengths.
I've seen many ways of doing this but since I am still very new at this I don't know which one to apply to my problem. Any help will be appreciated.
Loading

VulpesRank #55 · 29.2K reputationPosted May 6, 2012, 5:16 AM EDT
As expected, the output is:
1 2 3 4 2 6 2 7 2 8
Notice that there's no need to specify 'int' as the type parameter when you call MyMethod because the compiler can infer this from the types of the arguments.
Avuya MxoliRank #7,940 · 231 reputationPosted May 6, 2012, 7:52 AM EDT
theLizardRank #1,079 · 1.8K reputationPosted May 6, 2012, 7:45 PM EDT
No need to do this if (dupList.Count == 0) return; because if dupList count is 0 then it will fall through the loop test
VulpesRank #55 · 29.2K reputationPosted May 7, 2012, 12:56 AM EDT
In fact, if you don't need to know which items are duplicates, you could simplify the whole method to just this: