嗨我有一个问题我想不通我知道这个问题但不知道如何解决它
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();
我是一名优秀的程序员,十分优秀!