In a coding standards document, I found this statement:
Avoid using foreach to iterate over
immutable value-type collections.
E.g. String arrays.
Why should this be avoided ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You shouldn’t avoid it. The coding standard document you’re reading is talking nonsense. Try to find the author and ask him to explain.
Aside from anything else,
stringis a reference type and arrays are always mutable… this makes me concerned about the quality of the rest of the document, to be honest. Are there any other suspicious recommendations?(It’s possible that “immutable” was meant to refer to the value type rather than the collection – the fact that it’s ambiguous is another worrying sign, IMO.)