-2

I've defined a function in a class like this. In this class, a value is either looked up or calculated if not found among a list of already calculate values.

If calculated anew, the result is stored in a list so that I can look it up in subsequent calls.

The problem is that the compiler doesn't like the way I do it and tells me

An object reference is required for the non-static field, method or property App.GetGoodFontSize(string, Size).

I don't understand what the compiler suggests. Which object reference does it mean?

Thank you.

public class App : Application
{
    private List<udt> _list = new List<udt>();

    private class udt
    {
        public int iLen { get; set; }
        public Size nSize { get; set; }
        public double FontSize { get; set; }
    }

    public double GetGoodFontSize(string uText, Xamarin.Forms.Size uTextRect)
    {
        for (int i = 0; i < _list.Count; i++)
        {
            if ((_list[i].iLen == uText.Length) && (_list[i].nSize == uTextRect))
            {
                return _list[i].FontSize;
            }
        }

        int iBest = 100;

        for (int i = 100; i > 6; i--)
        {
            Size nSize = GetTextSize(uText, i);

            if (nSize.Width <= uTextRect.Width)
            {
                if (nSize.Height <= uTextRect.Height)
                {
                    iBest = i;
                    break;
                }
            }
        }

        udt n = new udt();
        n.iLen = uText.Length;
        n.nSize = uTextRect;
        n.FontSize = iBest;
        _list.Add(n);

        return iBest;
    }
tmighty
  • 10,734
  • 21
  • 104
  • 218

1 Answers1

2

Change your code like this:

public static double GetGoodFontSize(string uText, Xamarin.Forms.Size uTextRect)

private static List<udt> _list = new List<udt>();
tw2017
  • 105
  • 1
  • 6