English 中文(简体)
需要帮助执行三种价值观的某种清单
原标题:Need help implementing a list of some kind for three values

在申请中使用现有搜索引擎的新方式。 想法是利用预先固定装置进行搜查,而不是在搜查前检查箱中的优先价值。 与此类似:“第12345678号”,而搜索则将回馈一个电话号码。

问题是,这一调查由三个价值观组成。 我有两条征象和搜索器。 第三个数值是实际固定价值。

解决这一问题的最有效方式是什么? 坐在钥匙ValuePairs上,但这似乎最终形成了一种比喻。

我尝试在一个假肢中保持不同的可能性。

prefixes = new Dictionary<string, KeyValuePair<SearchCriteria, SearchType>> {
    { values },
    { values }
}

建议?

最佳回答

仅写一个简单的价值类别以掌握这些信息有什么错误?

public struct Search
{
    public Search(SearchCriteria criteria, SearchType type, string prefix) { ... }

    public readonly SearchCriteria Criteria;
    public readonly SearchType Type;
    public readonly String Prefix;
}

将你的各种搜索类型列入你可以使用的林克来获得“样子”;特定预设标准......

Search[] searches = new []
{
    new Search(SearchCriteria.PhoneNumber, SearchType.Match, "#"),
    new Search(SearchCriteria.PostCode, SearchType.CaseInsensetive, "*")
}

string prefix = "#";

var searchCriteria = searches.Single(x => x.Prefix = prefix).Criteria;
var searchType     = searches.Single(x => x.Prefix = prefix).Type;
问题回答

你们只能使用一种结构

struct ValueParts
{    
     public readonly SearchCriteria criteria;
     public readonly SearchType type;
     public readonly string prefix; 

     public ValueParts(SearchCriteria c, SearchType t, string p) 
     {
         criteria = c;
         type = t;
         prefix = p;
     }
}

或C#4.0 Tuple:

Tuple<SearchCriteria, SearchType, string> tuple(
      SearchCriteria.Normal, /*just making that up*/
      SearchType.And,       /* that too*/
      "#12345678");

两者都效率最高





相关问题
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. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签