Link to home
Start Free TrialLog in
Avatar of r_badris
r_badris

asked on

Casting string to int in c# without conversion functions

Hi All,

How to convert a string to int in C# with out using Convert.ToInt32() or Int.Parse() conversion function.

Thanks in advance,
Badri Narayanan R
Avatar of Gautham Janardhan
Gautham Janardhan

string str = "1";
int i = (int)str;
I don't think that it it possible to peform it without conversion ...
That would not stroke with the idea of OO-programming
s thats is not possible .. sorry i didnt test it...
>> string str = "1";
>> int i = (int)str;

On this you'll get the error 'Cannot convert type string to int'
Why don't you want to use the two built-in conversion functions (!!)

You could parse the string 'by hand' if you wanted, character by character...

But this then sounds like homework..
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial