I am trying to write the following code:
public const Size ImageSize = new Size() { Width = 28, Height = 28 };
But I get an error that Widthand Heightare read-only.
Width
Height
What is the recommended way to do this?
constlimited to primitives that the compiler can directly write as IL directly. readonlyshould be here if Size considered unchanged, i.e.
const
readonly
Size
public static readonly Size ImageSize = new Size(28,28);
Note that if it Sizeis mutable struct, bad things can happen; I would recommend a property rather than a field to prevent a number of confusing side effects.
struct
, System.Drawing.Size const. , .
System.Drawing.Size
readonly. "" , , , .
:
public static readonly Size ImageSize = new Size() { Width = 28, Height = 28 };
public readonly Size ImageSize = new Size(28, 28);
, , .
- , . null.
, :
public const Size ImageSize = new Size(); ImageSize.Width = 28; ImageSize.Height = 28;
, , , . . , , const , .
, , const. , , - . readonly. .
Size , , ?
, . , . Size ( , ). (, System.Drawing.Size), readonly const.
You can use:
public static readonly Size ImageSize = new Size(28, 28);
This is not actually const, but after initialization it will not be changed.
Source: https://habr.com/ru/post/1793861/More articles:Is it possible to have an array of unknown types? - genericsMemory leak tracing using AppVerifier - c ++Aligning runtime views in RelativeLayout - androidCan I choose my own image for C # Windows Drag Drop features? - c #php mysql asc / desc order - dateDB2SQLConfiguration Free Sleep - c #Configuring Django SnipMate for Django Projects Only - vimSend packet over UDP socket - javaExtract 50 random records from a Mysql database table (large dataset) - phpлучший способ построения графика для транспортного потока MPEG2 - windows-7All Articles