1
2
3
4
5
6
>
let f (item : 'T) (arr : 'T[]) =
    if Array.exists (fun x -> x = item) arr then
        arr
    else
        Array.init (arr.Length) (fun i -> if i < arr.Length-1 then arr.[i+1] else item);;
By on 12/23/2010 4:44 AM ()

Hi, Joh:
Thank you very much, your code works!
Merry Christmas and Happy New Year to you!

By on 12/23/2010 9:58 AM ()

As a hint, look at Array.exists and Array.append and remember that arrays are immutable.
If you're continually adding to this array piecemeal, consider using a ResizeArray or List<T>.

By on 12/22/2010 2:43 PM ()

Hi,
Thanks for your hint. But I am not smart enough to figure it out.
If you have a good idea, can you show me your code?
Thank you very much for your help.

By on 12/22/2010 10:47 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper