1. Application Scenario Reproduction
A simple application solution is as follows:
The CSharpLib class library defines a simple SomeType class as follows:
1
namespace
CSharpLib
2
{
3
public
class
SomeType
4
{
5
public
const
int
ConstField = 50;
6
public
static
readonly
int
ReadonlyField = 50;
7
}
8
}
In the ConsoleApp of the console application, reference the class library CSharpLib and write the following code:
01
using
System;
02
03
namespace
ConsoleApp
04
{
05
using
CSharpLib;
06
07
class
Program
08
{
09
static
void
Main(
string
[] args)
10
{
11
Console.WriteLine(
"Const field is {0}."
, SomeType.ConstField);
12
Console.WriteLine(
"Readonly field is {0}."
, SomeType.ReadonlyField);
13
Console.ReadKey();
14
}
15
}
16
}
In this way, the output of this console application is 50, and the result should be expected by every developer, without any suspicious points.
When we change the constants in the class library CSharpLib:
1
namespace