int.parse --将数字的字符串表示形式转换为它的等效 int 表示形式。
ListView 控件的主要属性是 Items,该属性包含控件所显示的项。SelectedItems 属性包含控件中当前选定项的集合。如果将 MultiSelect 属性设置为 true,则用户可选择多项,例如,同时将若干项拖放到另一个控件中。如果 CheckBoxes 属性设置为 true,则 ListView 控件可在项的旁边显示复选框。
Activation 属性确定用户必须采取何种操作以激活列表中的项:选项为“Standard”、“OneClick”和“TwoClick”。“OneClick”激活方式要求单击激活列表项。“TwoClick”激活方式要求用户双击激活列表项;单击更改项文本的颜色。“Standard”激活方式要求用户双击激活列表项,但项的外观并不改变。
ListViewItem.Tag 属性
获取或设置包含数据的对象以与该项关联。
属性值
包含与该项相关联的信息的对象。
备注
Tag 属性可用于存储要与某项关联的任何对象。虽然您可以存储任何项,但 Tag 属性通常用于存储与项相关的字符串信息(例如,唯一标识符)或数据库中项的数据的索引位置。
Fileinfo.openRead()
创建只读FileStream。
using System;
using System.IO;
using System.Text;
class Test
{
public static void Main()
{
string path = @"c:/temp/MyTest.txt";
FileInfo fi = new FileInfo(path);
// Delete the file if it exists.
if (!fi.Exists)
{
//Create the file.
using (FileStream fs = fi.Create())
{
Byte[] info = new UTF8Encoding(true).GetBytes("This is some text in the file.");
//Add some information to the file.
fs.Write(info, 0, info.Length);
}
}
//Open the stream and read it back.
using (FileStream fs = fi.OpenRead())
{
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
while (fs.Read(b,0,b.Length) > 0)
{
Console.WriteLine(temp.GetString(b));
}
}
}
}
FileInfo.Exists
获取指示文件是否存在的值。
using System;
using System.IO;
public class ExistsTest
{
public static void Main()
{
string neFile = "nonexistentfile";
// Open an existing file, or create a new one.
FileInfo fi = new FileInfo(neFile);
DetermineExists(fi, neFile);
neFile = "newFile.txt";
// Create the file on disk.
fi = new FileInfo(neFile);
FileStream fs = fi.Create();
DetermineExists(fi, neFile);
// Close the file so that it can be deleted.
fs.Close();
// Delete the file.
try
{
fi.Delete();
Console.WriteLine("The file '{0}' was deleted successfully.", fi.Name);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
private static void DetermineExists( FileInfo fi, string fileName )
{
// Determine whether the file exists.
if (fi.Exists)
Console.WriteLine("The file '{0}' exists in the specified directory.", fileName);
else
Console.WriteLine("The file '{0}' does not exist in the specified directory.", fileName);
}
}
FileInfo.Length 属性
获取当前文件的大小。
// The following example displays the names and sizes
// of the files in the specified directory.
using System;
using System.IO;
public class FileLength
{
public static void Main()
{
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo("c://");
// Get a reference to each file in that directory.
FileInfo[] fiArr = di.GetFiles();
// Display the names and sizes of the files.
Console.WriteLine("The directory {0} contains the following files:", di.Name);
foreach (FileInfo f in fiArr)
Console.WriteLine("The size of {0} is {1} bytes.", f.Name, f.Length);
}
}