© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
36 replies
steven preadly

How can I get the memory address of a feilds in C#?

created an object from a class in C#. Is it possible to retrieve its memory location and address using C# code?

i have tried this code but i got error at this line
IntPtr address = GCHandle.AddrOfPinnedObject(handle);
IntPtr address = GCHandle.AddrOfPinnedObject(handle);
of the code
Person person_1 =  new Person("mina remon shaker");
FieldInfo? fieldInfo = typeof(Person).GetField("Name");
GCHandle handle = GCHandle.Alloc(person_1, GCHandleType.Pinned);
IntPtr address = GCHandle.AddrOfPinnedObject(handle);
handle.Free();
Console.WriteLine("Object address: 0x{0:X}", address.ToInt64());
Person person_1 =  new Person("mina remon shaker");
FieldInfo? fieldInfo = typeof(Person).GetField("Name");
GCHandle handle = GCHandle.Alloc(person_1, GCHandleType.Pinned);
IntPtr address = GCHandle.AddrOfPinnedObject(handle);
handle.Free();
Console.WriteLine("Object address: 0x{0:X}", address.ToInt64());

`
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ How i can get the amount of bytes of an memory address?
C#CC# / help
3y ago
Finding the base address of a memory string in a running process?
C#CC# / help
13mo ago
How can I use a precompiled C/C++ dll in a C# project?
C#CC# / help
2y ago
❔ Can Rider debug memory using address?
C#CC# / help
3y ago