Solved

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

Posted on 2014-10-21
3
120 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 44

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 44

Accepted Solution

by:
AndyAinscow earned 500 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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