简体   繁体   English

将结构类型存储在 c# 的列表或字典中

[英]storing struct type in a list or dictionary in c#

I have existing legacy code in C# where we store struct type in a memlib type and then create 3 keys to access the memlib structs in a faster way.我在 C# 中有现有的遗留代码,我们将结构类型存储在 memlib 类型中,然后创建 3 个键以更快的方式访问 memlib 结构。 Please have a look at the below snapshot:请看下面的快照:

public struct gtBuildRecType : ICloneable
    {
        public double dParentLocCd; //   8 bytes : Key1
        public double dLocationCd; //   8 bytes : Key2
        public int lHierLevel; //   4 bytes : Key3
        public int lSequence;
        public int lDupChecked;
        public int nStatusInd;
    }

Memlib record and the 3 keys are defined like as following: Memlib 记录和 3 个键的定义如下:

    static public Memlib<gtBuildRecType> gnBuildTable = null;
    static public Key<gtBuildRecType> gnBuildParentCdKey = null;
    static public Key<gtBuildRecType> gnBuildLocCdKey = null;
    static public Key<gtBuildRecType> gnBuildHierLevelKey = null;

Now, gnBuildTable Memlib can contain thousands of struct records and we can use any of the 3 keys ie, gnBuildParentCdKey, gnBuildLocCdKey, gnBuildHierLevelKey for faster access.现在, gnBuildTable Memlib 可以包含数千条结构记录,我们可以使用 3 个键中的任何一个,即gnBuildParentCdKey、gnBuildLocCdKey、gnBuildHierLevelKey来更快地访问。 For example:例如:

gtBuildRecType uTempRec = gtBuildRecType.CreateInstance();
MemLibStatus nReturn = gnBuildTable.ReadEqual(gnBuildParentCdKey, ref uTempRec);

This piece of code will immediately fill the uTempRec from gnBuildTable where the gnBuildParentCdKey matches a struct record in the gnBuildTable and then we can update the uTempRec accordingly and save the changes.这段代码将立即从gnBuildTable填充uTempRec ,其中gnBuildParentCdKey匹配 gnBuildTable 中的结构记录,然后我们可以相应地更新 uTempRec保存更改。

NOW, My question is: I want to replace the Memlib with List or Dictionary.现在,我的问题是:我想用 List 或 Dictionary 替换 Memlib。 I would want to store these thousands of struct records in either List or Dictionary but How shall I implement the 3 keys approach with List or Dictionary, so that my search becomes even faster????.我想将这数千条结构记录存储在 List 或 Dictionary 中,但是我应该如何使用 List 或 Dictionary 实现 3 键方法,以便我的搜索变得更快???? I started with List(Not using any key) but half way across i am facing issues to search for accurate struct record in the list.我从列表开始(不使用任何键),但在中途我遇到了在列表中搜索准确结构记录的问题。

I had initially tried a dictionary approach as well using single key but i ran into issues there as well.我最初也尝试过使用单键的字典方法,但我也遇到了问题。

Thanks in advance:-)提前致谢:-)

Well, To overcome this issue I could use multi-index 3rd party library or could also work through the DataTable.好吧,为了克服这个问题,我可以使用多索引 3rd 方库,也可以通过 DataTable 工作。 Make the fields of structs as the column in datatable.将结构的字段作为数据表中的列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM