Reputation: 387
I don't know much about F# but i am working on a project (on C#) in which i have to make few changes inside pre-written F# code.
I want to declare a object public and then use this object locally.(like we do in C#).
class abc
{
public SubscriptionManager subman = null; // object of class SubscriptionManager
public void DoSomething()
{
subman = new SubscriptionManager();
}
}
Something like this.
Can i do this same thing into the F#?
Upvotes: 2
Views: 81
Reputation: 3149
As people mentioned in the comments, there are a couple of reasons why this may not be the right thing to do. That being said, this code would give you roughly what you are after:
[<AllowNullLiteral>]
type Manager() = class end
type abc() =
member val subman: Manager = null with get, set
member this.DoSomething() = this.subman <- Manager()
I've included a dummy Manager
class just to make the thing compile. There's a related discussion about public fields also here, that lists a solution where at least the mutable fields is not public.
Upvotes: 5