Define extension methods

Category:
Extension Methods
Description: Define extension methods to get version list from string
Code:
type System.String with 
member this.Versions =
if System.String.IsNullOrEmpty(this) then
failwith "empty or null string"
else
this.Split([|'.'|], System.StringSplitOptions.RemoveEmptyEntries)

let ExtensionSample2() =
let a = "1.2.4";
let versions = a.Versions
versions |> Seq.iter (fun n -> printfn "%s" n)
Assert.AreEqual(versions.Length, 3)
Assert.AreEqual(versions.[0], "1")

Execution Result:
1
2
4
both elements are equal
both elements are equal

Last edited Sep 14, 2011 at 3:07 AM by ttliu2000, version 1

Comments

No comments yet.