s
class Program
{
static readonly int x = 0;
static void Main(string[] args)
{
var xField = typeof(Program).GetField("x", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, 42);
Console.WriteLine("X = " + x); // 42
}
}
Size: a a a
s
class Program
{
static readonly int x = 0;
static void Main(string[] args)
{
var xField = typeof(Program).GetField("x", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, 42);
Console.WriteLine("X = " + x); // 42
}
}
VS
class Program
{
static readonly int x = 0;
static void Main(string[] args)
{
var xField = typeof(Program).GetField("x", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, 42);
Console.WriteLine("X = " + x); // 42
}
}
VS
s
VS
I
class Program
{
static readonly int x = 0;
static void Main(string[] args)
{
var xField = typeof(Program).GetField("x", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null, 42);
Console.WriteLine("X = " + x); // 42
}
}
Dv
К
К
К
К
Dv
class val : var {}
К
class val : var {}
Dv
const
— это чисто контракт, да. Чтобы его обойти, есть const_cast
или mutable
.VS
const
— это чисто контракт, да. Чтобы его обойти, есть const_cast
или mutable
.mutable
:)Dv
mutable
:)VS
Dv
VS
Dv