当前位置:网站首页>Unity list uses find or findall to find specific elements and the number of specific elements
Unity list uses find or findall to find specific elements and the number of specific elements
2022-04-22 05:23:00 【Vegetable code farmer lemon brother】
In the development process , Sometimes it needs to be in List Find a specific element in , Now we can use List Of Find Method to implement , Examples are as follows :
1. First we define a Student Class to simulate the class we need , Every student He has his student number (Number) And last name (LastName).
public class student
{
public int Number;
public string LastName;
}
2. Create a script , Statement Students by List, And declare a few student stay List in .
private List<student> Students = new List<student>()
{
new student(){
Number = 01,LastName = "Li"},
new student(){
Number = 02,LastName = "Wang"},
new student(){
Number = 03,LastName = "Wang"},
}
3. When calling a method , Use Find To find the student number 1 Of student
student student01 = Students.Find(s=> s.Number == 01);
Debug.log(student01.LastName);
At this time, the printed result is “Li”, It shows that we have successfully used... In the list Find The element was found by looking up its attribute .
4. So next , We can use FindAll Search for LastName by “Wang” Number of students .
int Count = Students.FindAll(s=> s.LastName =="Wang").Count;
Debug.log(Count);
At this time, the printed result is “2”, It shows that we have successfully used... In the list FindAll Find out the number of elements with specific attributes .
版权声明
本文为[Vegetable code farmer lemon brother]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210621162295.html
边栏推荐
- What are the challenges of Internet of things testing, and how do software testing institutions ensure quality
- Three paging query methods of SQL Server
- Keil-C51 与 Keil -ARM 共存的方法
- Mongodb experiment -- data backup and recovery and database optimization
- Codeforces Round #781 (Div. 2) ABCD
- Apache poi HSSF operation Excel
- Western dichotomy and Eastern trisection
- Mysql database for the 11th time
- abcabc
- Batch resolves the IP address of the domain name and opens the web page
猜你喜欢
![[C] file operation](/img/fd/ddf94b0ffa743f2288f723a263a045.png)
[C] file operation

Leetcode 1557. Minimum number of vertices to reach all nodes

MySQL数据库第十一次

Unity built-in terrain optimization

Keil-C51 与 Keil -ARM 共存的方法

2021-10-17

Feign calls the service, and the called service Seata transaction is not opened or XID is empty

Vs2019 official free print control

Idea 2021.1 Useful settings

abcabc
随机推荐
Sourcetree version backtracking and single change version backtracking
Von Neumann architecture
Interpreter mode (3.7-3.13)
Strategy mode (2.28-3.6)
After the MySQL database runs the code, the question mark is displayed in Chinese?
How to modify the IP address of the rancher server
Usage of swagger and common annotation explanation
Dynamic programming -- lc474 One and zero
Leetcode 1423. Maximum points you can obtain from cards
Access denied for user 'root' @ '% MySQL problem (solved)
Nodejs link redis
[C #] implementation scheme of singleton mode
String and byte [] turn to each other
Multi level cache architecture for 100 million traffic
Mysql database for the 11th time
Machine learning -- under fitting, over fitting and regularization
The chain of implicit trust: an analysis of the web third party resources loading
【高通SDM660平台】(8) --- Camera MetaData介绍
[WPF] use ellipse or rectangle to make circular progress bar
Codeforces Round #781 (Div. 2) ABCD