POV-Ray : Newsgroups : povray.off-topic : Reflections on employment : Re: Reflections on employment Server Time
29 Jul 2024 02:33:29 EDT (-0400)
  Re: Reflections on employment  
From: Paul Fuller
Date: 4 Dec 2012 09:51:22
Message: <50be0dea$1@news.povray.org>
On 3/12/2012 2:54 AM, Orchid Win7 v1 wrote:
> On 02/12/2012 03:06 PM, Warp wrote:
>> Orchid Win7 v1<voi### [at] devnull>  wrote:
>>> Here's a challenge - write me a C# function (or even just some
>>> psuedocode) which will take a string containing space-delimited positive
>>> integers, and return them in ascending order.
>>
>> If it were C++, I could write a few lines of code that does that
>
> Haskell:
>
>    foobar :: String -> [Int]
>    foobar = sort . map read . words
>
>
> C#:
>
>    public List<Int> foobar(String s)
>    {
>      string[] words = s.Split(' ');
>      List<Int> list = new List<Int>();
>      foreach (String word in words) {list.add(int.Parse(word));}
>      list.Sort();
>      return list;
>    }
>
>
> Not exactly taxing, eh?

Of course there are many ways to approach this in C# and most other 
languages.  Using LINQ and and working in decimal datatype without error 
handling:

private List<decimal> ParseAndSortValuesFromString1(string text)
{
	return text.Split(' ').Select(s => Decimal.Parse(s)).OrderBy(s => 
s).ToList();
}


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.