473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Return value of method

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
3 2825
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phil Powell | last post by:
My first time working with a PHP class, and after 6 hours of working out the kinks I am unable to return a value from the class, so now I appeal to the general audience what on earth did I do wrong...
5
by: n_o_s_p_a__m | last post by:
Can't compile. Does this mean that all functions that throw exceptions must be of return type void? examples: // won't compile: "not all code paths return a value" public override int Run() {...
59
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
8
by: WakeBdr | last post by:
I'm writing a class that will query a database for some data and return the result to the caller. I need to be able to return the result of the query in several different ways: list, xml,...
9
by: Samuel Shulman | last post by:
Hi I wander there is a way to return ByRef just like passing ByRef What I want to achieve is the following: Call a method that returns an object Use that call as an argument to a ByRef...
3
by: BombDrop | last post by:
Can any one help I have a method that will return a List to be bound as a datasource to a combobox see code for population below. I get the following error when i try to compile Error 29 ...
7
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function...
6
KoreyAusTex
by: KoreyAusTex | last post by:
If anyone can help me figure out the what the missing return statements are, I think it might be the fact that I need to add a return false in the getValue()? import java.util.*; public class...
4
by: Jonathan | last post by:
I have a SQL stored procedure for adding a new record in a transactions table. It also has two return values: CounterID and IDKey. I want to create a webservice that accepts the 10 input...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.