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
VulpesPosted May 6, 2012, 9:16 AM
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.
VulpesPosted May 7, 2012, 4:56 AM
In fact, if you don't need to know which items are duplicates, you could simplify the whole method to just this:
theLizardPosted May 6, 2012, 11:45 PM
No need to do this if (dupList.Count == 0) return; because if dupList count is 0 then it will fall through the loop test
Avuya MxoliPosted May 6, 2012, 11:52 AM