[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

How to create a linked list of strings in C#?

Yawen Chan

10/17/2002 10:43:00 AM

From my understanding, pointers in C# can only used for structures/classes
that do not contain reference types. So if I want to create a linked list
of strings, what should I do (instead of using an array)?

Here is what I've done:
string* pStr;

and the error that I gor when compiled:
Cannot take the address or size of a variable of a managed type ('string')

Thanks very much.

Yawen



5 Answers

nope

10/17/2002 10:59:00 AM

0

I guess you will use char instead of string and for manipulation you may
assign these to string type later on while manipulating
"Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in message
news:O1FRuFcdCHA.620@tkmsftngp12...
> From my understanding, pointers in C# can only used for structures/classes
> that do not contain reference types. So if I want to create a linked list
> of strings, what should I do (instead of using an array)?
>
> Here is what I've done:
> string* pStr;
>
> and the error that I gor when compiled:
> Cannot take the address or size of a variable of a managed type ('string')
>
> Thanks very much.
>
> Yawen
>
>
>


J. Dilfer

10/17/2002 11:19:00 AM

0

What you should probably do is use a Collection class (probably
System.Collections.Specialized.StringCollection). There's lots of object
collection types depending of functionality you need.

"Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in message
news:O1FRuFcdCHA.620@tkmsftngp12...
> From my understanding, pointers in C# can only used for structures/classes
> that do not contain reference types. So if I want to create a linked list
> of strings, what should I do (instead of using an array)?
>
> Here is what I've done:
> string* pStr;
>
> and the error that I gor when compiled:
> Cannot take the address or size of a variable of a managed type ('string')
>
> Thanks very much.
>
> Yawen
>
>
>


(Zane Thomas [.NET MVP])

10/17/2002 11:43:00 AM

0

On Thu, 17 Oct 2002 17:43:10 +0800, "Yawen Chan" <y3chan@engmail.uwaterloo.ca>
wrote:

>From my understanding, pointers in C# can only used for structures/classes
>that do not contain reference types. So if I want to create a linked list
>of strings, what should I do (instead of using an array)?

Please download the double-linked list sample from
http://www.pixeldustindustries.com/s...


--
*--------={ Fine Art for .NET }=--------*
| The Best Internet Components for .NET |
| Turn on, tune in, download. |
| @ |
| www.abderaware.com |
*---------------------------------------*
zane a@t abderaware.com

Yawen Chan

10/18/2002 2:34:00 AM

0

Thanks for all your suggestions. They really help.

Yawen


"Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in message
news:O1FRuFcdCHA.620@tkmsftngp12...
> From my understanding, pointers in C# can only used for structures/classes
> that do not contain reference types. So if I want to create a linked list
> of strings, what should I do (instead of using an array)?
>
> Here is what I've done:
> string* pStr;
>
> and the error that I gor when compiled:
> Cannot take the address or size of a variable of a managed type ('string')
>
> Thanks very much.
>
> Yawen
>
>
>


Thong Nguyen <tum(NOSPAM

10/18/2002 6:55:00 AM

0

Um. C# objects are refence types so why can't you just create a linked
list?

class ListNode
{
string next;
string prev;
}

class LinkedList
{
ListNode first;
ListNode last;
}


etc...

why would you ever need or want to use C# pointers?!

Encouraging people to use pointers is precisely why allowing pointers in C#
was a bad idea.

^Tum


"Yawen Chan" <y3chan@engmail.uwaterloo.ca> wrote in message
news:O1FRuFcdCHA.620@tkmsftngp12...
> From my understanding, pointers in C# can only used for structures/classes
> that do not contain reference types. So if I want to create a linked list
> of strings, what should I do (instead of using an array)?
>
> Here is what I've done:
> string* pStr;
>
> and the error that I gor when compiled:
> Cannot take the address or size of a variable of a managed type ('string')
>
> Thanks very much.
>
> Yawen
>
>
>