Static readonly string arrays
c#
Solution
Try something like this instead:
public static readonly ReadOnlyCollection<string> ErrorList = new ReadOnlyCollection<string>(
new string[] {
"string1",
"string2",
"stringn",
}
);
You'll need to `include` the namespace `System.Collections.ObjectModel` in order to expose this object. ReadOnlyCollection only implements as getter and your array content cannot be changed.
Problem
I am using static readonly string arrays in my web application. Basically array is having error codes and i have kept all similar error codes in one array and checking this array instead of checking each one in different constant string. like ``` public static readonly string[] myarray = string[] {"232132132","31232132","123123123"} ``` Please let me know is there any harm in using static readony string arrays ? Note : I am not facing any error, wanted to know is there any harm or performance issue for using like this?