Alan Wayne
Alan Wayne

Reputation: 5394

In F#, how to write null to a Nullable<System.DateTime> class member?

(Really Really confused).

I have a class, Visit, downloaded from a WCF service. It has a member defined as:

 public System.Nullable<System.DateTime> service_time 

In F# Code, how is null written to this member? Or how to convert this C# class to F# record with Option?

Thanks in advance.

Upvotes: 2

Views: 153

Answers (1)

Fyodor Soikin
Fyodor Soikin

Reputation: 80765

If the member is writable, you can use <- to modify it, like this:

myObject.service_time <- Nullable DateTime.Now

To create a Nullable value without a value inside it, use its parameterless constructor:

myObject.service_time <- Nullable()

Judging by your questions, it looks like you're only just starting out and don't even have a good baseline from which to explore. If this is the case, I would recommend doing some reading first, and maybe doing some toy exercises, before trying to actually implement things. One source that I found particularly useful is fsharpforfunandprofit.com. Check it out.

Upvotes: 3

Related Questions