By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,989 Members | 1,457 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,989 IT Pros & Developers. It's quick & easy.

POINTERS

P: n/a
Hello,

How can I use pointers in c#. I am trying to create a link list.

Cheers,
Po
Mar 31 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
All reference types are already pointers. Rather than setting the "next" field to a point, you just set it equal to the actual object that would be next.

"Pohihihi" <no*****@hotmail.com> wrote in message news:e9**************@TK2MSFTNGP14.phx.gbl...
Hello,

How can I use pointers in c#. I am trying to create a link list.

Cheers,
Po
Mar 31 '06 #2

P: n/a
"Pohihihi" <no*****@hotmail.com> a écrit dans le message de news:
e9**************@TK2MSFTNGP14.phx.gbl...

| How can I use pointers in c#. I am trying to create a link list.

As Peter has said, all references in C# are really pointers under the skin,
you just don't need to dereference them.

..NET 2.0 has a LinkedList<T> class already, so you may not need to do your
own unless you want to do it as a learning experience.

Otherwise, rolling your own is as simple as this :

public class Node
{
private object data;

private Node next;

public object Data
{
get { return data; }
set { data = value; }
}

public Node Next
{
get { return next; }
set { next = value; }
}

...
}

public class LinkedList
{
private Node first;

private Node last;

...

public void Add(Node node)
{
if (first == null)
{
first = node;
last = first;
}
else
{
last.Next = node;
last = node;
}
}
}

.... or something like that.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Mar 31 '06 #3

P: n/a

P: n/a
The point is that you don't need pointers to implement linked lists in
managed code. Unsafe won't be of great help either, the types a pointer in
C# can point to is somewhat limited, for instance you cannot point to
references or structures that contain references and that's what you need to
implement linked lists of arbitrary managed types.

Willy.

<ba**********@hotmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
| Hi Pohihihi,
|
| Did you check "unsafe" :
|
http://msdn.microsoft.com/library/de...clrfUnsafe.asp
|
| Regards,
| Bart
|
| http://www.xenopz.com/blog/bartdeboeck/
|
Apr 2 '06 #5

P: n/a
The .Net 2.0 platform has a very nice Generic LinkedList class which can be
used straight out of the box, BTW.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:Ob**************@TK2MSFTNGP12.phx.gbl...
The point is that you don't need pointers to implement linked lists in
managed code. Unsafe won't be of great help either, the types a pointer in
C# can point to is somewhat limited, for instance you cannot point to
references or structures that contain references and that's what you need
to
implement linked lists of arbitrary managed types.

Willy.

<ba**********@hotmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
| Hi Pohihihi,
|
| Did you check "unsafe" :
|
http://msdn.microsoft.com/library/de...clrfUnsafe.asp
|
| Regards,
| Bart
|
| http://www.xenopz.com/blog/bartdeboeck/
|

Apr 2 '06 #6

P: n/a

"Pohihihi" <no*****@hotmail.com> wrote in message news:e9**************@TK2MSFTNGP14.phx.gbl...
Hello,

How can I use pointers in c#. I am trying to create a link list.

Cheers,
Po
Apr 3 '06 #7

P: n/a
Hi,

What was wrong with the previous answers ? If you insist on using
pointers, you can use unsafe. If references are good, you can write
your own list or use one of the .net lists.

Regards,
Bart

http://www.xenopz.com/blog/bartdeboeck/

Apr 5 '06 #8

P: n/a
Hi,

What was wrong with the previous answers ? If you insist on using
pointers, you can use unsafe. If references are good, you can write
your own list or use one of the .net lists.

Regards,
Bart

http://www.xenopz.com/blog/bartdeboeck/

Apr 5 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.