C#中获取ArrayList里面元素的个数用什么方法

C#中获取ArrayList里面元素的个数用什么方法,第1张

//定义以及加变量

ArrayList arr = new ArrayList();

arrAdd("雷锋");

arrAdd("大_懒_虫");

//个数属性

int count = arrCount;

//使用里面的元素

string arr0 = arr[0]ToString();//雷锋

string arr1 = arr[1]ToString();//大_懒_虫

foreach (string name in arr)

{

  ConsoleWriteLine(name);

}

ConsoleReadKey(true);

C#遍历指定文件夹中的所有文件

DirectoryInfo TheFolder=new DirectoryInfo(folderFullName);

//遍历文件夹

foreach(DirectoryInfo NextFolder in TheFolderGetDirectories())

thislistBox1ItemsAdd(NextFolderName);

//遍历文件

foreach(FileInfo NextFile in TheFolderGetFiles())

thislistBox2ItemsAdd(NextFileName);

===================================================================

如何获取指定目录包含的文件和子目录

1 DirectoryInfoGetFiles():获取目录中(不包含子目录)的文件,返回类型为FileInfo[],支持通配符查找;

2 DirectoryInfoGetDirectories():获取目录(不包含子目录)的子目录,返回类型为DirectoryInfo[],支持通配符查找;

3 DirectoryInfo GetFileSystemInfos():获取指定目录下(不包含子目录)的文件和子目录,返回类型为FileSystemInfo[],支持通配符查找;

如何获取指定文件的基本信息;

FileInfoExists:获取指定文件是否存在;

FileInfoName,FileInfoExtensioin:获取文件的名称和扩展名;

FileInfoFullName:获取文件的全限定名称(完整路径);

FileInfoDirectory:获取文件所在目录,返回类型为DirectoryInfo;

FileInfoDirectoryName:获取文件所在目录的路径(完整路径);

FileInfoLength:获取文件的大小(字节数);

FileInfoIsReadOnly:获取文件是否只读;

FileInfoAttributes:获取或设置指定文件的属性,返回类型为FileAttributes枚举,可以是多个值的组合

FileInfoCreationTime、FileInfoLastAccessTime、FileInfoLastWriteTime:分别用于获取文件的创建时间、访问时间、修改时间;

假设a文件夹在F盘下,代码如下。将文件名输出到一个ListBox中

using SystemData;

using SystemDrawing;

using SystemLinq;

using SystemText;

using SystemWindowsForms;

using SystemIO;

namespace WindowsFormsApplication1

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button2_Click(object sender, EventArgs e)

{

DirectoryInfo theFolder = new DirectoryInfo(@"F:\a\");

DirectoryInfo[] dirInfo = theFolderGetDirectories();

//遍历文件夹

foreach (DirectoryInfo NextFolder in dirInfo)

{

// thislistBox1ItemsAdd(NextFolderName);

FileInfo[] fileInfo = NextFolderGetFiles();

foreach (FileInfo NextFile in fileInfo) //遍历文件

thislistBox2ItemsAdd(NextFileName);

}

}

}

}

jQuery的length 属性可以获取包含 jQuery 对象中元素的数目,所以获取input的个数可用如下代码实现

$('input')length;       // 所有input的数量,包括文本框、单选按钮、复选框、隐藏域等

$('input:text')length;  // 文本框的数量

示例代码如下

创建Html元素

<div class="box">

<span>点击按钮获取文本框数量:</span><br>

<div class="content">

<input type="text" name="name" value="John"/>

<input type="text" name="password" value="jack"/>

<input type="text" name="url" value="tom"/>

</div>

<input type="button" value="点击获取文本框数量">

</div>

设置css样式

divbox{width:300px;padding:20px;margin:20px;border:4px dashed #ccc;}

divbox span{color:#999;font-style:italic;}

divcontent{width:250px;margin:10px 0;padding:20px;border:2px solid #ff6666;}

input[type='button']{height:30px;margin:10px;padding:5px 10px;}

input[type='text']{width:200px;height:35px;padding:5px 10px;margin:5px 0;border:1px solid #ff9966;}

编写jquery代码

$(function(){

$(":button")click(function() {

alert($("input:text")length);

})

})

观察效果

以上就是关于C#中获取ArrayList里面元素的个数用什么方法全部的内容,包括:C#中获取ArrayList里面元素的个数用什么方法、C#获取如何获取指定文件夹下文件的个数、、如何用jquery获取当前页面中input的个数等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/9570373.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-29
下一篇2023-04-29

发表评论

登录后才能评论

评论列表(0条)

    保存