c# - How implement own HashSet contains method -



c# - How implement own HashSet contains method -

i have hahset collection of int[9] arrays , want know if hashse contains array. example

hashset<int[]> set = new hashset<int[]>(); int[] a=new int[9]{1,2,3,4,5,6,7,8,9}; set.add(a); int[] a2=new int[9]{1,2,3,4,5,6,7,8,9}; if(!set.contains(a2)) set.add(a2);

how can override or implement own equals method hastset.contains behave arrays.sequenceequals?

you need provide implementation of iequalitycomparer<int[]>, , utilize constructor takes custom comparer:

class myeqcmpforint : iequalitycomparer<int[]> { public bool equals(int[] a, int[] b) { ... } public int gethashcode(int[] data) { ... } } hashset<int[]> set = new hashset<int[]>(new myeqcmpforint());

c#

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -