sagar said:
Hi Guys..
I Wanted to convert an int to a string in C#...but i cannot use any
built in functions.So, can any one tell me an algorithm or a program
to do so....please is urgent....
When asking a question like this, you should explain up front that it is
a homework assignment, so that anyone replying to it can assist you at
an appropriate level.
Strictly speaking what you are asking for is not possible. You have to
use some built in functions to create any string at all. I assume that
you at least may use the functions for converting a character into a
string and concatenating strings, or creating a string from an array of
characters.
As the point of the excercise is to do what the ToString method does, I
assume that you may not use that method at all. Therefore you will have
to convert a value between 0 to 9 into a character by creating the
character value from the character code. The character code for the
digit 0 is 48, so you just add 48 to the value and cast it to a char.
To get the values for the separate digits, you use the modulo operator
(%) and the division operator (/).
You can either convert each character to a string and concatenate the
strings, or put the characters in a character array (char[]) and create
a string from the array.