我们如何使用其他.NET功能实现字典(TKEY,tvalue)功能? [英] How can we achieve the dictionary (TKEY, tvalue) functionality with other .NET features?

查看:110
本文介绍了我们如何使用其他.NET功能实现字典(TKEY,tvalue)功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将解析前两个csv行(标题,值),然后在逗号','的基础上拆分它们,然后将它们并行添加到集合中。我可以用字典做到这一点但是当两个标题相同或为空时它会给出错误n具有相同键的项目已经添加到字典中。在我的情况下Tkey =第一线标题值和TValue =第二线值。



我尝试过:



我尝试过C#Generics Dictionary和HashTable功能,但两者都有限制,Key必须是唯一的。

I am going to parse first two csv lines (headers,values) and then split them on base of comma ',' and then add them both parallel to the collection. I am able to do this with dictionary but when the two headers same or empty it gives error "n item with the same key has already been added in dictionary". In my case Tkey=First Line Header Values and TValue = Second Line Values.

What I have tried:

I have tried C# Generics Dictionary and HashTable feature but both have limitations that Key must be unique.

推荐答案

你似乎有你有空行和重复标题这一事实的问题。



如果你认为这是一个特征或问题。



你已经得到了一个有雾的问题的合理答案(如果你可以称之为)。



你需要一个更好的问题定义。
You seem to have an issue with the fact that you have "empty lines" and "duplicate headers".

Nobody can figure out if you think this is a "feature" or a "problem".

You have gotten reasonable answers to a foggy "question" (if you can call it that).

You need a better "problem definition".


我不知道你在做什么,但它听起来像 List< KeyValuePair< string ,string>> 可以解决问题。
I have no idea what you're doing but it sounds like a List<KeyValuePair<string, string>> could do the trick.


Quote:

我尝试过C#Generics Dictionary和HashTable功能,但两者都有局限性键必须是唯一的。

I have tried C# Generics Dictionary and HashTable feature but both have limitations that Key must be unique.



非空唯一键是字典的原则。没有字典会破坏这个规则。

字典闻起来像是你问题的错误解决方案。



为了得到解决方案,你需要准确解释你想用输入和输出样本做什么。


Non empty unique keys are the principle of dictionary. No dictionary will break this rule, ever.
The dictionary smells like a wrong solution to your problem.

In order to get a solution, you need to explain exactly what you want to do with a sample input and output.


这篇关于我们如何使用其他.NET功能实现字典(TKEY,tvalue)功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆