The C# code from ‘pragma foreign_proc’ declarations for C# will be placed in the bodies of static member functions of an automatically-generated C# class. ‘pragma foreign_code’ can be used to define additional members of this automatically-generated class, which can then be referenced by ‘pragma foreign_proc’ declarations for C# from that module.
:- pragma foreign_code("C#", " static int counter = 0; "). :- impure pred incr_counter is det. :- pragma foreign_proc("C#", incr_counter, [will_not_call_mercury], "counter++;"). :- semipure func get_counter = int. :- pragma foreign_proc("C#", get_counter = (Result::out), [will_not_call_mercury, promise_semipure], "Result = counter;").