Click here to Skip to main content
15,867,756 members
Articles / Programming Languages / C#
Tip/Trick

View unsafe pointer as an array in C# watch window

Rate me:
Please Sign up or sign in to vote.
5.00/5 (10 votes)
29 Jan 2014CPOL 15.2K   10   2
View unsafe pointer as an array in C# watch window

Introduction

MS visual studio C# watch window does not support size specifier for pointer to view it as an array whereas c++ watch window does it.

Background

Many articles are available for "Visual Studio tips" which includes the tips for watch window but I could not find any article explaining about viewing an unsafe pointer in C# watch window. Here is the solution but better ideas than this are always welcome.

Using the code

Refer below image for the unsafe fuction which receives the pointer arguments like "float * Vertices". We can use "Vertices,10" in C++ watch window to view the contents of the pointer. How to do that in C#??

Image 1

Step 1: Immediate window
Declare a float array in immediate window as the following image.

Image 2

Step2: Watch windowType the following line in watch window.
Marshal.Copy((IntPtr)Vertices, fVerticesArray, 0, noVertices)

Image 3

After the expression is evaluated in the watch window, type the variable name which we declared in immediate window. Expand the variable to view the contents of the pointer. That's all. :)

Image 4

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
TnTinMn30-Jan-14 15:46
TnTinMn30-Jan-14 15:46 
GeneralRe: My vote of 5 Pin
Sivaji156530-Jan-14 16:45
Sivaji156530-Jan-14 16:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.