Char Array in C#


I am beginner to C#. Can someone show me an example where program is accepting two numbers upto 256 digits using char arrays and then adding those two numbers using C#.

I would really appreciate help on this.

Who is Participating?
a_goatConnect With a Mentor Commented:
OK, basically don't think of it as character arrays.  Use two strings to read in the values.  Then you have to remember your old grade school addition:


Just start from the end of each string and add the two numbers together (you can convert the characters to numbers in a number of ways, my favorite is (byte)NextCharacter - 48)  Don't forget to handle the case where you have to carry a one over to the next column.  Build your result string as you go.

Was that vague enough to pass EE guidelines yet specific enough to help?
Sounds like homework. Why do you want it done that way?
aparmarAuthor Commented:
yes it is a homework. Its program that accepts two numbers of 256 digits each and after accepting two numbers it adds those two. Is there another way of doing it?


Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

aparmarAuthor Commented:
I can write simple program declaring two integer variable but my only problem is 256 digits limit.

Well, use a byte - not a char. A char in the .NET world is unicode and thus not 8 bits anyways, apart from not being a numeric type alltogether.
aparmarAuthor Commented:
Thanks goat. This helps. It answers my question. all I needed was a guideline not a solution.
Thank You.
Goat solved the question... see author comment 10/13/2004 04:52PM CEST
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.

All Courses

From novice to tech pro — start learning today.