Hi all,
I have a Interface like below
public interface ICalculator
{
void setNum(int num);
void getWidth();
}
and i implemented a class in Xamarin.Android using that interface like below
[assembly: Xamarin.Forms.Dependency(typeof(Calculator))]namespace Test.Droid
{
class Calculator: IClaclulator
{
private int base = 0;
public void setNum(int num)
{
base = num;
}
public int getBase()
{
return base;
}
}
}
but when i load this class in MainPage with DependencyService like this code
public partial class MainPage ContentPage
{
public MainPage()
{
InitializeComponent();
ICalculator icalculator = DependencyService.Get<ICalculator>(DependencyFetchTarget.GlobalInstance);
icalculator.setNum(10);
int result = icalculator.getBase();
}
}
The result should be 10, but it seems that after setNum(10) the num variable in Calculator class will update but after calling getBase() num variable in class is not in memory and it will return default value which is 0;