C#如何实现数组操作
发表于:2024-10-12 作者:千家信息网编辑
千家信息网最后更新 2024年10月12日,这篇文章给大家分享的是有关C#如何实现数组操作的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。数组是相同类型的对象的集合。数组具有相同数据类型的项的有序集合。要访问数组中的某
千家信息网最后更新 2024年10月12日C#如何实现数组操作
这篇文章给大家分享的是有关C#如何实现数组操作的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
数组是相同类型的对象的集合。数组具有相同数据类型的项的有序集合。要访问数组中的某个项,需要同时使用数组名称及该项与数组起点之间的偏移量。由于数组几乎可以为任意长度,因此可以使用数组存储数千乃至数百万个对象,但必须在创建数组时就确定其大小。数组中的每项都按索引进行访问,索引是一个数字,指示对象在数组中的存储位置或槽。
按顺序演示了以下功能:
◆动态创建数组
◆数组快速排序
◆反转数组元素
◆动态改变数组大小
◆检索数组中元素
◆复制数组中多个元素
namespace StringDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { System.Collections.ArrayList mystrlist = new System.Collections.ArrayList(); mystrlist.Add("aaaaaaaa"); mystrlist.Add("bbbbbbbb"); mystrlist.Add("cccccccc"); mystrlist.Add("dddddddd"); foreach (string str in mystrlist) { textBox1.Text += str + "\r\n"; } } private void button2_Click(object sender, EventArgs e) { String[] myArray = { "8", "one", "4", "0", "over", "the" }; foreach (string str in myArray) textBox1.Text += str + "\r\n"; textBox1.Text += "\r\n"; Array.Sort(myArray); foreach (string str in myArray) textBox1.Text += str + "\r\n"; } private void button3_Click(object sender, EventArgs e) { String[] myArray = { "8", "one", "4", "0", "over", "the" }; foreach (string str in myArray) textBox1.Text += str + "\r\n"; textBox1.Text += "\r\n"; Array.Reverse(myArray); foreach (string str in myArray) textBox1.Text += str + "\r\n"; } private void button4_Click(object sender, EventArgs e) { String[] myArray = { "one", "two", "three" }; foreach (string str in myArray) textBox1.Text += str + "\r\n"; textBox1.Text += "\r\n"; Array.Resize(ref myArray, 5); myArray[3] = "aaa"; myArray[4] = "bbb"; foreach (string str in myArray) textBox1.Text += str + "\r\n"; } private void button5_Click(object sender, EventArgs e) { string[] dinosaurs = { "Compsog0000nathus", "Amargasaurus", "Ovira0000ptor","Veloc0000iraptor", "Deinonychus","Dilop0000hosaurus","Gallimimus", "Triceratops"}; foreach (string str in dinosaurs) textBox1.Text += str + "\r\n"; textBox1.Text += "\r\n"; //要自己写一个SubStringis0000的函数,这是泛型编程 string[] subArray = Array.FindAll(dinosaurs,SubStringis0000); foreach (string str in subArray) textBox1.Text += str + "\r\n"; } private static bool SubStringis0000(string str) { if(str.Contains ("0000")) return true ; else return false ; } private void button6_Click(object sender, EventArgs e) { string[] dinosaurs = { "Compsog0000nathus", "Amargasaurus", "Ovira0000ptor","Veloc0000iraptor", "Deinonychus","Dilop0000hosaurus","Gallimimus", "Triceratops"}; foreach (string str in dinosaurs) textBox1.Text += str + "\r\n"; textBox1.Text += "\r\n"; string[] deststr = new string[2]; //Copy还有很多类型的参数,比如数组复制等。 Array.Copy(dinosaurs, 2, deststr, 0, 2); foreach (string str in deststr) textBox1.Text += str + "\r\n"; } private void button7_Click(object sender, EventArgs e) { textBox1.Text = ""; } } }
感谢各位的阅读!关于"C#如何实现数组操作"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
数组
元素
对象
类型
C#
相同
内容
动态
大小
更多
篇文章
索引
存储
不错
实用
有序
之间
位置
函数
功能
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
腾讯视频服务器在哪国
网络安全知多少宣传周手抄报
使用热点时键入网络安全密钥
软件开发有哪些规章制度
服务器磁盘状态ugoodf
战疫情保网络安全
济南软件开发公司张召明
最强pvp服务器
无锡企业软件开发系统
我的世界基岩版服务器延迟过高
数据库管理系统宿舍
拒绝网络安全主题班会
达梦数据库dmdpc
2021曲靖网络安全会议
egg注册页面数据存入数据库
数据库中统计表中的各类商品数量
深职计算机网络技术
没有基础学习网络安全吗
网络安全与信息网杂志
陕西软件开发乙级资质名录
28做软件开发
服务器标签
爱快虚拟机装win服务器系统
软件开发法务
载数据库模拟
银保监会网络安全等级保护
监控存储服务器跟录像机一样吗
DNF数据库技术指标
华为服务器BIOS备份工具
网络安全相关标语