C#将字符串转换为bool变量的名称

-3 c# string boolean

我试图做出类似的东西:

    // int counter; - this is changing in ther other parts of program
    bool abc1; bool abc2; bool abc3; bool abc4;

    if("abc" + counter == true)
    {
     //some code
    }
Run Code Online (Sandbox Code Playgroud)

无论如何,我需要将string和int转换为bool名称.我怎样才能做到这一点?

sst*_*tan 7

改为使用数组:

bool[] abc;

// ...

if (abc[counter] == true) {
{
    // some code.
}
Run Code Online (Sandbox Code Playgroud)

  • @ user5081068你不能拿一个值,只是神奇地得到它的变量名.为什么不能使用数组? (3认同)
  • 你想要做的事情听起来不是一个好主意,因为它听起来像你想做一些反思.如果你打算让自己走上这条道路,那么我很难相信你不能使用阵列. (3认同)