-3

Possible Duplicate:
Convert string[] to int[] in one string of code using LINQ

I have an array of strings I want to convert it to array of int

is there any way to convert it directly without looping

I mean without use foreach, for , LINQ select statement, etc.

Any suggestion please.

Community
  • 1
  • 1
AMH
  • 6,363
  • 27
  • 84
  • 135
  • And what is the relation between the string in the array and the int to which it converts? – thekip Jun 06 '11 at 07:05
  • @abatishchev: No, it's not. AMH tries to do it without LINQ. – Edwin de Koning Jun 06 '11 at 07:08
  • 1
    "without use foreach, for , LINQ select statement, etc" - that doesn't leave a whole lot. Why such a silly constraint? – H H Jun 06 '11 at 07:47
  • it's not a silly constraint , it's due to performance issue , we need to enhance the performance I tried the foreach but it's so slow – AMH Jun 06 '11 at 07:57
  • 1
    Trying to improve performance by arbitrarily striking options... good plan. – H H Jun 06 '11 at 09:06

1 Answers1

12

Array.ConvertAll: http://msdn.microsoft.com/en-us/library/exc45z53.aspx

Jim Deville
  • 10,632
  • 1
  • 37
  • 47
  • I had no idea pretty cool method – Radu Jun 06 '11 at 07:06
  • @james Deville may ask about the performace is it faster , than looping – AMH Jun 06 '11 at 07:29
  • @AMH - not sure unfortunately. I would hope that it is optimized, but i don't know for certain – Jim Deville Jun 06 '11 at 07:31
  • 3
    This function will loop though every instance just as yours would. There is no way to act on every item with out performing the iteration. – rerun Jun 06 '11 at 07:58
  • for ur information , it increased the performance incredibly , what was taken hours now take just few seconds, thanks a lot – AMH Jun 06 '11 at 10:51
  • @rerun if you were to modify the metadata (type pointed to and size of each element), then you could convert the array in O(1) time, couldn't you? – Jim Deville Jun 07 '11 at 06:35