English 中文(简体)
是否有这样的东西。 NET Dictionary withplicad keys to Punish with a text file?
原标题:Is there something like the .NET Dictionary with duplicated keys to fill with a text file?

我有一份案文文件,其结构如下:

01|value|value|value|value|value|value
02|value|value|value|value|value|value
03A|value|value|value|value|value|value
03A|value|value|value|value|value|value
.
.
N
04|value|value|value|value|value|value
05|value|value|value|value|value|value
06|value|value|value|value|value|value
.
.
N (variable lines)

I tried to read the text file and add it to a dictionary of type <string, string[]> in order to use it like MyDic["01"][0], this is a fragment of the code:

Dictionary<string, string[]> txtFromFile= new Dictionary<string, string[]>();
string strLine;
using (StreamReader sr = new StreamReader(filePath))
{
   while ((strLine= sr.ReadLine()) != null)
   {
      string[] strNodes= strLine.Split( | );
      txtFromFile.Add(strNodes[0], strNodes);
   }
}

不幸的是,正如你所看到的那样,这份案文文件可能重复了诸如<代码>03A等关键内容,因此我很想知道,在C#中是否收集了这方面的资料。

<>0> 我看到了一个叫作 look的班子,但没有建筑商。

  1. Any thoughts my friends?
  2. What do you suggest?

感谢!

问题回答

为什么不要仅仅制造这样的一类人

public class MyLine
{
  string key { get;set;}
  string[] value {get;set;}
}

并将其储存在一份基因清单中

那么,你就能够用林木来质疑你们想要的东西。

您可使用ToLookup推广方法:

string[] lines = File.ReadAllLines(filePath);
ILookup<string, string[]> result = lines
    .Select(line => line.Split( | ))
    .ToLookup(parts => parts[0]);

第一个问题是,如果你对具有同样关键意义的多个条目感到关切,你就试图使用错误类型。 您可以通过<条码>做到这一点。 List<KeyValuePair<string, string[]>>和你自己的研究功能,可能通过延长这一类别,或者你可以在字典内添加另一个字典,作为贵值类别:Dictionary<string, Dictionary<int, string[]>>。 选择权是更好的床垫,因为它有更好的业绩。

有多少清单有习惯类型?

class KeyValue 
{ 
 String ID { get ; set ; } 
 List<String> Values { get ; private set ;}
 (..Constructor etc...)
}

List<KeyValue> myValues = new List<KeyValue>();
while ((strLine= sr.ReadLine()) != null)
{
 string[] strNodes= strLine.Split( | );
 myValues.Add(new KeyValue(strNodes[0],strNodes));
} 

页: 1 List<KeyValuePair<string, string[]>> or List<Tuple<string, string[]>>

(当然,你可能选择不同的收集类型,而不是<代码>List<>)

另一种想法是使用

Dictionary<string, List<string[]>>

如果“指示”是可能重复的价值。 当一再发生时,你在内部再造假肢。 如果有一行存在,就会有一个名单。 如果发现重复增长,则增加一个。 这样,你们就可以看看看看有多少个重复的牢房只是按名单列出。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签