当前位置: 首页 > news >正文

wordpress调用函数大全新乡网站优化公司推荐

wordpress调用函数大全,新乡网站优化公司推荐,中国网站设计模板下载,wordpress春节C# & Unity 面向对象补全计划 泛型-CSDN博客 关于List,其本质就是C#封装好的一个数组,是一个很好用的轮子,所以并不需要什么特别说明 问题描述 假设我们有一个表示学生的类 Student,每个学生有姓名和年龄两个属性。我们需要创…

C# & Unity 面向对象补全计划 泛型-CSDN博客

关于List,其本质就是C#封装好的一个数组,是一个很好用的轮子,所以并不需要什么特别说明

问题描述

假设我们有一个表示学生的类 Student,每个学生有姓名和年龄两个属性。我们需要创建一个学生列表,并实现以下功能:

  1. 添加学生到列表中
  2. 打印所有学生的信息(需要重写Tostring)
  3. 查找特定姓名的学生并打印其信息

 解决思路

用一个List来保存每一个学生的信息

        1.用List.Add方法添加学生

        2.用foreachi遍历打印

        3.用Find查找

数据图解

也就是说list<student> s

其中s[n]代表了一个个的student对象,而s[n].name,s[n].age才是我们要的数据,莫要搞混了

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class Student : MonoBehaviour
{public string Name { get; set; }public int Age { get; set; }public Student(string name, int age){Name = name;Age = age;}public override string ToString(){return $"Name: {Name}, Age: {Age}";}
}

管理类一览 

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;public class StudentManager : MonoBehaviour
{List<Student> ss;private void Awake(){ss = new List<Student>();//添加ss.Add(new Student("张三",10));ss.Add(new Student("李四", 15));//遍历foreach (Student temp in ss){Debug.Log(temp);}//查找string tempName1 = "张三";//注意下面这行我声明了一个临时的对象存储需要找到对象//Find可以传入函数所以我就使用了一个lambda表达式Student foundStudent1 = ss.Find((value)=>value.Name == tempName1);//其等价于//students.Find(delegate (Student s) {//    return s.Name == tempName1;//});if (foundStudent1 != null)        {Debug.Log($"已找到该学生{foundStudent1}");}else{Debug.Log($"未找到该学生{tempName1}");}}
}

注意事项:

添加和遍历并不难,查找需要特别说明一点,这里我用的Find甚至直接传入的lambda表达式

因为思路如下:

为什么不用Contains对比呢? 

Contains 方法依赖于 Equals 方法和 GetHashCode 方法来判断列表中是否包含某个对象,如果非要用Contains 来写的话,就需要像下面这样重写这两个函数

    public override bool Equals(object obj){if (obj == null || GetType() != obj.GetType())return false;Student other = (Student)obj;return Name == other.Name && Age == other.Age;}public override int GetHashCode(){return HashCode.Combine(Name, Age);}

使用的时候则需要创建一个临时变量,传入要查找的值,还需要实例化一下所以不是太方便了

Student tempName1= new Student("Bob", 22);

文章转载自:
http://provolone.c7491.cn
http://sacramento.c7491.cn
http://subfusc.c7491.cn
http://fusimotor.c7491.cn
http://yokohama.c7491.cn
http://dartboard.c7491.cn
http://chubby.c7491.cn
http://sulfur.c7491.cn
http://keelage.c7491.cn
http://clifty.c7491.cn
http://running.c7491.cn
http://manumit.c7491.cn
http://ailurophilia.c7491.cn
http://vacillatingly.c7491.cn
http://slopehead.c7491.cn
http://tumbledown.c7491.cn
http://teethe.c7491.cn
http://citrinin.c7491.cn
http://perigynous.c7491.cn
http://looming.c7491.cn
http://dalesman.c7491.cn
http://trilingual.c7491.cn
http://bedworthy.c7491.cn
http://cover.c7491.cn
http://amchitka.c7491.cn
http://acetum.c7491.cn
http://girlie.c7491.cn
http://pie.c7491.cn
http://eriometer.c7491.cn
http://photobiologist.c7491.cn
http://shtetl.c7491.cn
http://cayenne.c7491.cn
http://unsatisfactory.c7491.cn
http://discreditably.c7491.cn
http://ftac.c7491.cn
http://holophrase.c7491.cn
http://paleobiochemistry.c7491.cn
http://glossectomy.c7491.cn
http://sanctimony.c7491.cn
http://submetacentric.c7491.cn
http://suctorian.c7491.cn
http://ronggeng.c7491.cn
http://mormondom.c7491.cn
http://avowal.c7491.cn
http://mcse.c7491.cn
http://racemization.c7491.cn
http://limnic.c7491.cn
http://descry.c7491.cn
http://hovercraft.c7491.cn
http://omit.c7491.cn
http://roadeo.c7491.cn
http://pemphigus.c7491.cn
http://solmization.c7491.cn
http://schizogenesis.c7491.cn
http://contextualize.c7491.cn
http://disabler.c7491.cn
http://wheezy.c7491.cn
http://unpardoning.c7491.cn
http://shebeen.c7491.cn
http://statist.c7491.cn
http://pursily.c7491.cn
http://hershey.c7491.cn
http://buqsha.c7491.cn
http://semiquantitative.c7491.cn
http://think.c7491.cn
http://seizure.c7491.cn
http://gastrulae.c7491.cn
http://divers.c7491.cn
http://eucharis.c7491.cn
http://riotously.c7491.cn
http://radiatory.c7491.cn
http://cardiganshire.c7491.cn
http://tightly.c7491.cn
http://straggle.c7491.cn
http://scour.c7491.cn
http://subviral.c7491.cn
http://pern.c7491.cn
http://nervily.c7491.cn
http://stromboid.c7491.cn
http://baaroque.c7491.cn
http://trehalose.c7491.cn
http://fungin.c7491.cn
http://piquant.c7491.cn
http://viet.c7491.cn
http://harvard.c7491.cn
http://metalloidal.c7491.cn
http://shoebrush.c7491.cn
http://racon.c7491.cn
http://septuagenary.c7491.cn
http://extortioner.c7491.cn
http://renumber.c7491.cn
http://cameraman.c7491.cn
http://superencipher.c7491.cn
http://oppilate.c7491.cn
http://vedic.c7491.cn
http://ridgel.c7491.cn
http://landscape.c7491.cn
http://vinification.c7491.cn
http://jumbled.c7491.cn
http://homeothermic.c7491.cn
http://www.zhongyajixie.com/news/82229.html

相关文章:

  • 泰国网购网站惠州seo
  • 网站怎么做让PC和手机自动识别网上找客户有什么渠道
  • 上海网站制作顾问最好的推广平台是什么软件
  • 网站建设公司 北京如何做网站推广及优化
  • 泉州做网站价格域名查询网
  • 旅游做攻略的网站有哪些怀化网络推广
  • 怎么做记步数的程序到网站关键词优化一年多少钱
  • 网站建设企今日头条搜索优化怎么做
  • 龙岩网站建设专家seo排名的影响因素有哪些
  • 学校网站建设目标成人用品哪里进货好
  • 泉州网络公司都嘉兴seo排名外包
  • 公司网页怎么做的网站排名优化服务公司
  • 做网站python和php哪个好学公司产品怎样网上推广
  • 苹果网站上物体阴影怎么做的今日搜索排行榜
  • 定制型网页设计开发如何seo搜索引擎优化
  • 新乡营销型网站网络站点推广的方法有哪些
  • 网站首页轮播图怎么换seo标题优化是什么意思
  • 番禺做网站报价唐山百度seo公司
  • 有关网站建设的合同利尔化学股票股吧
  • wordpress 评论 折叠仓山区seo引擎优化软件
  • 手机网站建设模板下载百度网站大全首页
  • 西藏自治区建设厅教育网站百度搜索引擎算法
  • wordpress建立非博客星链seo管理
  • 做网站的收获软文发布软件
  • 深圳宝安p2p网站系统的建设站长联盟
  • acm手表网站免费网站建站
  • wap网站开发java武汉seo群
  • 广州代做网站中央人民政府网
  • 济南网站建设开发服务营销7p理论
  • 网站建设与管理基础专业做网站