私は最近、C#でちょっとびっくりしています。一般的なコレクションでは少し混乱しています。ツリーの先頭がキーの値のペアであって、その下にキーの値のペアのリストが1つあります(ただし、これよりもレベルはありません)。これは適切でしょうか?キーバリューペアデータ構造の最適な実装ですか?
public class TokenTree
{
public TokenTree()
{
/* I must admit to not fully understanding this,
* I got it from msdn. As far as I can tell, IDictionary is an
* interface, and Dictionary is the default implementation of
* that interface, right?
*/
SubPairs = new Dictionary<string, string>();
}
public string Key;
public string Value;
public IDictionary<string, string> SubPairs;
}
実際にはデータを渡すためのシンプルなシャントです。
これは、いくつかの入力を節約し、すべてをもっと明瞭にするために、 "using"ステートメント(古いtypedefに似ています)でうまくいきます。 eを常時使用している場合。 g。 (文字列、文字列)のペア。 –
KeyValuePair NAME_HERE =新しいKeyValuePair <文字列、文字列>( "defaultkey"、 "defaultvalue"); –
HasanAboShally
@AndreasReiffのコメントを拡張するには、 'NameValuePair = System.Collections.Generic.KeyValuePair;を使用して'(文字列、文字列) '構造体を必要とする各ファイルの先頭近くに展開します。私の名前空間に 'class NameValuePair'を作るほうが便利だと分かったが、' public class NameValuePair \t { \t \t KeyValuePair it; \t \t公共のNameValuePair(文字列名、文字列値)が新しいKeyValuePair <文字列、文字列>(名前、値)= \t \t { \t \t \t。 \t \t \t \t公開ストリング名{get {return it.Key; }} \t \t公開ストリング値{get {return it.Value; }} \t} ' –
ToolmakerSteve