0

Integer と Char を保持できるデータ型が必要です。

private Int32[] XCordinates = {0,1,2,3,4,5,6,7,8,9 };
private Char[] yCordinates = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J' };

そして、私はこのような結果が欲しい

A0
A1
A2
A3
A4 and so on.... upto 
J8
J9

ここで、「H6」エントリから最速のパフォーマンスとデータ取得を得るには、どのデータ型を使用すればよいでしょうか。

  1. 辞書は複数のキーを許可しないため、方程式から外れています

  2. ArrayList を使用できますが、格納できるのは1種類のオブジェクトと必要なボックス化/ボックス化解除のみです。

または私は使用することができます

List<KeyValuePair<Char, Int32>> myKVPList = new List<KeyValuePair<Char, Int32>>();
foreach (Char yValue in yCordinates)
{
   foreach (Int32 xValue in XCordinates)
   {
       myKVPList.Add(new KeyValuePair<Char, Int32>(yValue, xValue));
    }
 }

リストは、配列と比較してデータへのアクセスが最も遅いです。何か提案はありますか?

4

2 に答える 2

1

.NET Framework 3.5 には、特別な LINQLookupクラスが含まれています。

var lookup = (from x in yCordinates
             from y in XCordinates
             select new{x, y}).ToLookup(xy => xy.x, xy => xy.y);

foreach(var xy in lookup)
    Console.WriteLine("x:{0} y-values:{1}", xy.Key, string.Join(",", xy.Select(y => y)));

結果:

x:A y-values:0,1,2,3,4,5,6,7,8,9
x:B y-values:0,1,2,3,4,5,6,7,8,9
x:C y-values:0,1,2,3,4,5,6,7,8,9
x:D y-values:0,1,2,3,4,5,6,7,8,9
x:E y-values:0,1,2,3,4,5,6,7,8,9
x:F y-values:0,1,2,3,4,5,6,7,8,9
x:G y-values:0,1,2,3,4,5,6,7,8,9
x:H y-values:0,1,2,3,4,5,6,7,8,9
x:I y-values:0,1,2,3,4,5,6,7,8,9
x:J y-values:0,1,2,3,4,5,6,7,8,9

ALookup<TKey, TElement>は a に似ていDictionary<TKey, TValue>ます。違いは、 aDictionary<TKey, TValue>はキーを単一の値にLookup<TKey, TElement>マップするのに対し、 a はキーを値のコレクションにマップすることです。

その欠点は次のとおりです。

  • パブリックコンストラクターがないため、ルックアップオブジェクトを作成することはできません。.ToLookupメソッドを使用してのみ使用できます
  • 作成後は編集できず、追加や削除などもできません。

補足として、存在しないキーに対して (インデクサーを介して) ルックアップをクエリすると、空のシーケンスが得られます。辞書で同じことをすると、例外が発生します。

于 2013-07-09T12:53:26.383 に答える
0

文字と数字のバイト表現を試してから、フォーマットすることができます:

        //values from 48-57 are 0 to 9,65-90 uppercase letters,97-122 lowercase letters
        byte[] ba = new byte[] { 65, 49, 70, 52, 88, 55 };

        for (int i = 0; i < ba.Length; i += 2)
        {
            Console.WriteLine(string.Format("{0}{1}",(char)ba[i],(char)ba[i + 1]));
        }

        Console.ReadKey();

本当に辞書を使いたくない場合は、文字列表現だけを試すこともできます:

            string[] vals = new string[] { "A122", "C67", "T8" };
            foreach (var item in vals)
            {
                //this is just to show you can convert to an int because if its
                //one letter and numbers you know index 1 of string will be
                //the start of the number representation.
                int count = int.Parse(item.Substring(1, item.Length - 1));
                Console.WriteLine("{0},{1}", item.Substring(0, 1), item.Substring(1, item.Length - 1));
            }
于 2013-07-09T12:58:02.383 に答える