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;
}
}
}
{
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;
}
}
}
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";
} }}
{
STRING_STATIC = "This is a static string";
}
在单线程下是同样的作用.
public static readonly string STRING_STATIC = "This is a static string";
2.其次,const只能一些基础类型的,如int/string...,而不能表示类或结构,如果定义:const color MyColor=color.Red; //将引发错误
readonly color MyColor=color.Red; //将不会错误,功能类似常量