C # list collection Add and find elements

Source: Internet
Author: User

This question comes from a community question and should be found using the Find method rather than contains

Using System;
Using System.Collections.Generic;
Using System.Text;

Namespace ConsoleApplication7
... {
Class Program
... {
static void Main (string[] args)
... {
list<int[]> alschedule = new list<int[]> ()//Declaration of a collection of int[] elements
Alschedule.add (new int[) ... {1, 2, 3});
Alschedule.add (new int[) ... {1, 2, 3, 4});
Int[] result = Alschedule.find (findelements);
if (Result!= null)
... {
Console.WriteLine (result);
}
Console.read ();
}
private static bool Findelements (int[] arrint)
... {
Return Isequals (Arrint, new int[] ... {1, 2, 3});
}
public static bool Isequals (array array1, array array2)
... {
Whether the comparison type is the same
if (! Object.referenceequals (array1. GetType (), Array2. GetType ()))
... {
return false;
}

Compare whether the length is the same
if (array1. GetLength (0)!= array2. GetLength (0))
... {
return false;
}

Compare whether members correspond equal
ValueType V1, v2;
for (int i = 0; i < array1. GetLength (0); i++)
... {
V1 = (valuetype) array1. GetValue (i);
V2 = (valuetype) array2. GetValue (i);

if (!v1. Equals (v2))
... {
return false;
}
}
return true;
}

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.