By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,997 Members | 1,098 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,997 IT Pros & Developers. It's quick & easy.

Return value of method

P: n/a
Hello. I have method (called GetKey) in a class that returns a string.
Also, I have in another class, a method which makes a call to the GetKey
method. What I wish to do is to do an evaluation of the return value of the
GetKey method, within this 2nd class. My question is, should I create a
field/property and assign it the value of the return value in GetKey class?
What you suggest? Here is some fake code so far

Class GetKey
{
public string GetKeyMethod(string myParam)
{
....
.....
return myKey
}

Class Myclass
{
GeyKey gk = new GetKey()
gk.GetKey(someParam)

//MUST NOW DO EVAL OF myKey,,, IF (blah blah blah)
May 11 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Toco,

What do you mean an evaluation of what is returned? Do you mean you
have code in there which you want to run? If so, you need to find some
other way to do this, as C# doesn't really lend itself to interpretation on
the fly (yes, there are methods to do this, but in reality, it's not worth
it).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Toco" <To**@discussions.microsoft.com> wrote in message
news:E0**********************************@microsof t.com...
Hello. I have method (called GetKey) in a class that returns a string.
Also, I have in another class, a method which makes a call to the GetKey
method. What I wish to do is to do an evaluation of the return value of
the
GetKey method, within this 2nd class. My question is, should I create a
field/property and assign it the value of the return value in GetKey
class?
What you suggest? Here is some fake code so far

Class GetKey
{
public string GetKeyMethod(string myParam)
{
...
....
return myKey
}

Class Myclass
{
GeyKey gk = new GetKey()
gk.GetKey(someParam)

//MUST NOW DO EVAL OF myKey,,, IF (blah blah blah)

May 11 '06 #2

P: n/a
Toco <To**@discussions.microsoft.com> wrote:
Hello. I have method (called GetKey) in a class that returns a string.
Also, I have in another class, a method which makes a call to the GetKey
method. What I wish to do is to do an evaluation of the return value of the
GetKey method, within this 2nd class. My question is, should I create a
field/property and assign it the value of the return value in GetKey class?
What you suggest? Here is some fake code so far

Class GetKey
{
public string GetKeyMethod(string myParam)
{
...
....
return myKey
}

Class Myclass
{
GeyKey gk = new GetKey()
gk.GetKey(someParam)

//MUST NOW DO EVAL OF myKey,,, IF (blah blah blah)


So do:

string key = gk.GetKey(someParam);

if (key....)
{
...
}

Basically, the code you showed discards the return value of the method,
whereas you want to "save" it in a variable.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
May 11 '06 #3

P: n/a
Hi,

"Toco" <To**@discussions.microsoft.com> wrote in message
news:E0**********************************@microsof t.com...
Hello. I have method (called GetKey) in a class that returns a string.
Also, I have in another class, a method which makes a call to the GetKey
method. What I wish to do is to do an evaluation of the return value of
the
GetKey method, within this 2nd class. My question is, should I create a
field/property and assign it the value of the return value in GetKey
class?
What you suggest? Here is some fake code so far


Your post is not very clear, so maybe more details will help you get a
better answer.

If you are asking if you should create a property in GetKey the answer is
not, the way you have it now is the correct one.

Calling the method (which you would have to change to return void ) and
forcng the calling code use a property to get the return value is not a good
idea. It's a bad design even.

Also if GetKeyMethod does not use any instance variable declared in GetKey I
suggest do it static.

Also I would suggest you to change the name GetKey is not very intuitive.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
May 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.