Jump to content

taking arguments in one line but int32

- - - - -

  • Please log in to reply
3 replies to this topic

#1
mokszyk

mokszyk

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
Hello, is it possible to take arguments in one line by something like this(?):
            int[] tablica = Console.ReadLine().Split(new char[] { ' ' });//of course doesn't work
it works if instead int[] there is string[], but is it possible to take ints by readline in one line?
Thanks for any help!
THink positive :)

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
Console.Readline() can only accept a char array (string), you must convert each array member to int32 separately.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
mokszyk

mokszyk

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
check this out :-P
int[] array = (from s in  Console.ReadLine().Split(new char[] { ' ', '\t' },  StringSplitOptions.RemoveEmptyEntries) select  int.Parse(s)).ToArray();

THink positive :)

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
Nice! C#/Java always seems to have a few tricks like that. :)
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users