Solved

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

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

831 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