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

List<T>属性和方法使用

//@author:shark_ddd
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;//使用函数来减少长度namespace List_T
{class Student{public string Name { get; set; }public int Age { get; set; }}internal class Program{static void PrintStudents(List<Student> students){foreach (Student student in students){Console.Write("Name:" + student.Name);Console.WriteLine(", Age:" + student.Age);}}static void PrintNumbers(List<int> numbers){foreach (int number in numbers){Console.Write(" " + number);}Console.WriteLine();}static void PrintStrings(List<string> strings){foreach (string str in strings){Console.Write(" " + str);}Console.WriteLine();}static void Main(string[] args){List<Student> studentList = new List<Student>{new Student { Name = "Alice", Age = 20 },new Student { Name = "Ben", Age = 18 },new Student { Name = "Clark", Age = 18 }};Console.WriteLine("Students:");PrintStudents(studentList);Console.WriteLine("=================================================================================");// 创建数字列表List<int> numberList = new List<int> { 1, 2, 3, 4, 5 };// 在数字列表末尾加入 6numberList.Add(6);// 在数字列表末尾加入 7、8、9numberList.AddRange(new List<int> { 7, 8, 9 });Console.WriteLine("now_List:");PrintNumbers(numberList);// 获取数字列表中的所有偶数List<int> evenNumbers = numberList.FindAll(n => n % 2 == 0);Console.WriteLine("获取的偶数有:");PrintNumbers(evenNumbers);// 删除数字列表中的 9numberList.Remove(9);Console.WriteLine("now_List:");PrintNumbers(numberList);// 删除数字列表中索引为 0 的元素numberList.RemoveAt(0);Console.WriteLine("now_List:");PrintNumbers(numberList);// 打印第一个Console.WriteLine("First_number:" + numberList.First());Console.WriteLine("=================================================================================");// 水果列表List<string> fruitList = new List<string> { "apple", "banana", "cherry" };// 在索引为 1 的位置插入 orangefruitList.Insert(1, "orange");Console.WriteLine("now_Fruit:");PrintStrings(fruitList);// 复制水果列表从索引 0 开始的两个元素到 myFruit 数组中,并从数组的索引 0 开始存入string[] myFruit = new string[2];fruitList.CopyTo(0, myFruit, 0, 2);Console.WriteLine("myFruit:");Console.WriteLine(string.Join(" ", myFruit));// 复制水果列表从索引 1 开始的三个元素到 subList 中List<string> subList = fruitList.GetRange(1, 3);Console.WriteLine("subList:");PrintStrings(subList);// 翻转水果列表元素排序顺序fruitList.Reverse();Console.WriteLine("now_Fruit:");PrintStrings(fruitList);// 对水果列表元素进行排序fruitList.Sort();Console.WriteLine("now_Fruit:");PrintStrings(fruitList);// 清空水果列表fruitList.Clear();Console.WriteLine("now_Fruit:");PrintStrings(fruitList);Console.ReadLine();}}
}//转换成字符串string.Join
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;//namespace List_T
//{
//    class Student
//    {
//        public string Name { get; set; }
//        public int Age { get; set; }
//    }//    internal class Program
//    {
//        static void Main(string[] args)
//        {
//            List<Student> studentList = new List<Student>
//            {
//                new Student { Name = "Alice", Age = 20 },
//                new Student { Name = "Ben", Age = 18 },
//                new Student { Name = "Clark", Age = 18 }
//            };//            Console.WriteLine("Students: " + string.Join(", ", studentList.Select(s => $"Name:{s.Name}, Age:{s.Age}")));//            Console.WriteLine("=================================================================================");//            // 创建数字列表
//            List<int> numberList = new List<int> { 1, 2, 3, 4, 5 };//            // 在数字列表末尾加入 6
//            numberList.Add(6);//            // 在数字列表末尾加入 7、8、9
//            numberList.AddRange(new List<int> { 7, 8, 9 });//            Console.WriteLine("now_List: " + string.Join(" ", numberList));//            // 获取数字列表中的所有偶数
//            List<int> evenNumbers = numberList.FindAll(n => n % 2 == 0);
//            Console.WriteLine("获取的偶数有: " + string.Join(" ", evenNumbers));//            // 删除数字列表中的 9
//            numberList.Remove(9);
//            Console.WriteLine("now_List: " + string.Join(" ", numberList));//            // 删除数字列表中索引为 0 的元素
//            numberList.RemoveAt(0);
//            Console.WriteLine("now_List: " + string.Join(" ", numberList));//            // 打印第一个
//            Console.WriteLine("First_number:" + numberList.First());//            Console.WriteLine("=================================================================================");//            // 水果列表
//            List<string> fruitList = new List<string> { "apple", "banana", "cherry" };//            // 在索引为 1 的位置插入 orange
//            fruitList.Insert(1, "orange");
//            Console.WriteLine("now_Fruit: " + string.Join(" ", fruitList));//            // 复制水果列表从索引 0 开始的两个元素到 myFruit 数组中,并从数组的索引 0 开始存入
//            string[] myFruit = new string[2];
//            fruitList.CopyTo(0, myFruit, 0, 2);
//            Console.WriteLine("myFruit: " + string.Join(" ", myFruit));//            // 复制水果列表从索引 1 开始的三个元素到 subList 中
//            List<string> subList = fruitList.GetRange(1, 3);
//            Console.WriteLine("subList: " + string.Join(" ", subList));//            // 翻转水果列表元素排序顺序
//            fruitList.Reverse();
//            Console.WriteLine("now_Fruit: " + string.Join(" ", fruitList));//            // 对水果列表元素进行排序
//            fruitList.Sort();
//            Console.WriteLine("now_Fruit: " + string.Join(" ", fruitList));//            // 清空水果列表
//            fruitList.Clear();
//            Console.WriteLine("now_Fruit: " + string.Join(" ", fruitList));//            Console.ReadLine();
//        }
//    }
//}    /*冗长的foreach
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace List_T
{class Student{public string Name { get; set; }public int Age { get; set; }}internal class Program{static void Main(string[] args){List<Student> studentList = new List<Student>{new Student { Name = "Alice", Age = 20 },new Student { Name = "Ben", Age = 18 },new Student { Name = "Clark", Age = 18 }};foreach (Student student in studentList){Console.Write("Name:" + student.Name);Console.WriteLine(",  Age:" + student.Age);}Console.WriteLine("=================================================================================");// 创建数字列表List<int> numberList = new List<int> { 1, 2, 3, 4, 5 };// 在数字列表末尾加入 6numberList.Add(6);// 在数字列表末尾加入 7、8、9numberList.AddRange(new List<int> { 7, 8, 9 });Console.Write("now_List:");foreach (int number in numberList){Console.Write(" " + number);}Console.WriteLine();// 获取数字列表中的所有偶数List<int> evenNumbers = numberList.FindAll(n => n % 2 == 0);Console.Write("获取的偶数有:");foreach (int number in evenNumbers){Console.Write(" " + number);}Console.WriteLine();// 删除数字列表中的 9numberList.Remove(9);Console.Write("now_List:");foreach (int number in numberList){Console.Write(" " + number);}Console.WriteLine();// 删除数字列表中索引为 0 的元素numberList.RemoveAt(0);Console.Write("now_List:");foreach (int number in numberList){Console.Write(" " + number);}Console.WriteLine();//打印第一个Console.WriteLine("First_number:" + numberList.First());Console.WriteLine("=================================================================================");// 水果列表List<string> fruitList = new List<string> { "apple", "banana", "cherry" };// 在索引为 1 的位置插入 orangefruitList.Insert(1, "orange");Console.Write("now_Fruit:");foreach (string number in fruitList){Console.Write(" " + number);}Console.WriteLine();// 复制水果列表从索引 0 开始的两个元素到 myFruit 数组中,并从数组的索引 0 开始存入string[] myFruit = new string[2];fruitList.CopyTo(0, myFruit, 0, 2);Console.Write("myFruit:");foreach (string number in myFruit){Console.Write(" " + number);}Console.WriteLine();// 复制水果列表从索引 1 开始的三个元素到 subList 中List<string> subList = fruitList.GetRange(1, 3);Console.Write("subList:");foreach (string number in subList){Console.Write(" " + number);}Console.WriteLine();// 翻转水果列表元素排序顺序fruitList.Reverse();Console.Write("now_Fruit:");foreach (string number in fruitList){Console.Write(" " + number);}Console.WriteLine();// 对水果列表元素进行排序fruitList.Sort();Console.Write("now_Fruit:");foreach (string number in fruitList){Console.Write(" " + number);}Console.WriteLine();// 清空水果列表fruitList.Clear();Console.Write("now_Fruit:");foreach (string number in fruitList){Console.Write(" " + number);}Console.WriteLine();Console.ReadLine();}}
}*/

相关文章:

List<T>属性和方法使用

//author&#xff1a;shark_ddd using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;//使用函数来减少长度namespace List_T {class Student{public string Name { get; set; }public int Age { get; set; …...

记一次:使用使用Dbeaver连接Clickhouse

前言&#xff1a;使用了navicat连接了clickhouse我感觉不太好用&#xff0c;就整理了一下dbeaver连接 0、使用Navicat连接clickhouse 测试连接 但是不能双击打开&#xff0c;可是使用命令页界面&#xff0c;右键命令页界面&#xff0c;然后可以用sql去测试 但是不太好用&#…...

Java面向对象编程进阶(四)

Java面向对象编程进阶&#xff08;四&#xff09; 一、equals()方法的使用二、toString()方法的使用三、复习 一、equals()方法的使用 适用性&#xff1a;任何引用数据都可以使用。 自定义的类在没有重写Object中equals()方法的情况下&#xff0c;调用的就是Object类中声明的…...

【51单片机】第一个小程序 —— 点亮LED灯

学习使用的开发板&#xff1a;STC89C52RC/LE52RC 编程软件&#xff1a;Keil5 烧录软件&#xff1a;stc-isp 开发板实图&#xff1a; 文章目录 单片机介绍LED灯介绍练习创建第一个项目点亮LED灯LED周期闪烁 单片机介绍 单片机&#xff0c;英文Micro Controller Unit&#xff0…...

如何通过自动化有效地简化 Active Directory 操作?

我们都知道规模稍微大一点的企业为了便于计算机的管理&#xff0c;基本都上了微软的AD域控制器。 那么肯定就会存在这么一个问题&#xff0c; 不断的会有计算机加入或者是退出域控制器&#xff0c;批量的创建、修改、删除AD域用户&#xff0c;如果企业的架构需要改变&#xff…...

Java-POI导出EXCEL(动态表头)

1、主要功能 导出excel&#xff0c;表头有固定的和动态的。动态表头之间不能穿插固定表头。 2、使用方法 引入下方两个工具类&#xff0c;定义excel固定表头类。调用方法即可。 调用方法&#xff1a; ExcelDynamicHeader<MajorNameChangeReport> ledgerSafetyProblemEx…...

利用 Direct3D 绘制几何体—9.流水线状态对象

到目前为止展示过编写输入布局描述、创建顶点着色器和像素着色器&#xff0c;以及配置光栅器状态组这 3 个步骤。接下来讲如何将这些对象绑定到图形流水线上&#xff0c;用以实际绘制图形。大多数控制图形流水线状态的对象被统称为流水线状态对象&#xff08;Pipeline State Ob…...

【开源项目】libfaketime安装、使用——小白教程

项目 Github&#xff1a;GitHub - wolfcw/libfaketime: libfaketime modifies the system time for a single application libfaketime安装 01.切换路径&#xff0c;目标路径&#xff1a;/usr/local &#xff08;在/usr/local路径下git clone 开源项目) 切换路径指令: cd …...

java.util.concurrent包

java.util.concurrent包是Java中用于并发编程的重要工具集&#xff0c;提供了丰富的并发原语和组件&#xff0c;以简化多线程编程的复杂性&#xff0c;并帮助开发者编写高效、可伸缩和线程安全的并发程序。其主要功能包括以下几个方面&#xff1a; 一、线程池和任务执行框架 …...

Django创建项目模块+创建映射类+视图

确保你的项目已经正确链接数据库 链接数据库的工具有很多,数据库的种类也有很多&#xff0c;我使用的数据库是mysql&#xff0c;工具是pmysql&#xff0c;使用pymysql链接数据库&#xff0c;在settings文件中这么设置&#xff1a; DATABASES {# default: {# ENGINE: dja…...

使用AMD GPU和LangChain构建问答聊天机器人

Question-answering Chatbot with LangChain on an AMD GPU — ROCm Blogs 作者&#xff1a;Phillip Dang 2024年3月11日 LangChain是一个旨在利用语言模型强大功能来构建前沿应用程序的框架。通过将语言模型连接到各种上下文资源并基于给定的上下文提供推理能力&#xff0c;L…...

2024年808数据结构答案

1.已知带头结点单链表&#xff0c;H为头指针。设计一个算法&#xff0c;查找到链表的第m个结点(不包含头结点)&#xff0c;并将元 素值为X的结点插入到该结点后&#xff0c;形成一个新的链表。 // 定义单链表节点结构 typedef struct Node {int data;struct Node* next; } Nod…...

Amazon Linux 2023 安装 Docker

Amazon Linux 2023 安装 Docker 1. 简介 在公司需要将代码部属到 Amazon Linux 2023 系统上时&#xff0c;去 Docker 官方文档里面看也没有针对该系统的部属文档。虽然有通用的 Linux 部属方案但不能应用包管理工具。 首先执行yum、dnf、apt&#xff0c;执行yum和dnf都有正确…...

接口测试(八)jmeter——参数化(CSV Data Set Config)

一、CSV Data Set Config 需求&#xff1a;批量注册5个用户&#xff0c;从CSV文件导入用户数据 1. 【线程组】–>【添加】–>【配置元件】–>【CSV Data Set Config】 2. 【CSV数据文件设置】设置如下 3. 设置线程数为5 4. 运行后查看响应结果...

GGD证明推导学习

GGD证明推导学习 这篇文章&#xff0c;建议先看相关的论文。这篇是我读证明的感悟&#xff0c;因此&#xff0c;不会论文的主体内容 首先&#xff0c;给出命题&#xff1a; DGI的sumary向量是一个常数 给定一个图&#xff1a; G { X ∈ R N D , A ∈ R N N } \mathcal{G…...

Flink难点和高频考点:Flink的反压产生原因、排查思路、优化措施和监控方法

目录 反压定义 反压影响 WebUI监控 Metrics指标 backPressureTimeMsPerSecond idleTimeMsPerSecond busyTimeMsPerSecond 反压可视化 资源优化 算子优化 数据倾斜优化 复杂算子优化 背压机制 反压预防 性能调优 内置工具 第三方工具 反压定义 在探讨Flink的性…...

Swarm - Agent 编排工具

文章目录 一、关于 Swarm&#xff08;实验性、教育性&#xff09;为什么选择蜂群文档 二、安装使用安装基本用法其它示例 三、Running Swarmclient.run()ArgumentsResponse字段 四、AgentFields Agent指令函数切换和更新上下文变量函数模式 流媒体评估工具 一、关于 Swarm&…...

使用Python中的jieba库进行简单情感分析

在自然语言处理&#xff08;NLP&#xff09;领域&#xff0c;情感分析是一项重要的任务&#xff0c;它可以帮助我们理解文本背后的情感倾向。本文将通过一个简单的例子来介绍如何使用Python的jieba库对中文文本进行基本的情感分析。 1. 环境准备 首先&#xff0c;确保已经安装…...

`pip` 下载速度慢

pip 下载速度慢&#xff08;例如只有 50KB/s&#xff09;可能由多个因素导致&#xff0c;以下是一些常见原因和解决方法&#xff1a; 1. 使用国内镜像源 国内访问 PyPI 服务器可能会较慢&#xff0c;您可以通过配置国内镜像源来提升下载速度。以下是一些常用的国内镜像源&…...

【WRF数据准备】基于GEE下载静态地理数据-叶面积指数LAI及绿色植被率Fpar

【WRF数据准备】基于GEE下载静态地理数据 准备:WRF所需静态地理数据(Static geographical data)数据范围说明基于GEE下载叶面积指数及绿色植被率GEE数据集介绍数据下载:LAI(叶面积指数)和Fpar(绿色植被率)数据处理:基于Python处理为单波段LAI数据参考GEE的介绍可参见另…...

ESP32读取DHT11温湿度数据

芯片&#xff1a;ESP32 环境&#xff1a;Arduino 一、安装DHT11传感器库 红框的库&#xff0c;别安装错了 二、代码 注意&#xff0c;DATA口要连接在D15上 #include "DHT.h" // 包含DHT库#define DHTPIN 15 // 定义DHT11数据引脚连接到ESP32的GPIO15 #define D…...

STM32F4基本定时器使用和原理详解

STM32F4基本定时器使用和原理详解 前言如何确定定时器挂载在哪条时钟线上配置及使用方法参数配置PrescalerCounter ModeCounter Periodauto-reload preloadTrigger Event Selection 中断配置生成的代码及使用方法初始化代码基本定时器触发DCA或者ADC的代码讲解中断代码定时启动…...

Frozen-Flask :将 Flask 应用“冻结”为静态文件

Frozen-Flask 是一个用于将 Flask 应用“冻结”为静态文件的 Python 扩展。它的核心用途是&#xff1a;将一个 Flask Web 应用生成成纯静态 HTML 文件&#xff0c;从而可以部署到静态网站托管服务上&#xff0c;如 GitHub Pages、Netlify 或任何支持静态文件的网站服务器。 &am…...

vue3 定时器-定义全局方法 vue+ts

1.创建ts文件 路径&#xff1a;src/utils/timer.ts 完整代码&#xff1a; import { onUnmounted } from vuetype TimerCallback (...args: any[]) > voidexport function useGlobalTimer() {const timers: Map<number, NodeJS.Timeout> new Map()// 创建定时器con…...

鸿蒙中用HarmonyOS SDK应用服务 HarmonyOS5开发一个生活电费的缴纳和查询小程序

一、项目初始化与配置 1. 创建项目 ohpm init harmony/utility-payment-app 2. 配置权限 // module.json5 {"requestPermissions": [{"name": "ohos.permission.INTERNET"},{"name": "ohos.permission.GET_NETWORK_INFO"…...

UR 协作机器人「三剑客」:精密轻量担当(UR7e)、全能协作主力(UR12e)、重型任务专家(UR15)

UR协作机器人正以其卓越性能在现代制造业自动化中扮演重要角色。UR7e、UR12e和UR15通过创新技术和精准设计满足了不同行业的多样化需求。其中&#xff0c;UR15以其速度、精度及人工智能准备能力成为自动化领域的重要突破。UR7e和UR12e则在负载规格和市场定位上不断优化&#xf…...

算法笔记2

1.字符串拼接最好用StringBuilder&#xff0c;不用String 2.创建List<>类型的数组并创建内存 List arr[] new ArrayList[26]; Arrays.setAll(arr, i -> new ArrayList<>()); 3.去掉首尾空格...

嵌入式常见 CPU 架构

架构类型架构厂商芯片厂商典型芯片特点与应用场景PICRISC (8/16 位)MicrochipMicrochipPIC16F877A、PIC18F4550简化指令集&#xff0c;单周期执行&#xff1b;低功耗、CIP 独立外设&#xff1b;用于家电、小电机控制、安防面板等嵌入式场景8051CISC (8 位)Intel&#xff08;原始…...

tomcat指定使用的jdk版本

说明 有时候需要对tomcat配置指定的jdk版本号&#xff0c;此时&#xff0c;我们可以通过以下方式进行配置 设置方式 找到tomcat的bin目录中的setclasspath.bat。如果是linux系统则是setclasspath.sh set JAVA_HOMEC:\Program Files\Java\jdk8 set JRE_HOMEC:\Program Files…...

【java面试】微服务篇

【java面试】微服务篇 一、总体框架二、Springcloud&#xff08;一&#xff09;Springcloud五大组件&#xff08;二&#xff09;服务注册和发现1、Eureka2、Nacos &#xff08;三&#xff09;负载均衡1、Ribbon负载均衡流程2、Ribbon负载均衡策略3、自定义负载均衡策略4、总结 …...