locked
How to implement Find method RRS feed

  • Question

  • User-1129879462 posted

    How to implement Find method

    Monday, December 11, 2017 2:09 PM

All replies

  • User475983607 posted

    See if the following reference doc answers your question.

    https://msdn.microsoft.com/en-us/library/x0b5b5bc(v=vs.110).aspx

    Monday, December 11, 2017 2:43 PM
  • User-335504541 posted

    Hi krisrajz,

    How to implement Find method

    What do you want implement Find method to?

    If you want to implement to something like array list, you need to create a Predicate<T> Delegate for your match.

    For example:

        class Program
        {
            static void Main(string[] args)
            {            
                Point[] points = { new Point(100, 200),
                             new Point(150, 250), new Point(250, 375),
                             new Point(275, 395), new Point(295, 450) };
    
                // Define the Predicate<T> delegate.
                Predicate<Point> predicate = FindPoints;
    
                // Find the first Point structure for which X times Y  
                // is greater than 100000. 
                Point first = Array.Find(points, predicate);
    
                // Display the first structure found.
                Console.WriteLine("Found: X = {0}, Y = {1}", first.X, first.Y);
            }
            private static bool FindPoints(Point obj)
            {
                return obj.X * obj.Y > 100000;
            }
        }
        internal class Point
        {
            public int X { get; set; }
            public int Y { get; set; }
            public Point(int x, int y)
            {
                this.X = x;
                this.Y = y;
            }
        }

    You could refer to the links below for more information:

    https://msdn.microsoft.com/en-us/library/x0b5b5bc%28v=vs.80%29.aspx?f=255&MSPPError=-2147217396

    https://msdn.microsoft.com/en-us/library/bfcke1bz(v=vs.110).aspx

    Best Regards,

    Billy

    Tuesday, December 12, 2017 8:14 AM