Virtual methods and overrides

 In F#, the abstract keyword is used to declare a virtual member. So, here we can write a complete definition of the member as we use abstract for virtual. F# is not similar to other .NET languages. Let's have a look at the following example:

type MyClassExampleBase() =
let mutable x = 0
abstract member virtualMethodExample : int -> int
default u. virtualMethodExample (a : int) = x <- x + a; x

type MyClassExampleDerived() =
inherit MyClassExampleBase ()
override u. virtualMethodExample (a: int) = a + 1

In the previous example, we declared a virtual method, virtualMethodExample, in a base class, MyClassExampleBase, and overrode it in a derived class, MyClassExampleDerived.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.228.88