Register
Sign In
Skip over navigation
Home
Add New Question
Jobs
Products
Pointer in .NET
Question posted
in
Computer Software
on
06 2010
Rate question difficulty level
5
1 Votes
Is it possible to create a pointer in .NET ?
If yes, please write how ?
If no , what id the reason ?
Add an answer
Share
|
3 Answers
Guest
Yes, we can create pointers. These are known as unsafe code.
We can apply these as :
unsafe
{
int* pi;
int intx = 1;
pi = &x;
System.Console.WriteLine("Value of intx is: " + *pi);
}
06/30/2010
Guest
Yes it is in unsafe mode. You must set compiler option that you will work in unsafe mode. Then every method that will use pointers in it, it's signature must be declared with unsafe.
eg. public unsafe void MyPointerIterator(){
// Inside comes the pointer declaration
// eg. int i = 0;
// int* counter = &i;
}
06/30/2010
Guest
Yes, pointers can be used in .net, but there is a limitation on its usage.
1. Pointers can be used in a code block/snippet which is marked as 'unsafe' - unsafe can be either modifier or a method
2. Pointers can be used for only value types and arrays, because GC can not have hold over pointers.
Usage -
public unsafe void DemoPointer()
{
int x = 10;
int *iPtr = &x;
Console.WriteLine((int)iPtr);
Console.WriteLine(*iPtr);
}
07/01/2010
Add an answer*
Your name
Email
Enter the code shown above:
please wait..
Company:
iforex
Location:
Israel
Tags:
.NET
,
CLR
,
C#
,
VB.NET
Occupations:
Software\Web Development
add a question
Now hiring!
Jobs
by
Simply
Hired
View all jobs