Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6605493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:17:26+00:00 2026-05-25T19:17:26+00:00

i have 2 forms. one of them is a form that User select a

  • 0

i have 2 forms. one of them is a form that User select a school class so click OK. I use

public int[] grad_class=new int[2];

for save which School class has selected. (list of classes is COMBO BOX)
after that i open another new form to edit information of that class’ students.
i use Switch like this:

switch(grad_class)
{
   case "11": something to do..., break;
   case "12": something to do..., break;
}

But My problem :
I define “grad_class” in form No.1 . so when i want to use that i have to do this:

form1 f1 = new form1();
f1.grade_class;

and in form No.2 i call this code.
in form No.1 i call:

form2 f2 = new form2();    

OCCUR STACK OVERFLOW EXCEPTION !!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:17:26+00:00Added an answer on May 25, 2026 at 7:17 pm

    You state:

    form1 f1 = new form1();
    f1.grade_class;
    

    and in form No.2 i call this code. in form No.1 i call:

    form2 f2 = new form2();    
    

    Well, there’s your issue right there. You state that in form1 you call form2.ctor and in form2 you call form1.ctor. So your code looks like this:

    public form1() {
        var f2 = new form2();
    }
    
    public form2() {
        var f1 = new form1();
    }
    

    Well, of course this results in a stack overflow. These are mutally recursive functions. You have no return condition, so you exhaust your stack space. Quite simply, what is happening is that the machine has to store state about where to go next when a method is finished. It typically stores this information in space called the stack. The stack is bounded though, so if you push too many “this is where to go next” blocks onto the stack by repeatedly invoking methods, you will exhaust this stack space and hit the infamous stack overflow exception.

    Edit: You said:

    namespace TeacherBook {
        public partial class ChooseGrade : Form {
            public int[] grad_class=new int[2]; //int array for grade & class (first for Grade,second for class) 
            EditStudent StdForm = new EditStudent();
        }
    namespace TeacherBook {
        public partial class EditStudent : Form {
            ChooseGrade ChGrade = new ChooseGrade(); // define form 
        }
    }
    

    Effectively what I suspected. You have a field initializer in ChooseGrade that instantiates a new instance of EditStudent. But EditStudent has a field initializer that instantiates a new instance of ChooseGrade. So when you instantiate a new instance of ChooseGrade, this causes the constructor for EditStudent to be invoked, which causes the constructor for ChooseGrade to be invoked, which causes the constructor for EditStudent to be invoked, and on and on it goes until you overflow your stack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two forms, one with a radio button that users must select to
I have three pages that has forms on them. They all lead to one
I have a form with some select elements. One of them is configured so
I have 3 buttons in a form. One of them is the submit button.
I have two completely different forms in one template. How to process them in
I (currently) have two forms, one that needs to call the other. In other
I have encountered a problem in my application. I have two forms, one that
I have a system that allows a person to select a form type that
I have a rails form with 2 selects where one of them depends on
I have a form with a select box that allows multiple options. After a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.