Reputation: 15138
I have a Window handle Picker and it says my handle is 0094167C. When I declare the variable in c# the letter in this code gives an error. How to declare?
public const IntPtr WinHandle = 0094167C;
Upvotes: 0
Views: 8092
Reputation: 111
I'd like to add to AgnosticOracle's answer.
In addition to constant-like static-readonly IntPtr/UIntPtr variables, you can use nint
and nuint
which are backed by IntPtr and UIntPtr, respectively.
These types can have integer and unsigned integer values assigned to them and can also be defined as constants.
Upvotes: 0
Reputation: 61
As OregonGhost points out you probably don't want to do that for a windows handle. However, for a IntPtr in general, what you can do is this static readonly fields:
static readonly IntPtr TenK = new IntPtr(1024 * 10000);
Upvotes: 0
Reputation: 23759
You know that the handle will typically change with each application and/or system start? This means your constant is subject to failure anyway.
If, however, you really want to assign a constant other than zero to an IntPtr
(which would be IntPtr.Zero
), the documentation states that there are constructors that take Int32
, Int64
or Void*
as parameter.
Upvotes: 6