我尝试做这样的事情:
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
};
但不幸的是,这不起作用:
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.
我怎么解决这个问题?
2
stackoverflow.com/questions/1109805/...
—
阿尔乔姆Koshelev
注意:关闭此问题作为重复项是一个错误。链接的问题与常量数组有关,此问题与常量列表有关。尽管这两种方法提供的功能大致相同,但它们是不同的,答案也不同。仅提及此问题的答案
—
Athari 2014年
ReadOnlyCollection。问题是相关的,但都不是重复的。