List 如何使用列表创建类<&燃气轮机;性质
问题是: -我想将文件名读入类中的列表List 如何使用列表创建类<&燃气轮机;性质,list,properties,List,Properties,问题是: -我想将文件名读入类中的列表 如何将文件名读入foreach语句中的列表 如何在类的列表属性中设置get和set语句 对于此操作,使用哪种类型:静态类还是普通类 ------修订--------这就是问题所在: 很抱歉给你带来了困惑 我想要的是将文件名添加到类的列表中。我想在列表中有一个文件名列表供以后使用 1) 如何将文件名添加到Click事件或Page Load事件中类的g_Photoname列表中 受保护的无效按钮\u单击(对象发送者,事件参数e) { //-1-获取临时目录中的
var pe = new PicExample(@"c:\temp\");
foreach (string f in pe.FileList)
{
// Question : How do I add the f in the List<> in this class ?
// PhotoNameCollection = f ; ??? Can do?
}
var pe=new PicExample(@“c:\temp\”);
foreach(pe.FileList中的字符串f)
{
//问题:如何在这个类的列表中添加f?
//PhotoNameCollection=f;???可以吗?
}
}
2) 创建一个静态类来保存类中列表中的文件名列表
a) 如何在此类中为列表设置get ad set语句
public class PhotoNameCollection
{
private List<string> g_Photoname
public List<string> PhotoName
{
get
{
}
set
{
}
}
}
b) 这个列表在这门课上正确使用了吗
public class PhotoNameCollection
{
private List<string> g_Photoname
public List<string> PhotoName
{
get
{
}
set
{
}
}
}
公共类PhotoNameCollection
{
私人列表g_Photoname
公共列表照片名
{
得到
{
}
设置
{
}
}
}
类似的内容应该可以帮助您开始
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var pe = new PicExample(@"c:\temp\");
foreach (var p in pe.FileList)
{
Console.WriteLine(p);
}
Console.ReadLine();
}
}
public class PicExample
{
private List<string> _fileNames = new List<string>();
public PicExample( string directory )
{
var files = Directory.EnumerateFiles(directory);
foreach (var file in files)
{
_fileNames.Add(file);
}
}
public List<string> FileList
{
get { return _fileNames; }
set { _fileNames = value; }
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.IO;
命名空间控制台应用程序1
{
班级计划
{
静态void Main(字符串[]参数)
{
var pe=新的PicExample(@“c:\temp\”);
foreach(pe.FileList中的var p)
{
控制台写入线(p);
}
Console.ReadLine();
}
}
公共类图片示例
{
私有列表_fileNames=新列表();
公共目录示例(字符串目录)
{
var files=目录。枚举文件(目录);
foreach(文件中的var文件)
{
_文件名。添加(文件);
}
}
公共列表文件列表
{
获取{return\u fileNames;}
设置{u fileNames=value;}
}
}
}
类似的内容应该可以帮助您开始
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var pe = new PicExample(@"c:\temp\");
foreach (var p in pe.FileList)
{
Console.WriteLine(p);
}
Console.ReadLine();
}
}
public class PicExample
{
private List<string> _fileNames = new List<string>();
public PicExample( string directory )
{
var files = Directory.EnumerateFiles(directory);
foreach (var file in files)
{
_fileNames.Add(file);
}
}
public List<string> FileList
{
get { return _fileNames; }
set { _fileNames = value; }
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.IO;
命名空间控制台应用程序1
{
班级计划
{
静态void Main(字符串[]参数)
{
var pe=新的PicExample(@“c:\temp\”);
foreach(pe.FileList中的var p)
{
控制台写入线(p);
}
Console.ReadLine();
}
}
公共类图片示例
{
私有列表_fileNames=新列表();
公共目录示例(字符串目录)
{
var files=目录。枚举文件(目录);
foreach(文件中的var文件)
{
_文件名。添加(文件);
}
}
公共列表文件列表
{
获取{return\u fileNames;}
设置{u fileNames=value;}
}
}
}
此列表应该是什么?文件行的集合?这个列表应该是什么?文件行的集合?很抱歉造成混淆。我想要的是将文件名添加到类的列表中。我想在列表中有一个文件名列表供以后使用。很抱歉造成混淆。我想要的是将文件名添加到类的列表中。我想在列表中有一个文件名列表供以后使用。