Reputation: 3051
how can i get the numbers entered in textbox in an array.
for example:
user enter 33,21,5,8 in textbox
and i want to make an array with this numbers,how can i do it?thanks in advance
Upvotes: 3
Views: 4551
Reputation: 30830
Int32[] numbers = textbox1.Text.Split(',').Select(s => Int32.Parse(s)).ToArray();
to get the first item, use following code:
Int32[] numbers = textbox1.Text.Split(',').Select(s => Int32.Parse(s)).ToArray();
Int32 firstNumber = numbers.First();
Upvotes: 8
Reputation: 63
private static void ConvertStringToArray(string p)
{
string[] CardsToBeSortedArray = p.Split(',');
int[] IntCard = Array.ConvertAll<string, int>(CardsToBeSortedArray, delegate(string
card)
{
int result;
int32.TryParse(card, out result);
return result;
});
}
Upvotes: 1