F#: Implement a method with a variable number of arguments

Today I learned how to implement a method that accepts a variable number of arguments of the same type.

In C#, we use “params” keyword.

In F#, we use the ParamArray attribute.

open System

type MyClass() =

    member this.SomeMethod([<ParamArray>](args:(string*string) array)) = ()
    

let someInstance = MyClass()

someInstance.SomeMethod( ("Table1","Column1"),
                         ("Table2","Column2"),
                         ("Table3","Column3"),
                         ("Table4","Column4") )

The example above demonstrates how an variable number of typed arguments can be passed to a method. The End.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: