Re: Hi Rick

  • From: Varun Khosla <varun.lists@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Mon, 23 Nov 2009 15:47:39 +0530

Hi Celia,
You cannot do it directly with numeric datatypes; however, converting
one to string can do the same, as:

int num = 281;
int hundredPart = int.Parse(num.ToString()
[0]
.ToString()); // I've broken the statement to make it easy to follow.

First, you convert the number into string. Then, you access the first
character (number in this case) using the character array notation (a
string is simply a sequence of characters). And lastly, you simply
convert the first character (2) back to int using the Parse method. I
have used the ToString method in the last step (to convert the
character into string) because, the int.Parse method requires an
argument of type  string (and not a char type) to operate on.

HTH

Varun

On 11/23/09, Celia Rodriguez <celia-rodriguez@xxxxxxxxxxxxx> wrote:
> In C# is there a way to reference a single digit out of a x number?
>
>
>
> For example:
>
> IfI have a number 281, and I only want to reference the number 2, how can I
> do this
>
>
>
> Thank you for any help.
>
> celia
>
>
__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

  • References:

Other related posts: