Thursday, March 28, 2013

F# Indexer

(In learning from "Programming F# 3.0, 2nd Edition")

Like ruby, F# can define indexer as defining Item property.

defining
member this.Item (idx : int) =
  ...
accessing
xxx.[42]


And also like ruby, indexer can take one more arguments.

defining
member this.Item (prefix : string , idx : int) =
  ...
accessing
xxx.["Answer", 42]

No comments:

Post a Comment