Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access .Net field from F# when the field name is a reserved keyword

Tags:

c#

.net

f#

I have a struct that has a field called type

How do i access it in F#?

c#

struct A {
   int type;
}

f#

let a = A()
let myThing = a.type  //error because type is a reserved keyword

How do i access the type field of A?

like image 432
Paul Nikonowicz Avatar asked Jun 28 '12 18:06

Paul Nikonowicz


2 Answers

You're accessing type like a static field. First, you need an instance of A:

let a = A()
let x = a.``type``
like image 113
Daniel Avatar answered Nov 09 '22 22:11

Daniel


You can use a double backtick to qualify it A.``type``.

like image 32
YonahW Avatar answered Nov 09 '22 23:11

YonahW