ฉันมีดังต่อไปนี้:
- รายการหลักที่เรียกว่า GlobalStrings
- รายการอื่นที่เรียกว่า localStrings
ในลูปตัวอย่างเช่น:
List<string> GlobalStrings = new List<string>();
List<string> localStrings = new List<string>();
for(x=1;x<10;x++)
{
localStrings.Add("some value");
localStrings.Add("some value");
}
// Want to append localStrings to GlobalStrings as easily as possible
3
กองทับไหลเป็นหินเสมอ ... เป็นคำถามที่ดี ...
—
Sangram Nandkhile
คุณกำลังทำผิด
—
Wassim AZIRAR
localStrings = new List<string>;
ควรวางไว้ก่อนหน้าfor
วนรอบ
Wassim ฉันคิดว่านั่นเป็นเหตุผลที่เขาแยกความแตกต่างระหว่างท้องถิ่นและระดับโลก localStrings เป็นโลคัลสำหรับขอบเขตลูป, GlobalStrings อยู่ในขอบเขตโกลบอล
—
Dagrooms
นี้เป็นตัวอย่างที่ไม่ดี (ที่เชิญ wrongheaded ทั้งหมดความคิดเห็นเช่น Wassim ของ) เนื่องจากเห็นได้ชัดว่าคุณก็สามารถ
—
Jim Balter
Add
ที่จะแทนที่จะเป็นGlobalStrings
localStrings
และ FWIW คุณวนซ้ำเพียง 9 ครั้งเท่านั้น น่าจะดีกว่าfor (int x = 0; x < 10; ++x) {var localStrings = GetAListOfStrings(); /* append those to GlobalStrings */}