4
การใช้บล็อกขอบเขตภายในภายในฟังก์ชั่นมีสไตล์ไม่ดีหรือไม่?
มีบางกรณี (ค่อนข้างหายาก) ที่มีความเสี่ยง: การนำตัวแปรที่ไม่ต้องการนำมาใช้ซ้ำ (ดูตัวอย่างที่ 1) หรือใช้ตัวแปรแทนตัวแปรอื่นปิดความหมาย (ดูตัวอย่างที่ 2) ตัวอย่างที่ 1: var data = this.InitializeData(); if (this.IsConsistent(data, this.state)) { this.ETL.Process(data); // Alters original data in a way it couldn't be used any longer. } // ... foreach (var flow in data.Flows) { // This shouldn't happen: given that ETL possibly …