Can external static method modify the global variable defined in CSP#?
2 posters
PAT Forum :: Support :: Using PAT :: CSP and PCSP Module
Page 1 of 1
Can external static method modify the global variable defined in CSP#?
I write the following code in CSP#.
The "Mylib.cs" goes as follows
Everything works fine except the fact that inc cannot actually modify the value of g. Can external static method modify the global variable defined in CSP#? Thanks.
- Code:
#import "PAT.Lib.List";
#import "Mylib";
var g = 0;
P = a{call(inc, g);} -> b{call(inc, g);} -> c{call(inc, g);} -> d{call(inc, g);} -> Skip;
The "Mylib.cs" goes as follows
- Code:
using System;
using System.Collections.Generic;
using System.Text;
//the namespace must be PAT.Lib, the class and method names can be arbitrary
namespace PAT.Lib
{
public class NewLib
{
public static int inc(ref int v)
{
v = v+1;
return v;
}
}
}
Everything works fine except the fact that inc cannot actually modify the value of g. Can external static method modify the global variable defined in CSP#? Thanks.
alex2ren- Posts : 6
Join date : 2012-12-03
Re: Can external static method modify the global variable defined in CSP#?
The primitive value (like int, bool) passed into the C# call is by value so even when you put ref in the method, it will not help. One way to solve this problem is to just do this: g = call(inc, g)
if the value passed in is an object, the update will be shown
if the value passed in is an object, the update will be shown
alex2ren wrote:I write the following code in CSP#.
- Code:
#import "PAT.Lib.List";
#import "Mylib";
var g = 0;
P = a{call(inc, g);} -> b{call(inc, g);} -> c{call(inc, g);} -> d{call(inc, g);} -> Skip;
The "Mylib.cs" goes as follows
- Code:
using System;
using System.Collections.Generic;
using System.Text;
//the namespace must be PAT.Lib, the class and method names can be arbitrary
namespace PAT.Lib
{
public class NewLib
{
public static int inc(ref int v)
{
v = v+1;
return v;
}
}
}
Everything works fine except the fact that inc cannot actually modify the value of g. Can external static method modify the global variable defined in CSP#? Thanks.
PAT Forum :: Support :: Using PAT :: CSP and PCSP Module
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|