0
我有一个文件并搜索多个值,即我需要搜索{Name,Class}并将其存储在列表或字典中,我需要使用c#。使用c搜索文件#
Ex。 姓名:“ABC” 职业:“5th” 考试成绩欠佳,考试不及格。 姓名:“CYS” 职业:第9名 因考绩良好,考试顺利通过考试。 Class:10th 无需评论。
string Filename = @"ClassInfo.fo";
XmlTextReader reader = new XmlTextReader(Filename);
List<string> xmlValue = new List<string>();
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Text: //Display the text in each element.
Console.WriteLine(reader.Value);
xmlValue.Add(reader.Value);
break;
}
}
string searchString = "Name :"
var foundIndices = new List<int>(xmlValue.Count);
int countValue=0;
Collection<PdfContent> pdfContent = new Collection<PdfContent>();
for (int i = 0; i < xmlValue.Count; i++)
{
if (xmlValue[i] == searchString)
{
foundIndices.Add(i);
pdfContent.Add(new PdfContent
{
Name= xmlValue[indexOfName],
Class=xmlValue[indexOfClass]
});
}
}
我能够得到的名字,但不是Class.Any解决方案 – Pat 2012-07-05 11:19:25
你用上面的代码得到了什么问题?你已经解释了你想做什么,你已经展示了你尝试过的东西,但是你没有解释你尝试过的东西有什么问题。请解释。 – zeencat 2012-07-05 11:21:35
我能够使用我的实体名称映射搜索条件“名称”,但是如何搜索“类”并将其映射到“类”实体。 – Pat 2012-07-05 11:25:31