Contains with string value and IEqualityComparer : Contains : LINQ C# Source Code


Custom Search

C# Source Code » LINQ » Contains »

 

Contains with string value and IEqualityComparer








    
 

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MyStringifiedNumberComparer : IEqualityComparer<string> {
    public bool Equals(string x, string y) {
        return (Int32.Parse(x) == Int32.Parse(y));
    }

    public int GetHashCode(string obj) {
        return Int32.Parse(obj).ToString().GetHashCode();
    }
}
public class MainClass {
    public static void Main() {
        string[] stringifiedNums = {"001", "49", "017", "0080", "00027", "2" };
        bool contains = stringifiedNums.Contains("000271",new MyStringifiedNumberComparer());
        Console.WriteLine(contains);
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo LINQ
» Contains