第三章 集合
来源:互联网 发布:淘宝哪里申请信用卡 编辑:程序博客网 时间:2024/05/10 17:10
using System;using System.Collections;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace day_03{ class Program { static void Main(string[] args) { ForeachTest(); foreach (Book item in list) { item.BookAuthor = "yy"; if (item.BookAuthor.Equals("yy")) { item.BookAuthor = "yyy"; break; } } Console.WriteLine("===================修改==============="); foreach (Book item in list) { Console.WriteLine(item.BookAuthor); } } static ArrayList list = new ArrayList(); private static void ForeachTest() { Book book1=new Book("yy","xx",50); Book book2 = new Book("yyy", "xxx", 60); Book book3 = new Book("yyyy", "xxxx", 70); list.Add(book1); list.Add(book2); list.Add(book3); foreach (Book item in list) { Book book = (Book)item; Console.WriteLine(item.BookName); } } private static void ListBeginOneDemo() { //集合分类:单列集合+双列集合 ArrayList list = new ArrayList(); //添加一个元素 list.Add("张"); list.Add("李"); list.Add("凤"); //遍历 foreach (string item in list) { Console.WriteLine(item); } //修改,将凤 改成 宋 for (int i = 0; i < list.Count; i++) { if (list[i].Equals("凤")) { list[i] = "宋"; break; } } Console.WriteLine("修改后"); foreach (string item in list) { Console.WriteLine(item); } //按索引删除 Console.WriteLine("========================"); list.RemoveAt(0); foreach (string item in list) { Console.WriteLine(item); } //释放一个人 凤 list.Remove("凤"); Console.WriteLine("==================释放后======"); foreach (string item in list) { Console.WriteLine(item); } //i just make a joke .释放 所有人 list.Clear(); Console.WriteLine("==================释放所有======"); foreach (string item in list) { Console.WriteLine(item); } } }} using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace day_03{ class Book { public string BookName { get; set; } public string BookAuthor { get; set; } public int BookPrice { get; set; } public Book() { } public Book(string bookname, string bookauthor, int bookprice) { this.BookName = bookname; this.BookAuthor = bookauthor; this.BookPrice = bookprice; } }}
0 0
- 第三章 集合
- 黑马程序员 第三章:集合
- 第三章 双列集合
- 集合入门介绍第三章——Set集合
- 第三章:3.1 正交函数集合
- 第三周求集合
- TimesTen内存数据库-第三章 定义缓存集合
- swift入门第三章集合、控制流,标签语句
- 第三章 JAVA集合之ArrayList源码浅析
- 流程的Python 第三章:字典和集合
- 第二章模糊集合及其基本运算+第三章模糊集合的其他运算
- 深入理解Java集合框架系列-第三章 使用集合排序
- 常用第三方类库框架集合
- iOS第三方框架集合
- IOS第三方框架集合
- iOS第三方框架集合
- IOS第三方框架集合
- iOS第三方框架集合
- Python自学之is和‘==’的区别
- java实现蛇形矩阵
- shell读取文件中的内容
- linux下编译:单文件,多文件
- android中的几种基本布局
- 第三章 集合
- caffeImagenet相关
- 网络层:IP、IGMP、ICMP
- svm
- 特殊的质数肋骨
- 48.android服务service-启动远程服务
- 还在被“催婚”? 人工智能可能终结这类问题
- 线程也疯狂----线程同步(1)
- React开发环境搭建步骤