Tôi cố gắng làm một cái gì đó như thế này:
public const List<String> METRICS = new List<String>()
{
SourceFile.LOC,
SourceFile.MCCABE,
SourceFile.NOM,
SourceFile.NOA,
SourceFile.FANOUT,
SourceFile.FANIN,
SourceFile.NOPAR,
SourceFile.NDC,
SourceFile.CALLS
};
Nhưng tiếc là điều này không hoạt động:
FileStorer.METRICS' is of type 'System.Collections.Generic.List<string>'. A const field of a reference type other than string can only be initialized with null.
Làm thế nào tôi có thể giải quyết vấn đề này?
ReadOnlyCollection
. Các câu hỏi có liên quan, nhưng không trùng lặp với một câu hỏi khác.