Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now