Inline instantiation of a constant List

Posted by Roflcoptr on Stack Overflow See other posts from Stack Overflow or by Roflcoptr
Published on 2011-01-12T11:44:01Z Indexed on 2011/01/12 11:53 UTC
Read the original article Hit count: 379

Filed under:
|

I try to do something like this:

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
        };

But unfortunately this doesn't work:

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.

How can I solve this problem?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET