静态字符串中的访问复选框

静态字符串中的访问复选框

你好
我有一个问题,我无法弄清楚我知道这个问题,但不知道如何解决

private static string Characters()
    {
        string str = null;

        const string lower = "abcdefghijklmnopqrstuvwxyzæøå";
        const string upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ";
        const string numeric = "0123456789";

        // connot acces non-static field 'checkLower' in static context
        if (checkLower.Checked)
        {
            str += lower;
        }
        if (checkUpper.Checked)
        {
            str += upper;
        }
        if (checkDigits.Checked)
        {
            str += numeric;
        }

        return str;
    }

    // if i change Characters to non-static this will say cannot access non-staic method 'Characters' in static context
    private static char[] fCharList = Characters().ToCharArray();

最佳答案

尝试这个

 private static string Characters(bool checkLowerChecked, bool checkUpperChecked, bool checkDigitsChecked )
        {
            string str = null;

            const string lower = "abcdefghijklmnopqrstuvwxyzæøå";
            const string upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ";
            const string numeric = "0123456789";

            // connot acces non-static field 'checkLower' in static context
            if (checkLowerChecked)
            {
                str += lower;
            }
            if (checkUpperChecked)
            {
                str += upper;
            }
            if (checkDigitsChecked)
            {
                str += numeric;
            }

            return str;
        }


并打电话

Characters(checkLower.Checked, checkUpper.Checked, checkDigits.Checked).ToCharArray();

关于c# - 静态字符串中的访问复选框,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4999037/

10-11 05:55