There are several restrictions to using pointers in C#. I've included a link to the MSDN section on using pointers in C# below.
I would encourage the use of objects instead of pointers if you can get away with it. Pointers are considered "unsafe" types, and must be included in trusted assemblies (if compiled into an assembly) to be accessed.
I believe pointers in C# (or .NET for that matter) are allocated on the heap, unless you call stackalloc to explicitly allocate them on the stack. They are declared with an * after the type declaration for multi-pointer declarations, or an * before the variable name for single pointer declarations. Two asterisks indicate a pointer to a pointer.
Also, any methods where a pointer is declared/used must be declared with an "unsafe" declaration before the method declaration.
You can obtain further information at the URL below.
How can I use pointers in C# programming?
The design of C# is to avoid the use of pointers. "Managed Code" is what it's called. For the most part you shouldn't need pointers in C# but you still have the ability to use pointers in C# but its strongly discouraged.
Reply:Hi
Pointer is a powerful tool in 'C', it is used to know the memory address of a variable/identifier/value
Pointers are also helpful in transfer more than one values/variables/identifiers from main program/function to another function
Tuesday, July 14, 2009
How can I use pointers in C#.net?
What is unsafe mode?
How can I use pointers in C#.net?
You can use pointers just like in C++ although it is use is rare( perhaps only for dealing with older API's with Win32).
You can reference memory directly, add addresses, pass by reference etc.
All operations with pointers need to be within unsafe mode blocks. Pointer operations are dangerous because you can modify or delete memory of other variable/space, for this the compiler requires you to mark areas where you use them as unsafe.
The best explanation you can find in MSDN.
How can I use pointers in C#.net?
You can use pointers just like in C++ although it is use is rare( perhaps only for dealing with older API's with Win32).
You can reference memory directly, add addresses, pass by reference etc.
All operations with pointers need to be within unsafe mode blocks. Pointer operations are dangerous because you can modify or delete memory of other variable/space, for this the compiler requires you to mark areas where you use them as unsafe.
The best explanation you can find in MSDN.
How do you use pointers in C#?
I want to have a list of items where an item points to the next item.
How do you use pointers in C#?
You don't need a pointer to do this, only a reference (which works the same way.)
Define a class
Add an instance variable nextItem of the same type as the class.
You can then tell each class what the next item in the structure is. You can also have a prevIitem variable to get a double-linked list.
Reply:Sorry, C# doesn't support pointers. You probably need to use the List collection. I havn't used it so I'm not sure. But I do know the pointers where one of the main features removed from C#.
survey for money
How do you use pointers in C#?
You don't need a pointer to do this, only a reference (which works the same way.)
Define a class
Add an instance variable nextItem of the same type as the class.
You can then tell each class what the next item in the structure is. You can also have a prevIitem variable to get a double-linked list.
Reply:Sorry, C# doesn't support pointers. You probably need to use the List collection. I havn't used it so I'm not sure. But I do know the pointers where one of the main features removed from C#.
survey for money
Can u tell about pointers in c++?
give an example program using class with resolution operator
Can u tell about pointers in c++?
Pointers are a type of special variable that store the address of the ordinary data type variables rather than the variable itself. They are also of types int,char, etc to store addresses of variable of type int,char...
eg:
suppose intx=3;
the variable x gets stored at a memory location 1001h
the %26amp; operator defines the address of a variable
now declare an pointer variable of type int
int *y;
y=%26amp;x;
here the address of x gets stored in y.
cout%26lt;%26lt;y;
the result will be like 1001.
this is the simplest way i can give you the concept of pointers but it is a huge topic to be understood completely.
bye
Reply:http://www.google.com/search?q=c%2B%2B+p...
Reply:MyClass *obj = new MyClass();
obj-%26gt;doit();
How's that? -%26gt; is it.
Can u tell about pointers in c++?
Pointers are a type of special variable that store the address of the ordinary data type variables rather than the variable itself. They are also of types int,char, etc to store addresses of variable of type int,char...
eg:
suppose intx=3;
the variable x gets stored at a memory location 1001h
the %26amp; operator defines the address of a variable
now declare an pointer variable of type int
int *y;
y=%26amp;x;
here the address of x gets stored in y.
cout%26lt;%26lt;y;
the result will be like 1001.
this is the simplest way i can give you the concept of pointers but it is a huge topic to be understood completely.
bye
Reply:http://www.google.com/search?q=c%2B%2B+p...
Reply:MyClass *obj = new MyClass();
obj-%26gt;doit();
How's that? -%26gt; is it.
I need a code for pascal's triangle in c++?
without using pointers (simple c++ lang)
the output should be: 1
1 1
1 2 1
1 3 3 1
and follows...........
pls help me out .....
I need a code for pascal's triangle in c++?
search google
the output should be: 1
1 1
1 2 1
1 3 3 1
and follows...........
pls help me out .....
I need a code for pascal's triangle in c++?
search google
Why we need pointers in C?
A pointer is the address of a variable rather than the content of it. For example try to figure out the difference between the "the third drawer" (that is, where it is located) and "the content of the third drawer" (what is inside it).
In C algorithms, there are times when we know where our variable is located, and we want to do some arithmetic or manipulation on it. In these cases, the address of the variable (a pointer to it) is more useful than the value of it. More technically, it is named call by reference. As a simple example imagine the difference between
void inc1 (int x)
{
x++ ;
}
and
void inc2 (int * x)
{
(*x)++ ;
}
If we call inc1 (t), the value of t (and int variable) is copied into x, and then the value of x is incremented. But t has not changed. It’s much like I photocopy a page and I give the copy to you and you write something new on your own copy. It is the normal call-by-value function call.
But if we call inc2(%26amp;t), the address (and not the content) of t is copied into pointer x. then the content of x is incremented. Because x has the address of t, it would mean that the content of t is incremented. It’s much like I tell you where the original page is located, and you go to the page, and write something new on it. It is call-by-reference function call.
--------------------------------------...
I added this comment later. You could mean why we need pointers in C and C++ but we don't need them in languages like C# and VB?
Actually, pointers are used in VB and C#, but this use is not as transparent to the programmer as it is in C and C++. Reference as called in VB and C# is a disguised look of pointer with more limited capabilities as comapared to its capabilities in C and C++. Although pointers provide a more powerful capability, it has some potential danger and problem which could be difficult to find. Reference is quite safe, and is adequate for alomost all the situations.
Why we need pointers in C?
Pointers alows you to do low level programming efficiently from C.
Reply:Because they are alot better then using arrays.
Pointers take up less space in memory and can be resized.
However sometimes it just better to use a array if the list is small enough.
Reply:Because of the way programming works in general.
When you develop an application you need to use memory resources. C being and older high level language gives you alot of low level flexibility and control. When you are using a language like C#, Java, Python and the like, they are actually using pointers for non value types.
But C gives you the ability to allocate RAM for your application and you can set a pointer to point to that area, and use it anyway you want, as a string*, char*, int*.
It is not a matter of needing pointers in C, pointers are needed in any good programming language, but C makes the concept of a pointer alot more apparent and gives you the choice to use value types or pointer types.
I would ask ... why would any language need complex value types like structs lol.
In C algorithms, there are times when we know where our variable is located, and we want to do some arithmetic or manipulation on it. In these cases, the address of the variable (a pointer to it) is more useful than the value of it. More technically, it is named call by reference. As a simple example imagine the difference between
void inc1 (int x)
{
x++ ;
}
and
void inc2 (int * x)
{
(*x)++ ;
}
If we call inc1 (t), the value of t (and int variable) is copied into x, and then the value of x is incremented. But t has not changed. It’s much like I photocopy a page and I give the copy to you and you write something new on your own copy. It is the normal call-by-value function call.
But if we call inc2(%26amp;t), the address (and not the content) of t is copied into pointer x. then the content of x is incremented. Because x has the address of t, it would mean that the content of t is incremented. It’s much like I tell you where the original page is located, and you go to the page, and write something new on it. It is call-by-reference function call.
--------------------------------------...
I added this comment later. You could mean why we need pointers in C and C++ but we don't need them in languages like C# and VB?
Actually, pointers are used in VB and C#, but this use is not as transparent to the programmer as it is in C and C++. Reference as called in VB and C# is a disguised look of pointer with more limited capabilities as comapared to its capabilities in C and C++. Although pointers provide a more powerful capability, it has some potential danger and problem which could be difficult to find. Reference is quite safe, and is adequate for alomost all the situations.
Why we need pointers in C?
Pointers alows you to do low level programming efficiently from C.
Reply:Because they are alot better then using arrays.
Pointers take up less space in memory and can be resized.
However sometimes it just better to use a array if the list is small enough.
Reply:Because of the way programming works in general.
When you develop an application you need to use memory resources. C being and older high level language gives you alot of low level flexibility and control. When you are using a language like C#, Java, Python and the like, they are actually using pointers for non value types.
But C gives you the ability to allocate RAM for your application and you can set a pointer to point to that area, and use it anyway you want, as a string*, char*, int*.
It is not a matter of needing pointers in C, pointers are needed in any good programming language, but C makes the concept of a pointer alot more apparent and gives you the choice to use value types or pointer types.
I would ask ... why would any language need complex value types like structs lol.
How do pointers in C++ save memory space and how does memory work?
A space in memory holds some value of information that your program has specified it will need at some time. So if you have already declared a space and need to reference the value of that space, you can use a pointer, instead of creating a duplicate space in memory. Your pointer just keeps reference of the location in memory where your original information is stored. So it saves space by not keeping the entire length of your information in two different places in memory.
How do pointers in C++ save memory space and how does memory work?
Think about a cabinet with 10 x 10 drawers. A pointer is a reference to the drawer. You will just need two digits to specify the location of any item. Now your item may be as big as you want, and with some imagination, each drawer could hold another cabinet with each one 10x10 drawers... And you get a pointer of pointer...
survey questions
How do pointers in C++ save memory space and how does memory work?
Think about a cabinet with 10 x 10 drawers. A pointer is a reference to the drawer. You will just need two digits to specify the location of any item. Now your item may be as big as you want, and with some imagination, each drawer could hold another cabinet with each one 10x10 drawers... And you get a pointer of pointer...
survey questions
Subscribe to:
Posts (Atom)