string [] lines = TheRichTextBox.Lines; for(int i = 0; i< lines.Length; i ++) { Len + = lines [i] .Length; } 它应该类似于foreach案例。 DavidAh. It''s not a compiler problem. It''s a property problem.get_Lines() is expensive. Who Knew? That''s the problem with properties: younever know how much code they run.Anyway, try this:string[] lines = TheRichTextBox.Lines;for (int i = 0; i < lines.Length; i++){Len += lines[i].Length;}It should be similar to the foreach case.David 这篇关于C#编译器无法优化for循环,与foreach相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 23:18