To find a value in the list, you can use the loop traversal comparison to find the result. The find method is provided in C # and can be directly used as long as the search condition is passed in. As follows:
Class program {public static void main (string [] ARGs) {list <user> usercollection = new list <user> (); usercollection. add (new user (1, "testone"); usercollection. add (new user (2, "testtwo"); usercollection. add (new user (3, "testthree"); User resultuser = usercollection. find (delegate (User user) {// return user. userid = 0; return user. userid = 1 & user. username. equals ("testone") ;}); console. writ Eline (resultuser! = NULL? Resultuser. userid + system. environment. newline + resultuser. username: "Not Found"); console. readline () ;}} public class user {private int userid = 0; private string username = string. empty; Public int userid {get {return this. userid ;}} Public String username {get {return this. username ;}} public user (INT userid, string username) {This. userid = userid; this. username = username ;}}
Result: