Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Returning a value to a variable in another method in the same class

Posted on 2014-10-21
3
Medium Priority
?
125 Views
Last Modified: 2014-10-21
Hello experts,

I am a novice programmer and need to know how to get a value from one method to another - to explain what I mean; the following method returns a value:

 private string isSelectedType()
                string selectedPerson = string.Empty;
            {
                string selectedPerson = string.Empty;
               
                if (rbStudent.Checked)
                 {
                selectedPerson = "Student";
                }
                if (rbStaff.Checked)
                {
                 selectedPerson = "Employee";
                }
                if (rbOther.Checked)
                {
                 selectedPerson = "Other";
                }
               
                return isSelectedType();
               
            }

Now, I need the value returned by isSelectedType to be placed into a string variable used in another method: some thing like this:
 
string tType;
tType =  isSelectedType();

How can I achieve the above without going into a constant loop ?

Thank you
0
Comment
Question by:adamtrask
  • 2
3 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 40395282
private string isSelectedType()
                string selectedPerson = string.Empty;
            {
                string selectedPerson = string.Empty;
               
                if (rbStudent.Checked)
                 {
                selectedPerson = "Student";
                }
                if (rbStaff.Checked)
                {
                 selectedPerson = "Employee";
                }
                if (rbOther.Checked)
                {
                 selectedPerson = "Other";
                }
               
                return selectedPerson ;
                //return isSelectedType();
               
            }
0
 
LVL 45

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 40395285
oops - spotted another mistake in your code

private string isSelectedType()
                //  THIS SHOULD NOT BE HERE  string selectedPerson = string.Empty;
            {
                string selectedPerson = string.Empty;
               
                if (rbStudent.Checked)
                 {
                selectedPerson = "Student";
                }
                if (rbStaff.Checked)
                {
                 selectedPerson = "Employee";
                }
                if (rbOther.Checked)
                {
                 selectedPerson = "Other";
                }
               
                return selectedPerson ;
                //return isSelectedType();
               
            }
0
 

Author Closing Comment

by:adamtrask
ID: 40395341
Thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Integration Management Part 2
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question