As in c # to create and then call the function? In C + + do so:
int func (int value)
{
value +=2;
}
But as is done in c #?
As in c # to create and then call the function? In C + + do so:
int func (int value)
{
value +=2;
}
But as is done in c #?
Here's the same function translated in C#:
public void Func(ref int value)
{
// Parameter is passed by reference so any modification
// to the value will propagate to the caller
value +=2;
}
And call it like this:
int value = 5;
Func(ref value); // value is now 7
UPDATE:
If as an alternative you don't want to reflect the modifications made to the value
parameter outside the function you could declare it like this:
public void Func(int value)
{
// Parameter is passed by value so any modification
// to the value will not propagate to the caller
value +=2;
}
And call like this:
int value = 5;
Func(value); // value is still 5
Considering your example is wrong... well, anyway.
public void func(ref int value)
{
value+=2;
}