Hi Varun

  • From: "Celia Rodriguez" <celia-rodriguez@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Mon, 30 Nov 2009 07:52:01 -0000

Hi Varun,

Can you email me off line, please.
Thanks,
Celia
Celia-rodriguez@xxxxxxxxxxxxx

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Varun Khosla
Sent: Monday, November 23, 2009 10:18 AM
To: programmingblind@xxxxxxxxxxxxx
Subject: Re: Hi Rick

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

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts:

  • » Hi Varun - Celia Rodriguez