Thread: adding a char variable to int one

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    11

    adding a char variable to int one

    hi,

    I'm really new to c# and I have a minor problem.

    I can't do this line right:

    Code:
    for(flg=line.Length-1;flg>=0;flg--)
    	{
         	        char c=line [flg];
    		num=num+c;
    	}	
    Console.WriteLine(num.ToString());
    all I get is the ascii value addition.

    for ex: string="123"
    num should be =6 instead I get num = 150

    I tried to do " num=num+(int)c" but it's the same result.
    "Cream is not the only thing that floats to the top..."

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Char.GetNumericValue is what you want.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    11
    thanks
    "Cream is not the only thing that floats to the top..."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. Working with random like dice
    By SebastionV3 in forum C++ Programming
    Replies: 10
    Last Post: 05-26-2006, 09:16 PM
  4. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  5. Replies: 2
    Last Post: 03-24-2006, 08:36 PM