나는 아래이 반복되는 코드는 내가이 통합 될 수 있음을 가정하고 있지만 각 사전이 다른 일반적인 사전 예고 경우 :이 반복 코드를 좀 더 우아하게 만들려면 어떻게해야합니까?
dictionary1 유형이다 dictionary2 반면
Dictionary<int, ContinuousIntegrationSolution>
유형이다 :
Dictionary<int, BugTracker>
DataTable dt = GetDataTable("CI");
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
int id = Convert.ToInt32(dr["id"]);
string name = dr["name"].ToString();
_dictionary1[id] = new ContinuousIntegrationSolution(){Name = name};
}
DataTable dt1 = GetDataTable("Bug_Tracking");
for (int i = 0; i < dt1.Rows.Count; i++)
{
DataRow dr = dt1.Rows[i];
int id = Convert.ToInt32(dr["id"]);
string name = dr["name"].ToString();
_dictionary2[id] = new BugTracker() { Name = name };
}
DataTable dt2 = GetDataTable("SDLC");
for (int i = 0; i < dt2.Rows.Count; i++)
{
DataRow dr = dt2.Rows[i];
int id = Convert.ToInt32(dr["id"]);
string name = dr["name"].ToString();
_dictionary3[id] = new SDLCProcess() { Name = name };
}
참고 : 나는 아래에 언급 된 몇 가지 오타를 해결했습니다.
코드에 버그가 있습니까? 3 개의 DataTable (dt, dt1 및 dt2)이 있지만 두 개의 사전 _dictionary1 및 _dictionary2 만 있습니까? –
ContinuousIntegrationSolution, BugTracker 및 SDLCProcess가 이름 멤버를 포함하는 공통 기본 클래스 또는 인터페이스를 갖도록 클래스 계층 구조를 변경할 수 있습니까? –
또한 dt는 스 니펫의 범위 내에서 정의되지 않습니다. –