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

使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式

一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明&#xff1a;假设每台服务器已…...

观成科技:隐蔽隧道工具Ligolo-ng加密流量分析

1.工具介绍 Ligolo-ng是一款由go编写的高效隧道工具&#xff0c;该工具基于TUN接口实现其功能&#xff0c;利用反向TCP/TLS连接建立一条隐蔽的通信信道&#xff0c;支持使用Let’s Encrypt自动生成证书。Ligolo-ng的通信隐蔽性体现在其支持多种连接方式&#xff0c;适应复杂网…...

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …...

AtCoder 第409​场初级竞赛 A~E题解

A Conflict 【题目链接】 原题链接&#xff1a;A - Conflict 【考点】 枚举 【题目大意】 找到是否有两人都想要的物品。 【解析】 遍历两端字符串&#xff0c;只有在同时为 o 时输出 Yes 并结束程序&#xff0c;否则输出 No。 【难度】 GESP三级 【代码参考】 #i…...

el-switch文字内置

el-switch文字内置 效果 vue <div style"color:#ffffff;font-size:14px;float:left;margin-bottom:5px;margin-right:5px;">自动加载</div> <el-switch v-model"value" active-color"#3E99FB" inactive-color"#DCDFE6"…...

基础测试工具使用经验

背景 vtune&#xff0c;perf, nsight system等基础测试工具&#xff0c;都是用过的&#xff0c;但是没有记录&#xff0c;都逐渐忘了。所以写这篇博客总结记录一下&#xff0c;只要以后发现新的用法&#xff0c;就记得来编辑补充一下 perf 比较基础的用法&#xff1a; 先改这…...

华为OD机试-食堂供餐-二分法

import java.util.Arrays; import java.util.Scanner;public class DemoTest3 {public static void main(String[] args) {Scanner in new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别while (in.hasNextLine()) { // 注意 while 处理多个 caseint a in.nextIn…...

Keil 中设置 STM32 Flash 和 RAM 地址详解

文章目录 Keil 中设置 STM32 Flash 和 RAM 地址详解一、Flash 和 RAM 配置界面(Target 选项卡)1. IROM1(用于配置 Flash)2. IRAM1(用于配置 RAM)二、链接器设置界面(Linker 选项卡)1. 勾选“Use Memory Layout from Target Dialog”2. 查看链接器参数(如果没有勾选上面…...

mysql已经安装,但是通过rpm -q 没有找mysql相关的已安装包

文章目录 现象&#xff1a;mysql已经安装&#xff0c;但是通过rpm -q 没有找mysql相关的已安装包遇到 rpm 命令找不到已经安装的 MySQL 包时&#xff0c;可能是因为以下几个原因&#xff1a;1.MySQL 不是通过 RPM 包安装的2.RPM 数据库损坏3.使用了不同的包名或路径4.使用其他包…...

Swagger和OpenApi的前世今生

Swagger与OpenAPI的关系演进是API标准化进程中的重要篇章&#xff0c;二者共同塑造了现代RESTful API的开发范式。 本期就扒一扒其技术演进的关键节点与核心逻辑&#xff1a; &#x1f504; 一、起源与初创期&#xff1a;Swagger的诞生&#xff08;2010-2014&#xff09; 核心…...