Int point to string

Is there a way in C# to create an int pointer to a string or char array, for example:

string whatever = "test";
int * ptr = &whatever[0];

I need to then pass this address to a function which accepts int as input.  Thanks ahead of time.  Nick

nstefanovAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
What function? Is this API or managed function? Please give more details.
0
nstefanovAuthor Commented:
Just a custom function, something like this:

int customfunction(int firstaddress, int lastaddress)
{
   if (firstaddress == lastaddress)
       do something....
   else
      do something else
   return some int;
}

Then I want to pass from above &whatever[0], &whatever[whatever.lenght] like so

int result = customfunction(&whatever[0], &whatever[last]);

Thanks




0
AlexFMCommented:
I think that you are trying to reproduce some C++ algorithms in C#. But .NET string cannot be changed once it is creted, every function which is applied to string creates new string instance. I don't see a way to apply unsafe pointer to string characters, because string [] operator gives string character by value, and address of it is not address of string.
Take a look at String.ToCharArray function and String (Char[])  constructor, maybe this algorithm can work on char array.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gregoryyoungCommented:
You can use string builder to marshal as an edittable string I believe.

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.