在特定 class 的方法中调用另一个 class 的 属性 导致溢出错误。

Calling another class's property within a particular class's method causing an overflow Error.

所以我有两个 class。 一个叫做 'Indexers',我在其中存储以下字符串:

  class Indexes
{
    public string IndexAlpha = "4uCLD[mY7^&*F_5+tXc~UrHMv1ZRxy|`3V}sjIOP<g#wT,.lnG6aK9/SJz?]bB$:8{2hfq=-0N()kd%iAe;'QEp!@>Wo"; //
    public string IndexOmega = "iHL@C7(^nYzu?4-<cJKe~;b/XAPF_[Uf&{|m9Oolg#%]xM0REyW`jN':82Q=p6}h3kwGTZ1Vt>v,DsS.!daBri)q+*";//                                                                                                                                  //
    public string EncryptionCharLibrary = ",q@xRm|T=3`adV!.sDZMi)h8tb1;eKy7Yn^Q2Gwk0S]?~HL(}Op#g6NjU<-fAilE:%9/J[Xv>{P&zW'co+Cu5_FrB*";// 
}

另一个叫做 'Persons' 我正在 运行 使用以下方法..

这首先被调用(在'Persons' class):

 Indexes UsingIndex = new Indexes();

然后... v

    public string InitialEncryptionComputationAndRepeatTracker() {
        StringBuilder sb = new StringBuilder(Password);
      int   count = ForMethod.ComputeOddEven();
        while (PasswordLength > 0)
        {

            char toFind = PasswordAsArray[PasswordLength - 1];//find first Password Char in array[0] to start                 
            int FromAlpha = 0;
            if (count % 2 == 0)
            {
                FromAlpha = UsingIndex.IndexAlpha.IndexOf(toFind);
            }
            else
            {
                FromAlpha = UsingIndex.IndexOmega.IndexOf(toFind);

            }
            char FromOmega = UsingIndex.EncryptionCharLibrary[FromAlpha];
            //TEST a Character:  
            //MessageBox.Show("input: " + toFind + " | High/low: " + FromAlpha + " | Encryption: " + FromOmega);
            char[] squiggle = { '-' };
            if (toFind != squiggle[0])
            {
                //do nothing (subtract 1 from length down below. --v-- 

                sb[PasswordLength - 1] = FromOmega;                         // store in position of StringBuilder  -
                FinalEncryptedPass = sb.ToString();              //  Enter change into password value    -                                                                                                        <-1

                //Checkfor repeat values -v- 
            }
            int RepeatChecker = FinalEncryptedPass.LastIndexOf(toFind); //grab another instance of, and store as an integer value, the index of where that repeat character is- 

            while (RepeatChecker != -1)                         // If the value 'RepeatChecker' is 'null'/ or -1, we know that there was no repeat of the value we just changed a second ago-                   -1-^
            {
                string integerToCountBy = RepeatChecker.ToString();
                AccountableToRepeats.Add(integerToCountBy); // should add a zero at the first repeat-
                string toFind2 = toFind.ToString();        //  Convert "the 'char' in question" to string so we can add to the string list ( AccountabletoRepeats )
                AccountableToRepeats.Add(toFind2);        //   ex. the password 'Reed23' would have the following stored in
                                                          //    AccountableToRepeats -list (ignoring encryption): AccountableToRepeats["0",1,"E",E"] before the while=looop ends.
                                                          //count = count++;// doesn't work.. just keep them in some order and replace the squiggles. 
                                                          // squiggle has to be a char first to go into stringbuilder below (just like 'fromOmega' (in the instance of "none-repeating characters"))
                sb[RepeatChecker] = squiggle[0];
                FinalEncryptedPass = sb.ToString();
                RepeatChecker = FinalEncryptedPass.LastIndexOf(toFind);    //check for another repeat of the same character (stored in 'toFind' variable)      // ----------------------+
            }
            PasswordLength = PasswordLength - 1;
            count = count+ 1;
        }
        return sb.ToString();

    }

该方法基本上应该在来自 'Indexers' 对象 (UsingIndexes) 的变量的特定索引处使用字符 (IndexAlpha、IndexOmega 和 EncryptionCharLibrary),然而!!,当我 运行 ,我在 'Indexes.cs' class 中得到一个错误,说 'system.Whosebugexception' 类型的异常被抛出..

这听起来像,用我的话来说,"the first variable in the Indexes.cs class is being declared until the-end-of-time"..我正在尝试通过基本上改组你在上面看到的代码来改革我的字面上野蛮的过程编程方式,我不确定它是否是在另一个 class 的方法中调用一个 class 的对象合适吗?那是我做错了吗?

idts.. 非常感谢任何帮助(在我输入 Person 的方法之前,我对 'Indexes.cs' 抛出溢出错误没有任何问题,(它的教名:'InitialEncryptionComputationAndRepeatTracker()') .

正如 Julo 指出的那样 ,

this is the method where the WhosebugException was thrown, place a breakpoint on the first line of the function. Once the application breaks, try to step each function (or to simply it, press again F5). The breakpoint should stop the application again. Then see stack trace to which function calls this function from within it and fix recursion.