当前位置: 首页 > 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的介绍可参见另…...

Vim 调用外部命令学习笔记

Vim 外部命令集成完全指南 文章目录 Vim 外部命令集成完全指南核心概念理解命令语法解析语法对比 常用外部命令详解文本排序与去重文本筛选与搜索高级 grep 搜索技巧文本替换与编辑字符处理高级文本处理编程语言处理其他实用命令 范围操作示例指定行范围处理复合命令示例 实用技…...

MPNet:旋转机械轻量化故障诊断模型详解python代码复现

目录 一、问题背景与挑战 二、MPNet核心架构 2.1 多分支特征融合模块(MBFM) 2.2 残差注意力金字塔模块(RAPM) 2.2.1 空间金字塔注意力(SPA) 2.2.2 金字塔残差块(PRBlock) 2.3 分类器设计 三、关键技术突破 3.1 多尺度特征融合 3.2 轻量化设计策略 3.3 抗噪声…...

遍历 Map 类型集合的方法汇总

1 方法一 先用方法 keySet() 获取集合中的所有键。再通过 gey(key) 方法用对应键获取值 import java.util.HashMap; import java.util.Set;public class Test {public static void main(String[] args) {HashMap hashMap new HashMap();hashMap.put("语文",99);has…...

【git】把本地更改提交远程新分支feature_g

创建并切换新分支 git checkout -b feature_g 添加并提交更改 git add . git commit -m “实现图片上传功能” 推送到远程 git push -u origin feature_g...

令牌桶 滑动窗口->限流 分布式信号量->限并发的原理 lua脚本分析介绍

文章目录 前言限流限制并发的实际理解限流令牌桶代码实现结果分析令牌桶lua的模拟实现原理总结&#xff1a; 滑动窗口代码实现结果分析lua脚本原理解析 限并发分布式信号量代码实现结果分析lua脚本实现原理 双注解去实现限流 并发结果分析&#xff1a; 实际业务去理解体会统一注…...

04-初识css

一、css样式引入 1.1.内部样式 <div style"width: 100px;"></div>1.2.外部样式 1.2.1.外部样式1 <style>.aa {width: 100px;} </style> <div class"aa"></div>1.2.2.外部样式2 <!-- rel内表面引入的是style样…...

rnn判断string中第一次出现a的下标

# coding:utf8 import torch import torch.nn as nn import numpy as np import random import json""" 基于pytorch的网络编写 实现一个RNN网络完成多分类任务 判断字符 a 第一次出现在字符串中的位置 """class TorchModel(nn.Module):def __in…...

2025季度云服务器排行榜

在全球云服务器市场&#xff0c;各厂商的排名和地位并非一成不变&#xff0c;而是由其独特的优势、战略布局和市场适应性共同决定的。以下是根据2025年市场趋势&#xff0c;对主要云服务器厂商在排行榜中占据重要位置的原因和优势进行深度分析&#xff1a; 一、全球“三巨头”…...

Spring是如何解决Bean的循环依赖:三级缓存机制

1、什么是 Bean 的循环依赖 在 Spring框架中,Bean 的循环依赖是指多个 Bean 之间‌互相持有对方引用‌,形成闭环依赖关系的现象。 多个 Bean 的依赖关系构成环形链路,例如: 双向依赖:Bean A 依赖 Bean B,同时 Bean B 也依赖 Bean A(A↔B)。链条循环: Bean A → Bean…...

Java + Spring Boot + Mybatis 实现批量插入

在 Java 中使用 Spring Boot 和 MyBatis 实现批量插入可以通过以下步骤完成。这里提供两种常用方法&#xff1a;使用 MyBatis 的 <foreach> 标签和批处理模式&#xff08;ExecutorType.BATCH&#xff09;。 方法一&#xff1a;使用 XML 的 <foreach> 标签&#xff…...