using System;namespace ClassLibrary1
{
    public class Class1
    {
        public const string STRING_CONST = "This is a const string.";
        public static readonly string STRING_STATIC = "This is a static string";
    }    class Class2
    {
        public string aa()
        {
            return Class1.STRING_CONST + Class1.STRING_STATIC;
        }
    }
}

解决方案 »

  1.   

    readonly 好像可以在构造函数中付值的
      

  2.   

    比如
    namespace ClassLibrary1
    {
        public class Class1
        {
            public const string STRING_CONST = "This is a const string.";
            public static readonly string STRING_STATIC;
            
            static Class1()
            {
                    STRING_STATIC = "here";
            }    }}
      

  3.   

    错误 1 无法对静态只读字段赋值(静态构造函数或变量初始值设定项中除外)我明白了,我记得听李建忠老师对于单件的设计模式课程public static Class1()
    {
        STRING_STATIC = "This is a static string";
    }
    在单线程下是同样的作用.
    public static readonly string STRING_STATIC = "This is a static string";
      

  4.   

    1.首先,const 是在编译时转换的。而readOnly可以在构造函数中赋值。
    2.其次,const只能一些基础类型的,如int/string...,而不能表示类或结构,如果定义:const color MyColor=color.Red;     //将引发错误
    readonly color MyColor=color.Red;  //将不会错误,功能类似常量