すべて、オブジェクト配列を作成したいと思いますfoo[]
。ここで、のコンストラクターFoo
は
public Foo(string name, string discription){}
次のような構造(ストアドプロシージャ、関数、またはビューを含まない)を持つデータベースオブジェクトがあります。
public class Database
{
public string name { get; set; }
public string filename { get; set; }
public List<Table> tables { get; set; }
public Database(string name, string filename)
{
this.name = name;
this.filename = filename;
}
}
protected internal class Table
{
public string name { get; set; }
public List<Column> columns { get; set;}
public Table(string name, List<Column> columns)
{
this.name = name;
this.columns = columns;
}
}
protected internal class Column
{
public string name { get; set; }
public string type { get; set; }
public Column(string name, string type, int maxLength,
bool isNullable)
{
this.name = name;
this.type = type;
}
}
オブジェクト配列Column
にTable
情報を追加する最も簡単な方法を知りたいですか?Foo[]
明らかに私はできる
List<Foo> fooList = new List<Foo>();
foreach (Table t in database.tables)
{
fooList.Add(new Foo(t.Name, "Some Description"));
foreach (Column c in t.columns)
fooList.Add(new Foo(c.Name, "Some Description"));
}
Foo[] fooArr = fooList.ToArray<Foo>();
しかし、もっと速い方法はありますか?明らかに、LINQは、同様の操作を行うクエリでは遅くなる可能性がありますが、ここでは速度に注意を払っているので、アドバイスをいただければ幸いです。重複するエントリがないため、おそらくHashSetを使用するのがよいでしょう...
御時間ありがとうございます。