fairyvoice <fa********@discussions.microsoft.comwrote:
>
And Michael, you say it is because of the garbage collection, then most
type in .net are managed type and garbage collection will deal with all of
them, then why only string is illegal to get a pointer?
The key is that there are two different kinds of "types" in C#: value
types, and reference types. The types that hold ordinals (byte, char,
bool, short, int, long, etc.) and the floating types (float, double) are
value types. You can get a pointer to those. Object and string are
reference types. You can't get a pointer to those.
>and Rossum, i know i can change the value in this way now, but i still want
to know why i can not get a pointer to the string type, thanks.
Basically, because that's just not how C# works. C# is not C++; you need
to think about the problem differently.
I assume you are trying to use the pointer for efficiency, but it's a false
economy. Remember that copying a string variable doesn't actually copy the
string:
string s = "Testing";
string t = s;
There's only one string there, with two references to it.
--
Tim Roberts,
ti**@probo.com
Providenza & Boekelheide, Inc.