Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

679 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